context("Testing Ising Glauber Model Dynamics")
with_seed <- function(seed, code) {
code <- substitute(code)
orig.seed <- .Random.seed
on.exit(.Random.seed <<- orig.seed)
set.seed(seed)
eval.parent(code)
}
SEED_VALUE <- 12345
### Ising Glauber Model Dynamics --------------------------------------------------
test_that("Test Ising Glauber Model Dynamics Ground Truth", {
input <- matrix(
cbind(
c(1.0, 1.0, 2.0, 3.0),
c(0.0, 0.0, 1.0, 0.0),
c(0.0, 0.0, 0.0, 1.0),
c(0.0, 0.0, 0.0, 0.0)
),
nrow = 4
)
results <- simulate_ising(input, 5, .5)
expect_equal(results$ground_truth, input)
})
test_that("Test Ising Glauber Model Dynamics Time Series Dimensions", {
input <- matrix(
cbind(
c(1.0, 1.0, 2.0, 3.0),
c(0.0, 0.0, 1.0, 0.0),
c(0.0, 0.0, 0.0, 1.0),
c(0.0, 0.0, 0.0, 0.0)
),
nrow = 4
)
results <- simulate_ising(input, 5)
expect_equal(nrow(results$TS), nrow(input))
expect_equal(ncol(results$TS), 5)
})
test_that("Test Ising Glauber Model Dynamics Random", {
input <- matrix(
cbind(
c(1.0, 1.0, 2.0, 3.0),
c(0.0, 0.0, 1.0, 0.0),
c(0.0, 0.0, 0.0, 1.0),
c(0.0, 0.0, 0.0, 0.0)
),
nrow = 4
)
results_random <- simulate_ising(input, 5)
results_random2 <- simulate_ising(input, 5)
expect_equal(results_random$ground_truth, input)
expect_equal(results_random2$ground_truth, input)
with_seed(SEED_VALUE, {
results_not_random <- simulate_ising(input, 5)
results_not_random2 <- simulate_ising(input, 5)
expect_equal(results_not_random$ground_truth, input)
expect_equal(results_not_random2$ground_truth, input)
expect_false(identical(results_random$TS, results_random2$TS))
})
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.