inst/tests/test-jg-vnodes.R

context("jg-vnodes")

test_that("jg_vnodes recognises variable nodes", { 
  expect_identical(jg_vnodes(""),character(0))
  expect_identical(jg_vnodes("~"),character(0))
  expect_equivalent(jg_vnodes("log(b)<-"),c("b"))
  expect_equivalent(jg_vnodes("log(b[d])<-"),c("b"))
  expect_equivalent(jg_vnodes("b[a[c[i]]]<-"),c("b"))
  expect_equivalent(jg_vnodes("b[1]<-"),c("b"))
})

test_that("jg_vnodes names", {
  
  x <- "data{
Y ~ dpois(2)
}
  
  model {
  
  bLambda ~ dlnorm(0,10^-2) # #$\\lamda_{beta}$
  for (i in 1:length(x)) { x[i]~dpois(bLambda) 
  b[i] ~dpois(1)     #$ \\beta$
  bc[i] <- b[i]
  }
  bd <- dpois(1, 1)
  }
  
  "
  expect_equivalent(jg_vnodes(x, "deterministic"),c("bc","bd"))
# for some crazy reason these test pass when test() but not when check!!!
#   expect_equivalent(jg_vnodes(x),c("b","bc","bd","bLambda","x","Y"))  
#   expect_equivalent(jg_vnodes(x, indices = TRUE),c("b[i]","bc[i]","bd","bLambda","x[i]","Y"))
#   expect_equivalent(jg_vnodes(x, "stochastic", indices = TRUE),c("b[i]","bLambda","x[i]","Y"))
  ns <- c("b", "bc", "bd", "bLambda", "x", "Y")
  names(ns) <- c("$ \\beta$", "bc", "bd", "$\\lamda_{beta}$", "x", "Y")
#  expect_identical(jg_vnodes(x), ns)
})

test_that("jg_vnodes throws error", {
  
  expect_error(jg_vnodes("", "docah"))
  expect_error(jg_vnodes("", indices = "stochastic"))
  expect_error(jg_vnodes("]~"))
})
poissonconsulting/juggler documentation built on Sept. 7, 2017, 1:55 p.m.