Skip to content

Commit a0c7ffd

Browse files
authored
Write tests for test-combining module (#53)
* Update default proportion and name for combined tests * Write tests for combine_tests.py * Minor improvements to test-combining test module Tweaks for consistency and clarity in test_combine_tests.py - comments, docstrings, variable naming, etc
1 parent c4e08bf commit a0c7ffd

File tree

3 files changed

+386
-18
lines changed

3 files changed

+386
-18
lines changed

crcsim/combine_tests.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import json
2-
from enum import Enum, unique
32
from pathlib import Path
43

54
import fire
65

7-
8-
@unique
9-
class TestCombiningMethod(str, Enum):
10-
SERIAL = "serial"
11-
PARALLEL = "parallel"
6+
from crcsim.enums import TestCombiningMethod
127

138

149
def combine_tests_in_params(
@@ -62,7 +57,10 @@ def combine_tests_in_params(
6257

6358
# Combine cost and other fields
6459
combined["cost"] = t1["cost"] + t2["cost"]
65-
combined["proportion"] = 1.0 # Set to 1.0 to ensure it's selected
60+
# By default, keep the assigned test proportions from the base params
61+
# and do not assign the combined test to anyone. Edits to test proportions
62+
# should be handled downstream in experiment logic.
63+
combined["proportion"] = 0.0
6664
combined["routine_start"] = min(t1["routine_start"], t2["routine_start"])
6765
combined["routine_end"] = max(t1["routine_end"], t2["routine_end"])
6866
combined["routine_freq"] = min(t1["routine_freq"], t2["routine_freq"])
@@ -87,23 +85,14 @@ def combine_tests_in_params(
8785
)
8886
]
8987

90-
# Name for the new test
91-
new_test_name = f"{test1}_{test2}_{how}"
88+
# Add the combined test to the parameters.
89+
new_test_name = f"{test1}_{test2}_{how.value}"
9290

93-
# Add the combined test to routine_tests if not already present
9491
if new_test_name not in params["routine_tests"]:
9592
params["routine_tests"].append(new_test_name)
9693

97-
# Set proportion of all other tests to 0.0
98-
for test_name in params["tests"]:
99-
params["tests"][test_name]["proportion"] = 0.0
100-
101-
# Now add the combined test to the tests dictionary
10294
params["tests"][new_test_name] = combined
10395

104-
# By default, we'll assign everyone the combined test
105-
params["tests"][new_test_name]["proportion"] = 1.0
106-
10796
return params
10897

10998

crcsim/enums.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,9 @@ class Sex(Enum):
157157
FEMALE = "female"
158158
MALE = "male"
159159
OTHER = "other"
160+
161+
162+
@unique
163+
class TestCombiningMethod(str, Enum):
164+
SERIAL = "serial"
165+
PARALLEL = "parallel"

0 commit comments

Comments
 (0)