1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
library(iterators)
# test isplit with a single factor
test01 <- function() {
x <- rnorm(200)
f <- factor(sample(1:10, length(x), replace=TRUE))
it <- isplit(x, f)
expected <- split(x, f)
for (i in expected) {
actual <- nextElem(it)
checkEquals(actual$value, i)
}
it <- isplit(x, f, drop=TRUE)
expected <- split(x, f, drop=TRUE)
for (i in expected) {
actual <- nextElem(it)
checkEquals(actual$value, i)
}
}
# test isplit with two factors
test02 <- function() {
x <- rnorm(200)
f <- list(factor(sample(1:10, length(x), replace=TRUE)),
factor(sample(1:10, length(x), replace=TRUE)))
it <- isplit(x, f)
expected <- split(x, f)
for (i in expected) {
actual <- nextElem(it)
checkEquals(actual$value, i)
}
it <- isplit(x, f, drop=TRUE)
expected <- split(x, f, drop=TRUE)
for (i in expected) {
actual <- nextElem(it)
checkEquals(actual$value, i)
}
}
|