tests/timeoutTest.R

# Test that timeout can stop an infinite iterator
test01 <- function() {
  it <- ihasNext(timeout(icount(), 2))
  x <- 0
  while (hasNext(it))
    x <- nextElem(it)
  checkTrue(x > 0)
}

# Test that timeout doesn't get in the way too much
test02 <- function() {
  n <- 1000
  actual <- as.list(timeout(icount(n), time=Inf))
  expected <- as.list(1:n)
  checkEquals(actual, expected)
}

Try the itertools package in your browser

Any scripts or data that you put into this service are public.

itertools documentation built on May 2, 2019, 6:16 p.m.