From 3f26621c1cc0f63bad5a3ce13470f215936f1946 Mon Sep 17 00:00:00 2001 From: wokron Date: Sat, 31 Aug 2024 17:53:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=84=9A=E6=9C=AC=E5=92=8C?= =?UTF-8?q?=E6=A0=B7=E4=BE=8B=E9=80=82=E9=85=8D=20mars?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/test.py | 27 +++++++++++++++++++-------- testcases/fibo.input | 7 ++++++- testcases/newton.input | 8 +++++++- testcases/sum.input | 12 +++++++++++- 4 files changed, 43 insertions(+), 11 deletions(-) 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