R Under development (unstable) (2026-01-23 r89325 ucrt) -- "Unsuffered Consequences" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(mfdb) > library(unittest, quietly = TRUE) > helpers <- c('utils/helpers.R', 'tests/utils/helpers.R') ; source(helpers[file.exists(helpers)]) > > cmp_group <- function (a, b) { + cmp(a[names(a)], b[names(b)]) + } > > ok_group("Can generate groupobjects", { + expect_equal( + class(mfdb_group()), + c("mfdb_group", "mfdb_aggregate")) + + expect_equal( + class(mfdb_group(cows = c("daisy", "freda"))), + c("mfdb_group", "mfdb_aggregate")) + }) # Can generate groupobjects ok - class(mfdb_group()) == c("mfdb_group", "mfdb_aggregat ok - class(mfdb_group(cows = c("dai == c("mfdb_group", "mfdb_aggregat > > ok_group("Can generate a numbered group", { + ok(cmp_group( + mfdb_group_numbered("age", c(4), c(5)), + mfdb_group(age1 = c(4), age2 = c(5)) + ), "groups match") + }) # Can generate a numbered group ok - groups match > > ok_group("Can get a bootstrap group", { + expect_error( + mfdb_bootstrap_group(2, "camel"), + "Second argument should be a mfdb_group") + expect_error( + mfdb_bootstrap_group(0, mfdb_group()), + "Count should be equal or greater than 1") + }) # Can get a bootstrap group ok - Error contained 'Second argument should be a mfdb_group' ok - Error contained 'Count should be equal or greater than 1' > > ok_group("Predefined timestep groups", { + ok(cmp(mfdb_timestep_yearly[[1]], 1:12), "mfdb_timestep_yearly") + ok(cmp(mfdb_timestep_biannually[[1]], 1:6), "mfdb_timestep_biannually") + ok(cmp(mfdb_timestep_biannually[[2]], 7:12), "mfdb_timestep_biannually") + ok(cmp(mfdb_timestep_quarterly[[1]], 1:3), "mfdb_timestep_quarterly") + ok(cmp(mfdb_timestep_quarterly[[2]], 4:6), "mfdb_timestep_quarterly") + ok(cmp(mfdb_timestep_quarterly[[3]], 7:9), "mfdb_timestep_quarterly") + ok(cmp(mfdb_timestep_quarterly[[4]], 10:12), "mfdb_timestep_quarterly") + }) # Predefined timestep groups ok - mfdb_timestep_yearly ok - mfdb_timestep_biannually ok - mfdb_timestep_biannually ok - mfdb_timestep_quarterly ok - mfdb_timestep_quarterly ok - mfdb_timestep_quarterly ok - mfdb_timestep_quarterly > > table_content <- data.frame(sample = 0, name = c('a', 'a', 'a'), value = 1:3) > mdb <- fake_mdb(save_temp_tables = TRUE) > mdb$ret_rows <- list( + "SELECT sample, name, value FROM temp_" = table_content, + "FROM information_schema.tables" = data.frame(count = 0)) > g <- NULL > > ok_group("Aggregates with mfdb_group", local({ + g <<- mfdb_group(a = c(1,"two",3), b = c(88)) + ok(cmp(capture.output(pre_query(mdb, g, "col")), c( + paste0("SELECT COUNT(*) FROM information_schema.tables WHERE (table_schema IN ('fake_schema') OR table_schema = (SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema())) AND table_name IN ('", attr(g, 'table_name'), "')"), + paste0("CREATE TABLE ", attr(g, 'table_name'), " (sample INT DEFAULT 1 NOT NULL, name VARCHAR(10), value INT )"), + paste0("INSERT INTO ", attr(g, 'table_name'), " (sample,name,value) VALUES (0,'a','1'),(0,'a','two'),(0,'a','3'),(0,'b','88')"), + paste0("CREATE INDEX idx_", attr(g, 'table_name') ,"_value_name_sample ON ", attr(g, 'table_name'), " (value,name,sample)"), + paste0("SELECT sample, name, value FROM ", attr(g, 'table_name')), + NULL)), "Created temporary table") + ok("mfdb_smallset" %in% class(pre_query(mdb, g, "col")), "Converted to an mfdb_smallset") + ok(cmp(sample_clause(mdb, g, "col", "out"), "0"), "Sample clause") + ok(cmp(select_clause(mdb, g, "col", "out"), paste0(attr(g, 'table_name'), ".name AS out")), "Select clause") + ok(cmp(from_clause(mdb, g, "col", "out"), attr(g, 'table_name')), "From clause") + ok(cmp(where_clause(mdb, g, "col", "out"), paste0("col = ", attr(g, 'table_name'), ".value")), "Where clause") + + g <<- mfdb_group(a1 = c(1,2,3), badger = c(88, 21), a3 = c(99)) + ok(cmp(capture.output(pre_query(mdb, g, "col")), c( + paste0("SELECT COUNT(*) FROM information_schema.tables WHERE (table_schema IN ('fake_schema') OR table_schema = (SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema())) AND table_name IN ('", attr(g, 'table_name'), "')"), + paste0("CREATE TABLE ", attr(g, 'table_name'), " (sample INT DEFAULT 1 NOT NULL, name VARCHAR(10), value INT )"), + paste0("INSERT INTO ", attr(g, 'table_name'), " (sample,name,value) VALUES (0,'a1',1),(0,'a1',2),(0,'a1',3),(0,'badger',88),(0,'badger',21),(0,'a3',99)"), + paste0("CREATE INDEX idx_", attr(g, 'table_name') ,"_value_name_sample ON ", attr(g, 'table_name'), " (value,name,sample)"), + paste0("SELECT sample, name, value FROM ", attr(g, 'table_name')), + NULL)), "Created temporary table") + ok(cmp(sample_clause(mdb, g, "col", "out"), "0"), "Sample clause") + ok(cmp(select_clause(mdb, g, "col", "out"), paste0(attr(g, 'table_name'), ".name AS out")), "Select clause") + ok(cmp(from_clause(mdb, g, "col", "out"), attr(g, 'table_name')), "From clause") + ok(cmp(where_clause(mdb, g, "col", "out"), paste0("col = ", attr(g, 'table_name'), ".value")), "Where clause") + }, asNamespace('mfdb'))) # Aggregates with mfdb_group ok - Created temporary table SELECT COUNT(*) FROM information_schema.tables WHERE (table_schema IN ('fake_schema') OR table_schema = (SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema())) AND table_name IN ('temp_hfupl') CREATE TABLE temp_hfupl (sample INT DEFAULT 1 NOT NULL, name VARCHAR(10), value INT ) INSERT INTO temp_hfupl (sample,name,value) VALUES (0,'a','1'),(0,'a','two'),(0,'a','3'),(0,'b','88') CREATE INDEX idx_temp_hfupl_value_name_sample ON temp_hfupl (value,name,sample) SELECT sample, name, value FROM temp_hfupl ok - Converted to an mfdb_smallset ok - Sample clause ok - Select clause ok - From clause ok - Where clause ok - Created temporary table ok - Sample clause ok - Select clause ok - From clause ok - Where clause > > ok_group("Large group aggregates don't attempt smallset", local({ + g <<- mfdb_group(a = c(1,"two",3), b = 1:100) + ok(cmp(capture.output(pre_query(mdb, g, "col")), c( + paste0("SELECT COUNT(*) FROM information_schema.tables WHERE (table_schema IN ('fake_schema') OR table_schema = (SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema())) AND table_name IN ('", attr(g, 'table_name'), "')"), + paste0("CREATE TABLE ", attr(g, 'table_name'), " (sample INT DEFAULT 1 NOT NULL, name VARCHAR(10), value INT )"), + paste0("INSERT INTO ", attr(g, 'table_name'), " (sample,name,value) VALUES (0,'a','1'),(0,'a','two'),(0,'a','3'),", paste0("(0,'b','", 1:100,"')", collapse=",")), + paste0("CREATE INDEX idx_", attr(g, 'table_name') ,"_value_name_sample ON ", attr(g, 'table_name'), " (value,name,sample)"), + NULL)), "Created temporary table") + ok(!("mfdb_smallset" %in% class(pre_query(mdb, g, "col"))), "Not a a mfdb_smallset") + ok(cmp(sample_clause(mdb, g, "col", "out"), "0"), "Sample clause") + ok(cmp(select_clause(mdb, g, "col", "out"), paste0(attr(g, 'table_name'), ".name AS out")), "Select clause") + ok(cmp(from_clause(mdb, g, "col", "out"), attr(g, 'table_name')), "From clause") + ok(cmp(where_clause(mdb, g, "col", "out"), paste0("col = ", attr(g, 'table_name'), ".value")), "Where clause") + + g <<- mfdb_group(a1 = c(1,2,3), badger = c(88, 21), a3 = c(99)) + ok(cmp(capture.output(pre_query(mdb, g, "col")), c( + paste0("SELECT COUNT(*) FROM information_schema.tables WHERE (table_schema IN ('fake_schema') OR table_schema = (SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema())) AND table_name IN ('", attr(g, 'table_name'), "')"), + paste0("CREATE TABLE ", attr(g, 'table_name'), " (sample INT DEFAULT 1 NOT NULL, name VARCHAR(10), value INT )"), + paste0("INSERT INTO ", attr(g, 'table_name'), " (sample,name,value) VALUES (0,'a1',1),(0,'a1',2),(0,'a1',3),(0,'badger',88),(0,'badger',21),(0,'a3',99)"), + paste0("CREATE INDEX idx_", attr(g, 'table_name') ,"_value_name_sample ON ", attr(g, 'table_name'), " (value,name,sample)"), + paste0("SELECT sample, name, value FROM ", attr(g, 'table_name')), + NULL)), "Created temporary table") + ok(cmp(sample_clause(mdb, g, "col", "out"), "0"), "Sample clause") + ok(cmp(select_clause(mdb, g, "col", "out"), paste0(attr(g, 'table_name'), ".name AS out")), "Select clause") + ok(cmp(from_clause(mdb, g, "col", "out"), attr(g, 'table_name')), "From clause") + ok(cmp(where_clause(mdb, g, "col", "out"), paste0("col = ", attr(g, 'table_name'), ".value")), "Where clause") + }, asNamespace('mfdb'))) # Large group aggregates don't attempt smallset ok - Created temporary table SELECT COUNT(*) FROM information_schema.tables WHERE (table_schema IN ('fake_schema') OR table_schema = (SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema())) AND table_name IN ('temp_mqtdu') CREATE TABLE temp_mqtdu (sample INT DEFAULT 1 NOT NULL, name VARCHAR(10), value INT ) INSERT INTO temp_mqtdu (sample,name,value) VALUES (0,'a','1'),(0,'a','two'),(0,'a','3'),(0,'b','1'),(0,'b','2'),(0,'b','3'),(0,'b','4'),(0,'b','5'),(0,'b','6'),(0,'b','7'),(0,'b','8'),(0,'b','9'),(0,'b','10'),(0,'b','11'),(0,'b','12'),(0,'b','13'),(0,'b','14'),(0,'b','15'),(0,'b','16'),(0,'b','17'),(0,'b','18'),(0,'b','19'),(0,'b','20'),(0,'b','21'),(0,'b','22'),(0,'b','23'),(0,'b','24'),(0,'b','25'),(0,'b','26'),(0,'b','27'),(0,'b','28'),(0,'b','29'),(0,'b','30'),(0,'b','31'),(0,'b','32'),(0,'b','33'),(0,'b','34'),(0,'b','35'),(0,'b','36'),(0,'b','37'),(0,'b','38'),(0,'b','39'),(0,'b','40'),(0,'b','41'),(0,'b','42'),(0,'b','43'),(0,'b','44'),(0,'b','45'),(0,'b','46'),(0,'b','47'),(0,'b','48'),(0,'b','49'),(0,'b','50'),(0,'b','51'),(0,'b','52'),(0,'b','53'),(0,'b','54'),(0,'b','55'),(0,'b','56'),(0,'b','57'),(0,'b','58'),(0,'b','59'),(0,'b','60'),(0,'b','61'),(0,'b','62'),(0,'b','63'),(0,'b','64'),(0,'b','65'),(0,'b','66'),(0,'b','67'),(0,'b','68'),(0,'b','69'),(0,'b','70'),(0,'b','71'),(0,'b','72'),(0,'b','73'),(0,'b','74'),(0,'b','75'),(0,'b','76'),(0,'b','77'),(0,'b','78'),(0,'b','79'),(0,'b','80'),(0,'b','81'),(0,'b','82'),(0,'b','83'),(0,'b','84'),(0,'b','85'),(0,'b','86'),(0,'b','87'),(0,'b','88'),(0,'b','89'),(0,'b','90'),(0,'b','91'),(0,'b','92'),(0,'b','93'),(0,'b','94'),(0,'b','95'),(0,'b','96'),(0,'b','97'),(0,'b','98'),(0,'b','99'),(0,'b','100') CREATE INDEX idx_temp_mqtdu_value_name_sample ON temp_mqtdu (value,name,sample) ok - Not a a mfdb_smallset ok - Sample clause ok - Select clause ok - From clause ok - Where clause ok - Created temporary table ok - Sample clause ok - Select clause ok - From clause ok - Where clause > > mdb$ret_rows <- list( + "SELECT sample, name, value FROM temp_" = data.frame(), + "FROM information_schema.tables" = data.frame(count = 1)) > ok_group("Aggregates with mfdb_group that's already been created", local({ + g <<- mfdb_group(a = c(1,"two",3), b = c(88)) + ok(cmp(capture.output(pre_query(mdb, g, "col")), c( + paste0("SELECT COUNT(*) FROM information_schema.tables WHERE (table_schema IN ('fake_schema') OR table_schema = (SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema())) AND table_name IN ('", attr(g, 'table_name'), "')"), + NULL)), "Don't recreate temporary table") + }, asNamespace('mfdb'))) # Aggregates with mfdb_group that's already been created ok - Don't recreate temporary table > mdb$ret_rows <- list( + "SELECT sample, name, value FROM temp_" = data.frame(), + "FROM information_schema.tables" = data.frame(count = 0)) > > ok_group("Aggregates with mfdb_bootstrap_group", local({ + g <<- mfdb_bootstrap_group(2, mfdb_group(camels = c(44), aardvarks = c(88))) + ok(cmp(capture.output(pre_query(mdb, g, "col")), c( + paste0("SELECT COUNT(*) FROM information_schema.tables WHERE (table_schema IN ('fake_schema') OR table_schema = (SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema())) AND table_name IN ('", attr(g, 'table_name'), "')"), + paste0("CREATE TABLE ", attr(g, 'table_name'), " (sample INT DEFAULT 1 NOT NULL, name VARCHAR(10), value INT )"), + paste0("INSERT INTO ", attr(g, 'table_name'), " (sample,name,value) VALUES (1,'camels',44),(1,'aardvarks',88),(2,'camels',44),(2,'aardvarks',88)"), + paste0("CREATE INDEX idx_", attr(g, 'table_name') ,"_value_name_sample ON ", attr(g, 'table_name'), " (value,name,sample)"), + paste0("SELECT sample, name, value FROM ", attr(g, 'table_name')), + NULL)), "Created temporary table") + ok(cmp(sample_clause(mdb, g, "col", "out"), paste0(attr(g, 'table_name'), ".sample")), "Sample clause") + ok(cmp(select_clause(mdb, g, "col", "out"), paste0(attr(g, 'table_name'), ".name AS out")), "Select clause") + ok(cmp(from_clause(mdb, g, "col", "out"), attr(g, 'table_name')), "From clause") + ok(cmp(where_clause(mdb, g, "col", "out"), paste0("col = ", attr(g, 'table_name'), ".value")), "Where clause") + ok(cmp(agg_summary(mdb, g, 'col', 'out', data.frame(bssample = "1.1.1"), 1), list( + camels = 44, + aardvarks = 88 + )), "Aggregation summary (sample 1)") + ok(cmp(agg_summary(mdb, g, 'col', 'out', data.frame(bssample = "2.2.2"), 2), list( + camels = 44, + aardvarks = 88 + )), "Aggregation summary (sample 2)") + + g <<- mfdb_bootstrap_group(2, mfdb_group(g1 = c(44, 55), g2 = c(88, 99)), seed = 123456) + ok(cmp(capture.output(pre_query(mdb, g, "col")), c( + paste0("SELECT COUNT(*) FROM information_schema.tables WHERE (table_schema IN ('fake_schema') OR table_schema = (SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema())) AND table_name IN ('", attr(g, 'table_name'), "')"), + paste0("CREATE TABLE ", attr(g, 'table_name'), " (sample INT DEFAULT 1 NOT NULL, name VARCHAR(10), value INT )"), + paste0("INSERT INTO ", attr(g, 'table_name'), " (sample,name,value) VALUES (1,'g1',55),(1,'g1',55),(1,'g2',88),(1,'g2',88),(2,'g1',44),(2,'g1',44),(2,'g2',99),(2,'g2',88)"), + paste0("CREATE INDEX idx_", attr(g, 'table_name') ,"_value_name_sample ON ", attr(g, 'table_name'), " (value,name,sample)"), + paste0("SELECT sample, name, value FROM ", attr(g, 'table_name')), + NULL)), "Created temporary table") + ok(cmp(sample_clause(mdb, g, "col", "out"), paste0(attr(g, 'table_name'), ".sample")), "Sample clause") + ok(cmp(select_clause(mdb, g, "col", "out"), paste0(attr(g, 'table_name'), ".name AS out")), "Select clause") + ok(cmp(from_clause(mdb, g, "col", "out"), attr(g, 'table_name')), "From clause") + ok(cmp(where_clause(mdb, g, "col", "out"), paste0("col = ", attr(g, 'table_name'), ".value")), "Where clause") + ok(cmp(agg_summary(mdb, g, 'col', 'out', data.frame(bssample = "1.1.1"), 1), list( + g1 = c(55, 55), + g2 = c(88, 88) + )), "Aggregation summary (sample 1)") + ok(cmp(agg_summary(mdb, g, 'col', 'out', data.frame(bssample = "2.0.0"), 2), list( + g1 = c(44, 44), + g2 = c(99, 88) + )), "Aggregation summary (sample 2)") + + # Test a few more random combinations + g <<- mfdb_bootstrap_group(2, mfdb_group(g1 = c(44, 55), g2 = c(88, 99)), seed = 8081) + ok(cmp(capture.output(pre_query(mdb, g, "col")), c( + paste0("SELECT COUNT(*) FROM information_schema.tables WHERE (table_schema IN ('fake_schema') OR table_schema = (SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema())) AND table_name IN ('", attr(g, 'table_name'), "')"), + paste0("CREATE TABLE ", attr(g, 'table_name'), " (sample INT DEFAULT 1 NOT NULL, name VARCHAR(10), value INT )"), + paste0("INSERT INTO ", attr(g, 'table_name'), " (sample,name,value) VALUES (1,'g1',44),(1,'g1',55),(1,'g2',99),(1,'g2',99),(2,'g1',44),(2,'g1',55),(2,'g2',99),(2,'g2',99)"), + paste0("CREATE INDEX idx_", attr(g, 'table_name') ,"_value_name_sample ON ", attr(g, 'table_name'), " (value,name,sample)"), + paste0("SELECT sample, name, value FROM ", attr(g, 'table_name')), + NULL)), "Created temporary table") + + g <<- mfdb_bootstrap_group(2, mfdb_group(g1 = c(44, 55), g2 = c(88, 99)), seed = 203785) + ok(cmp(capture.output(pre_query(mdb, g, "col")), c( + paste0("SELECT COUNT(*) FROM information_schema.tables WHERE (table_schema IN ('fake_schema') OR table_schema = (SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema())) AND table_name IN ('", attr(g, 'table_name'), "')"), + paste0("CREATE TABLE ", attr(g, 'table_name'), " (sample INT DEFAULT 1 NOT NULL, name VARCHAR(10), value INT )"), + paste0("INSERT INTO ", attr(g, 'table_name'), " (sample,name,value) VALUES (1,'g1',55),(1,'g1',55),(1,'g2',99),(1,'g2',99),(2,'g1',44),(2,'g1',44),(2,'g2',88),(2,'g2',99)"), + paste0("CREATE INDEX idx_", attr(g, 'table_name') ,"_value_name_sample ON ", attr(g, 'table_name'), " (value,name,sample)"), + paste0("SELECT sample, name, value FROM ", attr(g, 'table_name')), + NULL)), "Created temporary table") + ok(cmp(agg_summary(mdb, g, 'col', 'out', data.frame(bssample = "0.1"), 1), list( + g1 = c(55, 55), + g2 = c(99, 99) + )), "Aggregation summary (sample 1)") + ok(cmp(agg_summary(mdb, g, 'col', 'out', data.frame(bssample = "0.2"), 2), list( + g1 = c(44, 44), + g2 = c(88, 99) + )), "Aggregation summary (sample 2)") + }, asNamespace('mfdb'))) # Aggregates with mfdb_bootstrap_group ok - Created temporary table ok - Sample clause ok - Select clause ok - From clause ok - Where clause ok - Aggregation summary (sample 1) ok - Aggregation summary (sample 2) ok - Created temporary table ok - Sample clause ok - Select clause ok - From clause ok - Where clause ok - Aggregation summary (sample 1) ok - Aggregation summary (sample 2) ok - Created temporary table ok - Created temporary table ok - Aggregation summary (sample 1) ok - Aggregation summary (sample 2) Warning messages: 1: In set.seed(seed, kind = "Mersenne-Twister", normal.kind = "Inversion", : non-uniform 'Rounding' sampler used 2: In set.seed(seed, kind = "Mersenne-Twister", normal.kind = "Inversion", : non-uniform 'Rounding' sampler used 3: In set.seed(seed, kind = "Mersenne-Twister", normal.kind = "Inversion", : non-uniform 'Rounding' sampler used 4: In set.seed(seed, kind = "Mersenne-Twister", normal.kind = "Inversion", : non-uniform 'Rounding' sampler used > > ok_group("Aggregates with mfdb_group areas", local({ + # Areas are a special case, they have to be broken down into areacells first + g <<- mfdb_group(a = c(1,2,3), b = c(88, 89)) + ok(cmp(capture.output(pre_query(mdb, g, "c.areacell_id")), c( + paste0("SELECT COUNT(*) FROM information_schema.tables WHERE (table_schema IN ('fake_schema') OR table_schema = (SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema())) AND table_name IN ('", attr(g, 'table_name'), "')"), + paste0("CREATE TABLE ", attr(g, 'table_name'), " (sample INT DEFAULT 1 NOT NULL, name VARCHAR(10), value INT )"), + paste0("INSERT INTO ", attr(g, 'table_name'), " SELECT 0 AS sample, 'a' AS name, areacell_id AS value FROM (SELECT division, areacell_id FROM division UNION SELECT name, areacell_id FROM areacell) divac WHERE division IN ('1','2','3')"), + paste0("INSERT INTO ", attr(g, 'table_name'), " SELECT 0 AS sample, 'b' AS name, areacell_id AS value FROM (SELECT division, areacell_id FROM division UNION SELECT name, areacell_id FROM areacell) divac WHERE division IN ('88','89')"), + paste0("CREATE INDEX idx_", attr(g, 'table_name') ,"_value_name_sample ON ", attr(g, 'table_name'), " (value,name,sample)"), + paste0("SELECT sample, name, value FROM ", attr(g, 'table_name')), + NULL)), "Created temporary table") + }, asNamespace('mfdb'))) # Aggregates with mfdb_group areas ok - Created temporary table > > ok_group("Seed handling", { + # Helper to define groups with a given seed + orig_group <- mfdb_group(g1 = c(44, 55), g2 = c(88, 99)) + bs_group <- function (seed) { mfdb_bootstrap_group(2, orig_group, seed = seed) } + + # Repeatedly manage to make the same sample group (also tested by above tests) + ok(cmp(bs_group(99), bs_group(99)), "Forced seed creates the same group") + + # Seed before == seed after + old_seed <- .Random.seed + bs_group(433) + ok(cmp(old_seed, .Random.seed), "The PRNG state got restored with set seed") + old_seed <- .Random.seed + bs_group(NULL) + ok(cmp(old_seed, .Random.seed), "The PRNG state got restored with NULL seed") + + # Works if there is no seed set yet + remove(".Random.seed", pos = globalenv()) + ok(cmp_group(bs_group(123456), bs_group(123456)), "Managed to generate groups before seed is set") + }) # Seed handling ok - Forced seed creates the same group ok - The PRNG state got restored with set seed ok - The PRNG state got restored with NULL seed ok - Managed to generate groups before seed is set Warning messages: 1: In set.seed(seed, kind = "Mersenne-Twister", normal.kind = "Inversion", : non-uniform 'Rounding' sampler used 2: In set.seed(seed, kind = "Mersenne-Twister", normal.kind = "Inversion", : non-uniform 'Rounding' sampler used 3: In set.seed(seed, kind = "Mersenne-Twister", normal.kind = "Inversion", : non-uniform 'Rounding' sampler used 4: In set.seed(seed, kind = "Mersenne-Twister", normal.kind = "Inversion", : non-uniform 'Rounding' sampler used 5: In set.seed(seed, kind = "Mersenne-Twister", normal.kind = "Inversion", : non-uniform 'Rounding' sampler used 6: In set.seed(seed, kind = "Mersenne-Twister", normal.kind = "Inversion", : non-uniform 'Rounding' sampler used > > proc.time() user system elapsed 1.01 0.06 1.01 1..58 # Looks like you passed all 58 tests.