Skip to content

Commit e62ee9d

Browse files
committed
test: convert Simulations tests to snapshot tests and add mocks
- Convert grepl-based tests to expect_snap() for consistency: - knit_print.Simulations - knit_print.DASimulations - knit_print.GeneralSimulationsSummary - knit_print.SimulationsSummary - Add mocks for .DefaultSimulations, .DefaultDASimulations, and .DefaultSimulationsSummary to ensure stable snapshots - Add SimulationsSummary fixture generation - Regenerate all fixtures for consistency
1 parent e338ffb commit e62ee9d

11 files changed

+72
-67
lines changed

tests/testthat/_snaps/Linux/helpers_knitr_Simulations.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
Output
66
[1] "### Simulation Results\n\n- **Number of simulations:** 2\n- **Random seed:** 123\n- **Dose grid size:** 3\n- **Final recommended doses:** 1.00, 2.00\n\n"
77

8+
# knit_print.Simulations works correctly
9+
10+
Code
11+
knit_print(.DefaultSimulations(), asis = FALSE)
12+
Output
13+
[1] "### Simulation Results\n\n- **Number of simulations:** 1\n- **Random seed:** 819\n- **Dose grid size:** 11\n- **Final recommended doses:** 15.00\n\n- **Stopping reasons:** Number of cohorts is 9 and thus reached the prespecified minimum number 3 (100.0%), Number of patients is 17 and thus below the prespecified minimum number 20 (100.0%), Probability for target toxicity is 52 % for dose 15 and thus above the required 50 % (100.0%)\n\n"
14+
815
# knit_print.DualSimulations works correctly
916

1017
Code
@@ -33,12 +40,33 @@
3340
Output
3441
[1] "### Simulation Results\n\n- **Number of simulations:** 2\n- **Random seed:** 123\n- **Dose grid size:** 2\n- **Final recommended doses:** 1.00, 2.00\n\n- **TD target during trial:** Mean = 62.50\n- **TD target end of trial:** Mean = 70.00\n- **Stopping reasons:** A (50.0%), B (50.0%)\n\n- **Gstar estimates:** Mean = 105.00, Range = [100.00, 110.00]\n- **Optimal dose:** Mean = 105.00\n\n- **Sigma2 beta W estimates:** Mean = 0.013, Range = [0.010, 0.015]\n\n"
3542

43+
# knit_print.DASimulations works correctly
44+
45+
Code
46+
knit_print(.DefaultDASimulations(), asis = FALSE)
47+
Output
48+
[1] "### Simulation Results\n\n- **Number of simulations:** 2\n- **Random seed:** 819\n- **Dose grid size:** 42\n- **Final recommended doses:** 16.00, 28.00\n\n- **Stopping reasons:** Number of patients is 20 and thus below the prespecified minimum number 50 (50.0%), Number of patients is 22 and thus below the prespecified minimum number 50 (50.0%), Probability for target toxicity is 51 % for dose 16 and thus above the required 50 % (50.0%), Probability for target toxicity is 59 % for dose 28 and thus above the required 50 % (50.0%)\n\n- **Trial duration:** Mean = 111.00, Range = [110.00, 112.00]\n\n"
49+
50+
# knit_print.GeneralSimulationsSummary works correctly
51+
52+
Code
53+
knit_print(.DefaultSimulationsSummary(), asis = FALSE)
54+
Output
55+
[1] "### Simulation Summary (1 simulations)\n\n**Target toxicity interval:** [20.0%, 35.0%]\n\n**Target dose interval:** [NA, NA]\n\n**Dose most often selected as MTD:** 15 (observed toxicity rate: NaN%)\n\n**Proportion selecting target MTD:** 0.0%\n\n**Number of patients:** 17\n\n**Patients treated above target:** 0\n\n**Fitted toxicity at dose most selected:** 0.249\n\n**Stopping rules triggered:** NA (100.0%), NA (100.0%), ≥ 3 cohorts dosed (100.0%), P(0.2 ≤ prob(DLE | NBD) ≤ 0.35) ≥ 0.5 (100.0%), ≥ 20 patients dosed (0.0%) \n\n"
56+
57+
# knit_print.SimulationsSummary works correctly
58+
59+
Code
60+
knit_print(.DefaultSimulationsSummary(), asis = FALSE)
61+
Output
62+
[1] "### Simulation Summary (1 simulations)\n\n**Target toxicity interval:** [20.0%, 35.0%]\n\n**Target dose interval:** [NA, NA]\n\n**Dose most often selected as MTD:** 15 (observed toxicity rate: NaN%)\n\n**Proportion selecting target MTD:** 0.0%\n\n**Number of patients:** 17\n\n**Patients treated above target:** 0\n\n**Fitted toxicity at dose most selected:** 0.249\n\n**Stopping rules triggered:** NA (100.0%), NA (100.0%), ≥ 3 cohorts dosed (100.0%), P(0.2 ≤ prob(DLE | NBD) ≤ 0.35) ≥ 0.5 (100.0%), ≥ 20 patients dosed (0.0%) \n\n"
63+
3664
# knit_print.DualSimulationsSummary works correctly
3765

