File: test_cache.R

package info (click to toggle)
r-bioc-biobase 2.24.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,288 kB
  • ctags: 64
  • sloc: ansic: 711; makefile: 5; sh: 3
file content (35 lines) | stat: -rw-r--r-- 951 bytes parent folder | download | duplicates (7)
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
test_cache_basic <- function() {
    pre <- "tmp_R_TEST_"
    cfile <- file.path(tempdir(), paste(pre, "theVar.RData", sep=""))
    on.exit(file.remove(cfile), add=TRUE)
    
    expensive <- function(n) n + 1
    cache(theVar <- expensive(5), dir=tempdir(), prefix=pre)
    checkEquals(6, theVar)
    checkTrue(file.exists(cfile))
    ## call again
    remove(theVar)
    cache(theVar <- expensive(5), dir=tempdir(), prefix=pre)
    checkEquals(6, theVar)
}


test_cache_infunc <- function() {
    pre <- "tmp_R_TEST_"
    cfile <- file.path(tempdir(), paste(pre, "theVar.RData", sep=""))
    on.exit(file.remove(cfile), add=TRUE)

    expensive <- function(n) n + 1
    aFunc <- function() {
        m <- 1
        cache(theVar <- expensive(m), dir=tempdir(), prefix=pre)
        theVar
    }
    val <- aFunc()
    checkEquals(2, val)
    checkTrue(file.exists(cfile))
    ## call again
    remove(val)
    val <- aFunc()
    checkEquals(2, val)
}