diff --git a/scripts/test.py b/scripts/test.py index f47efda..3a92d97 100644 --- a/scripts/test.py +++ b/scripts/test.py @@ -79,18 +79,29 @@ def general_test(test_files: list[pathlib.Path], preprocess_fn, run_fn, compare_ def compare(test_result_file: pathlib.Path, output_file: pathlib.Path): + def convert_to_float(text): + try: + val = float(text) + except ValueError: + val = f"'{text}'" + return val + with open(test_result_file, "r") as f: - test_results = map(float, f.readlines()) + test_results = map(convert_to_float, f.readlines()) with open(output_file, "r") as f: - expected_results = map(float, f.readlines()) + expected_results = map(convert_to_float, f.readlines()) is_success = True - for no, (test_result, expected_result) in enumerate( - zip(test_results, expected_results) - ): - if abs(test_result - expected_result) > 1e-6: - is_success = False - print(f"line {no + 1}: {test_result} != {expected_result}") + try: + for no, (test_result, expected_result) in enumerate( + zip(test_results, expected_results, strict=True) + ): + if type(test_result) != float or abs(test_result - expected_result) > 1e-6: + is_success = False + print(f"line {no + 1}: {test_result} != {expected_result}") + except ValueError: + is_success = False + print("result number not matched") return is_success diff --git a/testcases/fibo.input b/testcases/fibo.input index 119f08d..4896dee 100644 --- a/testcases/fibo.input +++ b/testcases/fibo.input @@ -1 +1,6 @@ -5 1 3 5 7 9 \ No newline at end of file +5 +1 +3 +5 +7 +9 \ No newline at end of file diff --git a/testcases/newton.input b/testcases/newton.input index c2a8a22..c387dc8 100644 --- a/testcases/newton.input +++ b/testcases/newton.input @@ -1 +1,7 @@ -5 0.00001 2 3 4 5 7 \ No newline at end of file +5 +0.00001 +2 +3 +4 +5 +7 diff --git a/testcases/sum.input b/testcases/sum.input index e212eb8..c59d0b3 100644 --- a/testcases/sum.input +++ b/testcases/sum.input @@ -1 +1,11 @@ -10 1 2 3 4 5 6 7 8 9 10 \ No newline at end of file +10 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 \ No newline at end of file