[Vegan-commits] r2842 - pkg/permute/inst/tests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jan 26 20:20:03 CET 2014


Author: gsimpson
Date: 2014-01-26 20:20:03 +0100 (Sun, 26 Jan 2014)
New Revision: 2842

Modified:
   pkg/permute/inst/tests/test-allPerms.R
Log:
Unit tests extended: check for unique permutations in allPerms; check Plot-level permutations.

Modified: pkg/permute/inst/tests/test-allPerms.R
===================================================================
--- pkg/permute/inst/tests/test-allPerms.R	2014-01-26 02:18:45 UTC (rev 2841)
+++ pkg/permute/inst/tests/test-allPerms.R	2014-01-26 19:20:03 UTC (rev 2842)
@@ -3,7 +3,6 @@
 
 context("Testing allPerms()")
 
-## test that allPerms returns
 test_that("allPerms - blocks - within block free", {
     ## example data from Joris Meys from
     ## http://stackoverflow.com/a/21313632/429846
@@ -20,6 +19,10 @@
     p <- allPerms(nr, control = hh)
     expect_that(nrow(p), equals(np - 1)) ## default is to drop observed
 
+    ## check no duplicate indices within rows
+    dup <- any(apply(p, 1, function(x) any(duplicated(x))))
+    expect_false(dup, info = "Blocks: even; within: free; no observed")
+
     ## with the observed permutation included
     hh <- how(within = Within("free"),
               blocks = factor(thedata$judge),
@@ -27,6 +30,10 @@
               observed = TRUE)
     p <- allPerms(nr, control = hh)
     expect_that(nrow(p), equals(np)) ## now includes observed
+
+    ## check no duplicate indices within rows
+    dup <- any(apply(p, 1, function(x) any(duplicated(x))))
+    expect_false(dup, info = "Blocks: even; within: free; observed")
 })
 
 test_that("allPerms - blocks - within block free - uneven block sizes", {
@@ -42,6 +49,10 @@
     p <- allPerms(ll, control = hh)
     expect_that(nrow(p), equals(np - 1)) ## default is to drop observed
 
+    ## check no duplicate indices within rows
+    dup <- any(apply(p, 1, function(x) any(duplicated(x))))
+    expect_false(dup, info = "Blocks: uneven; within: free; no observed")
+
     ## with the observed permutation included
     hh <- how(within = Within("free"),
               blocks = fac,
@@ -49,4 +60,26 @@
               observed = TRUE)
     p <- allPerms(ll, control = hh)
     expect_that(nrow(p), equals(np)) ## now includes observed
+
+    ## check no duplicate indices within rows
+    dup <- any(apply(p, 1, function(x) any(duplicated(x))))
+    expect_false(dup, info = "Blocks: uneven; within: free; observed")
 })
+
+## testing plot-level permutations ------------------------------------
+test_that("allPerms: plots; within: free; even: yes;", {
+    fac <- rep(1:3, each = 3)
+
+    hh <- how(plots = Plots(strata = fac),
+              complete = TRUE, maxperm = 1e9)
+    ll <- length(fac)
+    np <- numPerms(ll, hh)
+    p <- allPerms(ll, control = hh)
+    expect_that(nrow(p), equals(np - 1), ## default is to drop observed
+                info = "Check n all perms == numPerms output.")
+
+    ## check no duplicate indices within rows
+    dup <- any(apply(p, 1, function(x) any(duplicated(x))))
+    expect_false(dup,
+                 info = "Checking Unique: Blocks: even; within: free; no observed")
+})



More information about the Vegan-commits mailing list