Skip to content

Commit 2aac57e

Browse files
authored
fix(runner): boolean parsing for c++ runner (#49)
2 parents 2d5b59a + 432cef7 commit 2aac57e

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

app/services/execution/templates.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def run_tests(solution, method_name, test_data, is_sample: bool = False):
5858
5959
try:
6060
result = eval(f"solution.{{format_test_data(method_name, test['input'])}}")
61+
if isinstance(result, str):
62+
result = f"'{{result}}'"
6163
passed = compare_results(result, test['expected'])
6264
results.append(TestResult(
6365
expected=test['expected'],
@@ -535,6 +537,14 @@ def run_tests(solution, method_name, test_data, is_sample: bool = False):
535537
}}
536538
return result;
537539
}}
540+
// Handle booleans
541+
else if constexpr (std::is_same_v<T, bool>) {{
542+
if (val.isBool()) {{
543+
return val.asBool();
544+
}} else {{
545+
throw std::runtime_error("JSON value is not a boolean");
546+
}}
547+
}}
538548
// Handle chars specifically
539549
else if constexpr (std::is_same_v<T, char>) {{
540550
if (val.isString()) {{
@@ -651,10 +661,11 @@ def run_tests(solution, method_name, test_data, is_sample: bool = False):
651661
auto output = solution.{method_name}({args_param});
652662
653663
Json::Value expected;
654-
reader->parse(test["expected"].asString().c_str(),
655-
test["expected"].asString().c_str() +
656-
test["expected"].asString().length(),
657-
&expected, &errors);
664+
const std::string& expected_str = test["expected"].asString();
665+
if (!reader->parse(expected_str.c_str(), expected_str.c_str() + expected_str.length(), &expected, &errors)) {{
666+
std::cerr << "Parse error: " << errors << std::endl;
667+
return false;
668+
}}
658669
659670
Json::Value output_json= valueToJson(output);
660671

app/services/room/state.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,19 @@ def validate_hp_multiplier(cls, v):
8080

8181
@field_validator("prob_easy", "prob_medium", "prob_hard")
8282
def validate_prob(cls, v):
83-
min_prob, max_prob = 0.0, 1.0
83+
min_prob, max_prob = 0.0, 3.0
8484
if not (min_prob <= v <= max_prob):
8585
raise ValueError(f"Probability must be between {min_prob} and {max_prob}")
8686
return v
8787

88-
@field_validator("prob_hard")
89-
def validate_prob_sum(cls, v, info):
90-
values = info.data
91-
if "prob_easy" in values and "prob_medium" in values:
92-
total = values["prob_easy"] + values["prob_medium"] + v
93-
if not (0.99 <= total <= 1.01): # Allow small floating point errors
94-
raise ValueError("Probabilities must sum to 1")
95-
return v
88+
# @field_validator("prob_hard")
89+
# def validate_prob_sum(cls, v, info):
90+
# values = info.data
91+
# if "prob_easy" in values and "prob_medium" in values:
92+
# total = values["prob_easy"] + values["prob_medium"] + v
93+
# if not (0.99 <= total <= 1.01): # Allow small floating point errors
94+
# raise ValueError("Probabilities must sum to 1")
95+
# return v
9696

9797
@field_validator("starting_sp")
9898
def validate_starting_sp(cls, v):

0 commit comments

Comments
 (0)