|
| 1 | +test_that("Trial run: subject_id globally unique with mixed n_readouts across arms", { |
| 2 | + # Arm A: 3 subjects, 1 readout each -> 3 rows |
| 3 | + dataA <- data.frame( |
| 4 | + id = c(1, 2, 3), |
| 5 | + value = c(1, 2, 3), |
| 6 | + readout_time = 0 |
| 7 | + ) |
| 8 | + popA <- Population$new("A", data = dataA, n_readouts = 1L) |
| 9 | + |
| 10 | + # Arm B: 3 subjects, 2 readouts each -> 6 rows |
| 11 | + dataB <- data.frame( |
| 12 | + id = c(1, 1, 2, 2, 3, 3), |
| 13 | + value = c(4, 4, 5, 5, 6, 6), |
| 14 | + readout_time = rep(c(0, 1), 3) |
| 15 | + ) |
| 16 | + popB <- Population$new("B", data = dataB, n_readouts = 2L) |
| 17 | + |
| 18 | + timer <- Timer$new("t") |
| 19 | + timer$add_timepoint(time = 1, arm = "A", enroller = 3L, dropper = 0L) |
| 20 | + timer$add_timepoint(time = 1, arm = "B", enroller = 3L, dropper = 0L) |
| 21 | + |
| 22 | + trigger_by_calendar(1, timer, analysis = function(df, current_time) df) |
| 23 | + |
| 24 | + trial <- Trial$new( |
| 25 | + name = "mixed_readouts", |
| 26 | + seed = 1, |
| 27 | + timer = timer, |
| 28 | + population = list(popA, popB) |
| 29 | + ) |
| 30 | + |
| 31 | + trial$run() |
| 32 | + |
| 33 | + snap <- trial$locked_data[["time_1"]] |
| 34 | + |
| 35 | + expect_equal(nrow(snap), 9L) |
| 36 | + |
| 37 | + expect_equal(sort(unique(snap$subject_id)), 1:6) |
| 38 | + |
| 39 | + rows_A <- snap[snap$subject_id %in% 1:3, ] |
| 40 | + expect_true(all(table(rows_A$subject_id) == 1)) |
| 41 | + |
| 42 | + rows_B <- snap[snap$subject_id %in% 4:6, ] |
| 43 | + expect_true(all(table(rows_B$subject_id) == 2)) |
| 44 | +}) |
0 commit comments