@@ -181,3 +181,89 @@ test_that("rates regression: simulate, estimate, compare, plot", {
181181 col = c(" #2C7FB8" , " #D95F02" ), lwd = 2 , bty = " n" )
182182 }
183183})
184+
185+ test_that(" rates regression: identical outputs with fixed seed" , {
186+ testthat :: skip_on_cran()
187+ if (Sys.getenv(" RSOCSIM_RUN_INTEGRATION_TESTS" ) != " 1" ) {
188+ testthat :: skip(paste(
189+ " Integration test disabled." ,
190+ " Enable by setting RSOCSIM_RUN_INTEGRATION_TESTS=1." ,
191+ " In PowerShell: $Env:RSOCSIM_RUN_INTEGRATION_TESTS=\" 1\" " ,
192+ " In R: Sys.setenv(RSOCSIM_RUN_INTEGRATION_TESTS=\" 1\" )"
193+ ))
194+ }
195+
196+ if (! exists(" startSocsimWithFile" , where = asNamespace(" rsocsim" ), mode = " function" )) {
197+ testthat :: skip(" Compiled backend not available." )
198+ }
199+
200+ simdir <- file.path(tempdir(), " rsocsim-rates-regression-fixed-seed" )
201+ dir.create(simdir , showWarnings = FALSE , recursive = TRUE )
202+ print(paste(c(" simdir: " , simdir )))
203+
204+ fert_src <- system.file(" extdata" , " SWEfert2022" , package = " rsocsim" , mustWork = TRUE )
205+ mort_src <- system.file(" extdata" , " SWEmort2022" , package = " rsocsim" , mustWork = TRUE )
206+ init_src <- system.file(" extdata" , " init_new.opop" , package = " rsocsim" , mustWork = TRUE )
207+
208+ file.copy(fert_src , file.path(simdir , " SWEfert2022" ), overwrite = TRUE )
209+ file.copy(mort_src , file.path(simdir , " SWEmort2022" ), overwrite = TRUE )
210+ file.copy(init_src , file.path(simdir , " init_new.opop" ), overwrite = TRUE )
211+ file.create(file.path(simdir , " init_new.omar" ))
212+
213+ sup_content <- c(
214+ " marriage_queues 1" ,
215+ " bint 10" ,
216+ " segments 1" ,
217+ " marriage_eval distribution" ,
218+ " marriage_after_childbirth 1" ,
219+ " input_file init_new" ,
220+ " duration 1200" ,
221+ " include SWEfert2022" ,
222+ " include SWEmort2022" ,
223+ " run"
224+ )
225+ sup_path <- file.path(simdir , " socsim.sup" )
226+ writeLines(sup_content , sup_path )
227+
228+ seed_env <- Sys.getenv(" RSOCSIM_RATES_SEED" , " 123456" )
229+ seed <- if (seed_env == " random" ) " 123456" else seed_env
230+ suffix <- " rates_fixed_seed"
231+
232+ print(paste0(" Fixed-seed reproducibility check. Using seed=" , seed , " ." ))
233+ result1 <- socsim(simdir , " socsim.sup" , seed = seed , process_method = " inprocess" , suffix = suffix )
234+ expect_equal(result1 , 1 )
235+
236+ output_dir1 <- file.path(simdir , paste0(" sim_results_" , seed , " _" , suffix ))
237+ opop_path1 <- file.path(output_dir1 , " result.opop" )
238+ omar_path1 <- file.path(output_dir1 , " result.omar" )
239+
240+ expect_true(file.exists(opop_path1 ))
241+ expect_true(file.exists(omar_path1 ))
242+
243+ opop1 <- read_opop(fn = opop_path1 )
244+ omar1 <- read_omar(fn = omar_path1 )
245+
246+ result2 <- socsim(simdir , " socsim.sup" , seed = seed , process_method = " inprocess" , suffix = suffix )
247+ expect_equal(result2 , 1 )
248+
249+ output_dir2 <- file.path(simdir , paste0(" sim_results_" , seed , " _" , suffix ))
250+ opop_path2 <- file.path(output_dir2 , " result.opop" )
251+ omar_path2 <- file.path(output_dir2 , " result.omar" )
252+
253+ expect_true(file.exists(opop_path2 ))
254+ expect_true(file.exists(omar_path2 ))
255+
256+ opop2 <- read_opop(fn = opop_path2 )
257+ omar2 <- read_omar(fn = omar_path2 )
258+
259+ identical_opop <- isTRUE(all.equal(opop1 , opop2 , check.attributes = TRUE ))
260+ identical_omar <- isTRUE(all.equal(omar1 , omar2 , check.attributes = TRUE ))
261+
262+ print(paste0(
263+ " Fixed-seed reproducibility outcome: opop identical=" , identical_opop ,
264+ " , omar identical=" , identical_omar , " ."
265+ ))
266+
267+ expect_true(identical_opop )
268+ expect_true(identical_omar )
269+ })
0 commit comments