From ae29c4044a3fdb6f25b853d01ecae5cea25f153c Mon Sep 17 00:00:00 2001
From: Thomas Wutzler <twutz@bgc-jena.mpg.de>
Date: Mon, 4 Jan 2021 19:41:09 +0100
Subject: [PATCH] added random seed in tests

to avoid accidental failing of the tests
---
 DESCRIPTION                            |  2 +-
 inst/unitTests/runitLogitnorm.R        |  4 +-
 inst/unitTests/runitmodeLogitnorm.R    | 88 +++++++++++++-------------
 inst/unitTests/runitmomentsLogitnorm.R | 64 ++++++++++---------
 4 files changed, 82 insertions(+), 76 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index dae4f7e..2dcbdbf 100755
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -9,4 +9,4 @@ Suggests: RUnit, knitr, ggplot2, reshape2
 VignetteBuilder: knitr
 License: GPL-2
 LazyData: true
-RoxygenNote: 6.0.1
+RoxygenNote: 7.1.1
diff --git a/inst/unitTests/runitLogitnorm.R b/inst/unitTests/runitLogitnorm.R
index d025fcb..68c0a83 100755
--- a/inst/unitTests/runitLogitnorm.R
+++ b/inst/unitTests/runitLogitnorm.R
@@ -38,6 +38,7 @@ test.plogitnorm <- function(){
 
 test.dlogitnorm <- function(){
   q <- c(-1,0,0.5,1,2)
+  set.seed(0815)
   ans <- suppressWarnings(dlogitnorm(q))
   checkEquals(c(0,0,1.595769,0,0), ans, tolerance = 1e-7)
 }
@@ -80,7 +81,8 @@ test.twCoefLogitnormMLE <- function(){
 
 
 test.twCoefLogitnormE <- function(){
-	theta <- twCoefLogitnormE(0.7,0.9)
+  set.seed(0815)
+  theta <- twCoefLogitnormE(0.7,0.9)
 	px <- plogitnorm(x,mu = theta[1],sigma = theta[2])	#percentiles function
 	dx <- dlogitnorm(x,mu = theta[1],sigma = theta[2])	#density function
 	#plot(px~x); abline(v = c(0.7,0.9)); abline(h = c(0.5,0.975))
diff --git a/inst/unitTests/runitmodeLogitnorm.R b/inst/unitTests/runitmodeLogitnorm.R
index a73f46f..f3b743e 100755
--- a/inst/unitTests/runitmodeLogitnorm.R
+++ b/inst/unitTests/runitmodeLogitnorm.R
@@ -1,43 +1,45 @@
-#TODO
-
-.setUp <-function () {
-}
-
-.tearDown <- function () {
-}
-
-test.rightMode <- function(){
-	theta0 <- c(mu=1.5, sigma=0.8)
-	#plot the true and the rediscovered distributions
-	xGrid = seq(0,1, length.out=81)[-c(1,81)]
-	dx <- dlogitnorm(xGrid, mu=theta0[1], sigma=theta0[2])
-	plot( dx~xGrid, type="l")
-	
-	mle <- modeLogitnorm(mu=theta0[1], sigma=theta0[2] )
-	abline(v=mle,col="gray")
-	
-	#check by monte carlo integration
-	#z <- rlogitnorm(1e6, mu=theta0[1], sigma=theta0[2]);	var(z)
-	#dz <- density(z)
-	#checkEqualsNumeric( dz$x[which.max(dz$y)], mle, tolerance=5e-2)
-	checkEqualsNumeric( 0.88, mle, tolerance=1e-2)
-}
-
-test.leftMode <- function(){
-	theta0 <- c(mu=-1.5, sigma=0.8)
-	#plot the true and the rediscovered distributions
-	xGrid = seq(0,1, length.out=81)[-c(1,81)]
-	dx <- dlogitnorm(xGrid, mu=theta0[1], sigma=theta0[2])
-	plot( dx~xGrid, type="l")
-	
-	mle <- modeLogitnorm(mu=theta0[1], sigma=theta0[2] )
-	abline(v=mle,col="gray")
-	
-	#check by monte carlo integration
-	# deprecated: did not run on Windows
-	#z <- rlogitnorm(1e6, mu=theta0[1], sigma=theta0[2]);	var(z)
-	#dz <- density(z)
-	#checkEqualsNumeric( dz$x[which.max(dz$y)], mle, tolerance=5e-2)
-	checkEqualsNumeric( 0.12, mle, tolerance=1e-2)		# regression 0.12 calculated previously
-}
-
+#TODO
+
+.setUp <-function () {
+}
+
+.tearDown <- function () {
+}
+
+test.rightMode <- function(){
+	theta0 <- c(mu=1.5, sigma=0.8)
+	#plot the true and the rediscovered distributions
+	xGrid = seq(0,1, length.out=81)[-c(1,81)]
+	dx <- dlogitnorm(xGrid, mu=theta0[1], sigma=theta0[2])
+	plot( dx~xGrid, type="l")
+	
+	set.seed(0815)
+	mle <- modeLogitnorm(mu=theta0[1], sigma=theta0[2] )
+	abline(v=mle,col="gray")
+	
+	#check by monte carlo integration
+	#z <- rlogitnorm(1e6, mu=theta0[1], sigma=theta0[2]);	var(z)
+	#dz <- density(z)
+	#checkEqualsNumeric( dz$x[which.max(dz$y)], mle, tolerance=5e-2)
+	checkEqualsNumeric( 0.88, mle, tolerance=1e-2)
+}
+
+test.leftMode <- function(){
+	theta0 <- c(mu=-1.5, sigma=0.8)
+	#plot the true and the rediscovered distributions
+	xGrid = seq(0,1, length.out=81)[-c(1,81)]
+	dx <- dlogitnorm(xGrid, mu=theta0[1], sigma=theta0[2])
+	plot( dx~xGrid, type="l")
+	
+	set.seed(0815)
+	mle <- modeLogitnorm(mu=theta0[1], sigma=theta0[2] )
+	abline(v=mle,col="gray")
+	
+	#check by monte carlo integration
+	# deprecated: did not run on Windows
+	#z <- rlogitnorm(1e6, mu=theta0[1], sigma=theta0[2]);	var(z)
+	#dz <- density(z)
+	#checkEqualsNumeric( dz$x[which.max(dz$y)], mle, tolerance=5e-2)
+	checkEqualsNumeric( 0.12, mle, tolerance=1e-2)		# regression 0.12 calculated previously
+}
+
diff --git a/inst/unitTests/runitmomentsLogitnorm.R b/inst/unitTests/runitmomentsLogitnorm.R
index bc4221b..98dbcc3 100755
--- a/inst/unitTests/runitmomentsLogitnorm.R
+++ b/inst/unitTests/runitmomentsLogitnorm.R
@@ -1,31 +1,33 @@
-#TODO
-
-.setUp <-function () {
-}
-
-.tearDown <- function () {
-}
-
-test.1 <- function(){
-	theta0 <- c(mu=1.5, sigma=0.8)
-	#plot the true and the rediscovered distributions
-	xGrid = seq(0,1, length.out=81)[-c(1,81)]
-	dx <- dlogitnorm(xGrid, mu=theta0[1], sigma=theta0[2])
-	plot( dx~xGrid, type="l")
-	
-	moments <- momentsLogitnorm(mu=theta0[1], sigma=theta0[2] )
-	#check by monte carlo integration
-	z <- rlogitnorm(1e6, mu=theta0[1], sigma=theta0[2]);	var(z)
-	checkEqualsNumeric( mean(z), moments["mean"], tolerance=1e-3)
-	checkEqualsNumeric( var(z), moments["var"], tolerance=6e-3)
-}
-
-test.momentsLogitnorm41 <- function(){
-	(res <- momentsLogitnorm(4,1))
-	checkEqualsNumeric( c(0.97189602, 0.00101663), res)
-}
-
-test.momentsLogitnorm501 <- function(){
-	(res <- momentsLogitnorm(5,0.1))
-	checkEqualsNumeric( c(9.932743e-01, 4.484069e-07), res, tolerance=1e-7)
-}
+#TODO
+
+.setUp <-function () {
+}
+
+.tearDown <- function () {
+}
+
+test.1 <- function(){
+  set.seed(0815)
+  theta0 <- c(mu=1.5, sigma=0.8)
+	#plot the true and the rediscovered distributions
+	xGrid = seq(0,1, length.out=81)[-c(1,81)]
+	dx <- dlogitnorm(xGrid, mu=theta0[1], sigma=theta0[2])
+	plot( dx~xGrid, type="l")
+	
+	moments <- momentsLogitnorm(mu=theta0[1], sigma=theta0[2] )
+	#check by monte carlo integration
+	z <- rlogitnorm(1e6, mu=theta0[1], sigma=theta0[2]);	var(z)
+	checkEqualsNumeric( mean(z), moments["mean"], tolerance=1e-3)
+	checkEqualsNumeric( var(z), moments["var"], tolerance=1e-2)
+}
+
+test.momentsLogitnorm41 <- function(){
+	(res <- momentsLogitnorm(4,1))
+	checkEqualsNumeric( c(0.97189602, 0.00101663), res)
+}
+
+test.momentsLogitnorm501 <- function(){
+  set.seed(0815)
+  (res <- momentsLogitnorm(5,0.1))
+	checkEqualsNumeric( c(9.932743e-01, 4.484069e-07), res, tolerance=1e-7)
+}