aboutsummaryrefslogtreecommitdiff
path: root/pkg/tests
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2015-04-24 02:21:04 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2015-04-24 02:22:08 +0200
commit7d2096855edcc196629c1c7a9983a56ec6addd1e (patch)
treed4adf4a7c2db89b0ca816c9ae5973bab1317c88b /pkg/tests
parentbcfe0af7970efe36c3aa661e89953fbe3689c310 (diff)
Add a geometric mean function
Diffstat (limited to 'pkg/tests')
-rw-r--r--pkg/tests/testthat/test_geomean.R11
1 files changed, 11 insertions, 0 deletions
diff --git a/pkg/tests/testthat/test_geomean.R b/pkg/tests/testthat/test_geomean.R
new file mode 100644
index 0000000..0cc3416
--- /dev/null
+++ b/pkg/tests/testthat/test_geomean.R
@@ -0,0 +1,11 @@
+library(pfm)
+context("Geometric mean calculation")
+
+test_that("The geometric mean is correctly calculated", {
+ expect_equal(geomean(c(1, 3, 9)), 3)
+ expect_equal(geomean(c(0, 3, 9)), 0)
+ expect_error(geomean(c(1, 3, NA, 9), na.rm = FALSE), "NA")
+ expect_equal(geomean(c(1, 3, NA, 9), na.rm = TRUE), 3)
+ expect_error(geomean(c(1, -3, 9)), "positive")
+ expect_error(geomean(c(1, -3, NA, 9)), "positive")
+})

Contact - Imprint