aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2015-05-14 00:21:12 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2015-05-14 00:21:47 +0200
commit01c69fcff8c5a82b4c80faaeb44ff00827e792ca (patch)
tree5aa6d4c2a339980b726d7f02d906b73c602a885b
parent42739646dc36ff74d43b638fc2c4f5259496e2b9 (diff)
Start of migration from RUnit to testthat
-rw-r--r--.gitignore1
-rw-r--r--DESCRIPTION5
-rw-r--r--GNUmakefile4
-rw-r--r--inst/unitTests/Makefile15
-rw-r--r--tests/doRUnit.R42
-rw-r--r--tests/testthat.R4
-rw-r--r--tests/testthat/runit.mkinerrmin.R (renamed from inst/unitTests/runit.mkinerrmin.R)0
-rw-r--r--tests/testthat/runit.mkinfit.R (renamed from inst/unitTests/runit.mkinfit.R)0
-rw-r--r--tests/testthat/runit.mkinpredict.R (renamed from inst/unitTests/runit.mkinpredict.R)0
-rw-r--r--tests/testthat/test_parent_only.R48
10 files changed, 58 insertions, 61 deletions
diff --git a/.gitignore b/.gitignore
index 39eac04e..81a0b7d7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,4 +9,5 @@ vignettes/*.toc
vignettes/.build.timestamp
vignettes/mkin.tex
vignettes/FOCUS_Z.tex
+vignettes/compiled_models_cache
mkin.Rcheck
diff --git a/DESCRIPTION b/DESCRIPTION
index 03976d1e..0477a200 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -3,7 +3,7 @@ Type: Package
Title: Routines for Fitting Kinetic Models with One or More State
Variables to Chemical Degradation Data
Version: 0.9-35
-Date: 2015-02-20
+Date: 2015-05-13
Authors@R: c(person("Johannes", "Ranke", role = c("aut", "cre", "cph"),
email = "jranke@uni-bremen.de"),
person("Katrin", "Lindenberger", role = "ctb"),
@@ -17,7 +17,8 @@ Description: Calculation routines based on the FOCUS Kinetics Report (2006).
for a particular purpose.
Depends: minpack.lm, rootSolve
Imports: FME, deSolve
-Suggests: knitr, RUnit
+Suggests: knitr,
+ testthat
License: GPL
LazyLoad: yes
LazyData: yes
diff --git a/GNUmakefile b/GNUmakefile
index 126dede1..b731166b 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -18,13 +18,13 @@ SDDIR ?= $(RFSVN)/www/mkin_static
pkgfiles = NEWS \
data/* \
DESCRIPTION \
- inst/unitTests* \
inst/staticdocs/README \
man/* \
NAMESPACE \
R/* \
README.md \
tests/* \
+ tests/testthat* \
TODO \
vignettes/*
@@ -69,7 +69,7 @@ clean:
test: install-no-vignettes
cd tests;\
- "$(RBIN)/Rscript" doRUnit.R
+ "$(RBIN)/Rscript" testthat.R
vignettes/mkin.pdf: vignettes/mkin.Rnw
"$(RBIN)/Rscript" -e "tools::buildVignette(file = 'vignettes/mkin.Rnw', dir = 'vignettes')"
diff --git a/inst/unitTests/Makefile b/inst/unitTests/Makefile
deleted file mode 100644
index 8d132253..00000000
--- a/inst/unitTests/Makefile
+++ /dev/null
@@ -1,15 +0,0 @@
-TOP=../..
-PKG=${shell cd ${TOP};pwd}
-SUITE=doRUnit.R
-R=R
-
-all: inst test
-
-inst: # Install package
- cd ${TOP}/..;\
- ${R} CMD INSTALL ${PKG}
-
-test: # Run unit tests
- export RCMDCHECK=FALSE;\
- cd ${TOP}/tests;\
- ${R} --vanilla --slave < ${SUITE}
diff --git a/tests/doRUnit.R b/tests/doRUnit.R
deleted file mode 100644
index 9faee940..00000000
--- a/tests/doRUnit.R
+++ /dev/null
@@ -1,42 +0,0 @@
-# Adapted from a version around 2.9 of the rcdk package by Rajarshi Guha
-if(require("RUnit", quietly=TRUE)) {
-
- pkg <- "mkin"
- path <- system.file(package=pkg, "unitTests")
-
- cat("\nRunning unit tests\n")
- print(list(pkg=pkg, getwd=getwd(), pathToUnitTests=path))
-
- library(package=pkg, character.only=TRUE)
-
- ## Define tests
- testSuite <- defineTestSuite(name=paste(pkg, " Unit Tests"),
- dirs=path)
- ## Run
- tests <- runTestSuite(testSuite)
-
- ## Default report name
- pathReport <- file.path(path, "report")
-
- ## Report to stdout and text files
- cat("------------------- UNIT TEST SUMMARY ---------------------\n\n")
- printTextProtocol(tests, showDetails=FALSE)
- printTextProtocol(tests, showDetails=FALSE,
- fileName=paste(pathReport, "Summary.txt", sep=""))
- printTextProtocol(tests, showDetails=TRUE,
- fileName=paste(pathReport, ".txt", sep=""))
-
- ## Report to HTML file
- printHTMLProtocol(tests, fileName=paste(pathReport, ".html", sep=""))
-
- ## Return stop() to cause R CMD check stop in case of
- ## - failures i.e. FALSE to unit tests or
- ## - errors i.e. R errors
- tmp <- getErrors(tests)
- if(tmp$nFail > 0 | tmp$nErr > 0) {
- stop(paste("\n\nunit testing failed (#test failures: ", tmp$nFail,
- ", #R errors: ", tmp$nErr, ")\n\n", sep=""))
- }
-} else {
- warning("cannot run unit tests -- package RUnit is not available")
-}
diff --git a/tests/testthat.R b/tests/testthat.R
new file mode 100644
index 00000000..01c9b7cd
--- /dev/null
+++ b/tests/testthat.R
@@ -0,0 +1,4 @@
+library(testthat)
+library(mkin)
+
+test_check("mkin")
diff --git a/inst/unitTests/runit.mkinerrmin.R b/tests/testthat/runit.mkinerrmin.R
index 56a33ff9..56a33ff9 100644
--- a/inst/unitTests/runit.mkinerrmin.R
+++ b/tests/testthat/runit.mkinerrmin.R
diff --git a/inst/unitTests/runit.mkinfit.R b/tests/testthat/runit.mkinfit.R
index 8eefb995..8eefb995 100644
--- a/inst/unitTests/runit.mkinfit.R
+++ b/tests/testthat/runit.mkinfit.R
diff --git a/inst/unitTests/runit.mkinpredict.R b/tests/testthat/runit.mkinpredict.R
index 997857ce..997857ce 100644
--- a/inst/unitTests/runit.mkinpredict.R
+++ b/tests/testthat/runit.mkinpredict.R
diff --git a/tests/testthat/test_parent_only.R b/tests/testthat/test_parent_only.R
new file mode 100644
index 00000000..16fc5131
--- /dev/null
+++ b/tests/testthat/test_parent_only.R
@@ -0,0 +1,48 @@
+context("Fitting of parent only models")
+
+calc_dev.percent <- function(fitlist, reference) {
+ for (i in 1:length(fitlist)) {
+ fit <- fitlist[[i]]
+ results <- c(fit$bparms.optim,
+ endpoints(fit)$distimes$DT50,
+ endpoints(fit)$distimes$DT90)
+ dev.percent[[i]] <- abs(100 * ((reference - results)/reference))
+ }
+ return(dev.percent)
+}
+
+SFO <- mkinmod(parent = list(type = "SFO"))
+FOMC <- mkinmod(parent = list(type = "FOMC"))
+
+test_that("SFO fit for FOCUS A deviates less than 0.1% from median of values from FOCUS report", {
+ fits.A.SFO <- list()
+ fits.A.SFO[[1]] <- mkinfit("SFO", FOCUS_2006_A, quiet=TRUE)
+ fits.A.SFO[[2]] <- mkinfit(SFO, FOCUS_2006_A, quiet=TRUE)
+ fits.A.SFO[[3]] <- mkinfit(SFO, FOCUS_2006_A, quiet=TRUE, solution_type = "eigen")
+ fits.A.SFO[[4]] <- mkinfit(SFO, FOCUS_2006_A, quiet=TRUE, solution_type = "deSolve")
+
+ median.A.SFO <- as.numeric(lapply(subset(FOCUS_2006_SFO_ref_A_to_F,
+ dataset == "A",
+ c(M0, k, DT50, DT90)), "median"))
+
+ dev.percent <- calc_dev.percent(fits.A.SFO, median.A.SFO)
+ expect_equivalent(dev.percent[[1]] < 0.1, rep(TRUE, 4))
+ expect_equivalent(dev.percent[[2]] < 0.1, rep(TRUE, 4))
+ expect_equivalent(dev.percent[[3]] < 0.1, rep(TRUE, 4))
+ expect_equivalent(dev.percent[[4]] < 0.1, rep(TRUE, 4))
+})
+
+test_that("SFO fit for FOCUS C deviates less than 0.1% from median of values from FOCUS report", {
+ fits.C.SFO <- list()
+ fits.C.SFO[[1]] <- mkinfit("SFO", FOCUS_2006_C, quiet=TRUE)
+ fits.C.SFO[[2]] <- mkinfit(SFO, FOCUS_2006_C, quiet=TRUE)
+ fits.C.SFO[[3]] <- mkinfit(SFO, FOCUS_2006_C, quiet=TRUE, solution_type = "deSolve")
+
+ median.C.SFO <- as.numeric(lapply(subset(FOCUS_2006_SFO_ref_A_to_F,
+ dataset == "C",
+ c(M0, k, DT50, DT90)), "median"))
+ dev.percent <- calc_dev.percent(fits.C.SFO, median.C.SFO)
+ expect_equivalent(dev.percent[[1]] < 0.1, rep(TRUE, 4))
+ expect_equivalent(dev.percent[[2]] < 0.1, rep(TRUE, 4))
+ expect_equivalent(dev.percent[[3]] < 0.1, rep(TRUE, 4))
+})

Contact - Imprint