File: chunksizeTest.R

package info (click to toggle)
r-cran-iterators 1.0.14-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 600 kB
  • sloc: sh: 29; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 707 bytes parent folder | download | duplicates (6)
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
library(iterators)

# test that various values of chunksize
test01 <- function() {
  nr <- 13
  nc <- 21
  mat <- matrix(rnorm(nr * nc), nr)

  for (n in 1:(nc+2)) {
    it <- iter(mat, by='col', chunksize=n)
    bcols <- as.list(it)
    for (bcol in bcols) {
      checkTrue(nrow(bcol) == nr)
      checkTrue(ncol(bcol) <= n && ncol(bcol) >= 1)
    }
    actual <- do.call('cbind', bcols)
    checkEquals(mat, actual)
  }

  for (n in 1:(nr+2)) {
    it <- iter(mat, by='row', chunksize=n)
    brows <- as.list(it)
    for (brow in brows) {
      checkTrue(ncol(bcol) == nc)
      checkTrue(nrow(brow) <= n && nrow(brow) >= 1)
    }
    actual <- do.call('rbind', brows)
    checkEquals(mat, actual)
  }
}