tests/testthat/test_sim.R

library(HMMCPP)

context("Simulation of HMM")
test_that("Rcpp_sample works",{
  set.seed(2015)
  x <- replicate(100, Rcpp_sample(prob = rep(1/2,2)))
  expect_equivalent(sum(x==0), 55)
  expect_equivalent(sum(x==1), 45)
})

test_that("Sim HMM works",{
  A <- matrix(c(0.9,0.1, 0.1, 0.9), nrow = 2)
  B <- matrix(c(rep(1/6,6),
                rep(1/10,5), 1/2),
              nrow = 2,
              byrow = TRUE)
  set.seed(9987)
  x <- sim_HMM(initial_prop = rep(1/2,2),
               n_sims = 10,
               A = A,
               state_sym = c("F","B"),
               B = B,
               obs_sym = 1:6)
  expect_equal(sum(x$states_N==1), 7)
  expect_equal(sum(x$states=="F"), 3)
  expect_equal(sum(x$obs=="3"), 3)
  expect_equal(sum(x$observation=="4"), 3)
}
)
jonotuke/HMMCPP documentation built on May 19, 2019, 8:34 p.m.