3866
Code
3967
knit_print(.DefaultDualSimulationsSummary(), asis = FALSE)
4068
Output
41-
[1] "### Simulation Summary (1 simulations)\n\n**Target toxicity interval:** [20.0%, 35.0%]\n\n**Target dose interval:** [NA, NA]\n\n**Dose most often selected as MTD:** 1 (observed toxicity rate: 0.0%)\n\n**Proportion selecting target MTD:** 0.0%\n\n**Number of patients:** 12\n\n**Patients treated above target:** 0\n\n**Fitted toxicity at dose most selected:** 0.069\n\n**Stopping rules triggered:** NA (100.0%), P(0.9 ≤ Biomarker ≤ 1) ≥ 0.5 (relative) (0.0%), ≥ 10 patients dosed (100.0%), Stopped because of missing dose (0.0%) \n\n**Biomarker fit at dose most selected:** 0.237\n\n"
69+
[1] "### Simulation Summary (1 simulations)\n\n**Target toxicity interval:** [20.0%, 35.0%]\n\n**Target dose interval:** [NA, NA]\n\n**Dose most often selected as MTD:** 1 (observed toxicity rate: 0.0%)\n\n**Proportion selecting target MTD:** 0.0%\n\n**Number of patients:** 12\n\n**Patients treated above target:** 0\n\n**Fitted toxicity at dose most selected:** 0.057\n\n**Stopping rules triggered:** NA (100.0%), P(0.9 ≤ Biomarker ≤ 1) ≥ 0.5 (relative) (0.0%), ≥ 10 patients dosed (100.0%), Stopped because of missing dose (0.0%) \n\n**Biomarker fit at dose most selected:** 0.233\n\n"
4270

4371
# knit_print.PseudoSimulationsSummary works correctly
4472

30 Bytes
Binary file not shown.
5 Bytes
Binary file not shown.
10 Bytes
Binary file not shown.
Binary file not shown.
-4 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
-12 Bytes
Binary file not shown.
832 Bytes
Binary file not shown.

tests/testthat/fixtures/make_persistent_objects_for_mocked_constructors.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ saveRDS(
2424
testthat::test_path("fixtures", "default_simulations.Rds")
2525
)
2626

27+
# SimulationsSummary ----
28+
29+
simulations_truth <- function(dose) plogis(-4 + 0.5 * log(dose))
30+
31+
.default_simulations_summary <- summary(
32+
.default_simulations,
33+
truth = simulations_truth
34+
)
35+
36+
saveRDS(
37+
.default_simulations_summary,
38+
testthat::test_path("fixtures", "default_simulations_summary.Rds")
39+
)
40+
2741
# DASimulations ----
2842

2943
design <- .DefaultDADesign()

0 commit comments

Comments
 (0)