https://github.com/cran/pracma
Raw File
Tip revision: 3f1c6b45c918375fc2b65bb2a7d6e3590979cb61 authored by HwB on 12 December 2011, 00:00:00 UTC
version 0.9.1
Tip revision: 3f1c6b4
isprime.R
###
### ISPRIME.R  +++ Test suite +++
###


test.isprime <- function(input, expected) {
    output <- do.call(getFromNamespace("isprime", "pracma"), input)
    identical(output, expected)
}

isprime.expected.n1 <- 0
isprime.expected.n2 <- 1
isprime.expected.n100  <- 
    matrix(c(0, 1, 1, 0, 1, 0, 1, 0, 0, 0,
             1, 0, 1, 0, 0, 0, 1, 0, 1, 0,
             0, 0, 1, 0, 0, 0, 0, 0, 1, 0,
             1, 0, 0, 0, 0, 0, 1, 0, 0, 0,
             1, 0, 1, 0, 0, 0, 1, 0, 0, 0,
             0, 0, 1, 0, 0, 0, 0, 0, 1, 0,
             1, 0, 0, 0, 0, 0, 1, 0, 0, 0,
             1, 0, 1, 0, 0, 0, 0, 0, 1, 0,
             0, 0, 1, 0, 0, 0, 0, 0, 1, 0,
             0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ),
           nrow=10, ncol=10, byrow=TRUE)

test.isprime(list(x=1), isprime.expected.n1)
test.isprime(list(x=2), isprime.expected.n2)
test.isprime(list(x=matrix(1:100, 10, 10, byrow=TRUE)),
    isprime.expected.n100)
back to top