@@ -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
0 commit comments