|
| 1 | +test_that("the same seed returns the same result", { |
| 2 | + |
| 3 | + # Run model twice using same run number (which will set the seed) |
| 4 | + env1 <- model(run_number=0, param=defaults()) |
| 5 | + env2 <- model(run_number=0, param=defaults()) |
| 6 | + |
| 7 | + # Compare output results |
| 8 | + expect_identical( |
| 9 | + env1 %>% get_mon_arrivals(), |
| 10 | + env2 %>% get_mon_arrivals()) |
| 11 | + expect_identical( |
| 12 | + env1 %>% get_mon_resources(), |
| 13 | + env2 %>% get_mon_resources()) |
| 14 | + |
| 15 | + # Conversely, if run with different run number, expect different |
| 16 | + env1 <- model(run_number=0, param=defaults()) |
| 17 | + env2 <- model(run_number=1, param=defaults()) |
| 18 | + |
| 19 | + # Compare output results |
| 20 | + expect_failure(expect_identical( |
| 21 | + env1 %>% get_mon_arrivals(), |
| 22 | + env2 %>% get_mon_arrivals())) |
| 23 | + expect_failure(expect_identical( |
| 24 | + env1 %>% get_mon_resources(), |
| 25 | + env2 %>% get_mon_resources())) |
| 26 | + |
| 27 | + # Repeat experiment, but with multiple replications |
| 28 | + envs1 <- trial(param=defaults()) |
| 29 | + envs2 <- trial(param=defaults()) |
| 30 | + |
| 31 | + # Aggregate results from replications in each trial, then compare full trial |
| 32 | + expect_identical( |
| 33 | + do.call(rbind, lapply(envs1, get_mon_arrivals)), |
| 34 | + do.call(rbind, lapply(envs2, get_mon_arrivals))) |
| 35 | + expect_identical( |
| 36 | + do.call(rbind, lapply(envs1, get_mon_resources)), |
| 37 | + do.call(rbind, lapply(envs2, get_mon_resources))) |
| 38 | +}) |
0 commit comments