[Vegan-commits] r1979 - permbranches/0.6/inst/tests
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Nov 1 15:33:56 CET 2011
Author: gsimpson
Date: 2011-11-01 15:33:55 +0100 (Tue, 01 Nov 2011)
New Revision: 1979
Modified:
permbranches/0.6/inst/tests/test-shuffle.R
Log:
merging r1978 from permute trunk to 0.6 branch
Modified: permbranches/0.6/inst/tests/test-shuffle.R
===================================================================
--- permbranches/0.6/inst/tests/test-shuffle.R 2011-11-01 14:32:42 UTC (rev 1978)
+++ permbranches/0.6/inst/tests/test-shuffle.R 2011-11-01 14:33:55 UTC (rev 1979)
@@ -20,3 +20,25 @@
expect_that(shuffle(1, control = ctrl), is_identical_to(1L))
expect_that(shuffle(3, control = ctrl), is_identical_to(c(1L, 2L, 3L)))
})
+
+## test what shuffle returns when permuting only the strata
+## must *not* assume that the samples are in contiguous blocks
+test_that("shuffle() works for non-contigous blocks of samples", {
+ ## permuting levels of block instead of observations
+ ## non-contiguous blocks - checks that r1972 continues to work
+ block <- factor(rep(1:4, 5))
+ CTRL <- permControl(strata = block,
+ blocks = Blocks(type = "free"),
+ within = Within(type = "none"))
+ n <- 20
+ set.seed(2)
+ result <- shuffle(n, CTRL)
+ out1 <- as.integer(c( 3, 2, 1, 4,
+ 7, 6, 5, 8,
+ 11,10, 9,12,
+ 15,14,13,16,
+ 19,18,17,20))
+ expect_that(result, is_identical_to(out1))
+ out2 <- factor(as.integer(rep(c(3,2,1,4), 5)), levels = 1:4)
+ expect_that(block[result], is_identical_to(out2))
+})
More information about the Vegan-commits
mailing list