tests/testthat/test_cache.R

data <- bnlearn::learning.test
scorer <- CreateScorer(data = data)
cache <- BuildCache(scorer)
cached_scorer <- CachedScorer(scorer)

testthat::test_that('CachedScorer returns function', {
  testthat::expect_true(methods::is(cached_scorer, 'function'))
})

testthat::test_that('Cached scorer looks up correct score', {
  testthat::expect_true(cached_scorer('A', c('B', 'C')) < 0.0)
  testthat::expect_true(cached_scorer('A', c()) < 0.0)
  testthat::expect_true(cached_scorer('A', NULL) < 0.0)
  testthat::expect_equal(cached_scorer('A', c('B', 'C')),
                         BNLearnScorer('A', c('B', 'C'), data = data))
  testthat::expect_equal(cached_scorer('A', c()),
                         BNLearnScorer('A', c(), data = data))  
})

Try the cia package in your browser

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

cia documentation built on April 4, 2025, 5:23 a.m.