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("]~"))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.