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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Nov 7 05:21:56 CET 2013


Author: gsimpson
Date: 2013-11-07 05:21:56 +0100 (Thu, 07 Nov 2013)
New Revision: 2663

Added:
   pkg/permute/inst/tests/test-shuffleSet.R
Log:
adds initial unit test for shuffleSet

Added: pkg/permute/inst/tests/test-shuffleSet.R
===================================================================
--- pkg/permute/inst/tests/test-shuffleSet.R	                        (rev 0)
+++ pkg/permute/inst/tests/test-shuffleSet.R	2013-11-07 04:21:56 UTC (rev 2663)
@@ -0,0 +1,20 @@
+library(testthat)
+library_if_available(permute)
+
+context("Testing shuffleSet()")
+
+## test that shuffleSet interleves the separate block-level
+## permutations correctly back into the original ordering
+## This always generates odd, even, odd, ..., numbered vector
+## of observations, hence when we take the modulus 2 we get
+## a vector of 1,0,1,0,1,...
+test_that("shuffleSet interleves block-level perms correctly", {
+    gr <- factor(rep(1:2, length=20))
+    ctrl <- how(nperm=5, blocks=gr)
+    p <- shuffleSet(20, control = ctrl) %% 2
+    y <- rep_len(c(1L, 0L), ncol(p))
+    nc <- ncol(p)
+    for (i in seq_len(nrow(p))) {
+        expect_that(p[i, ], equals(y))
+    }
+})



More information about the Vegan-commits mailing list