Skip to content

Commit

Permalink
Merge branch 'fix/mips' of github.com:wokron/tolangc into fix/mips
Browse files Browse the repository at this point in the history
  • Loading branch information
XingZiiii committed Aug 31, 2024
2 parents a3a486f + 3f26621 commit 769a4a5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
27 changes: 19 additions & 8 deletions scripts/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion testcases/fibo.input
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
5 1 3 5 7 9
5
1
3
5
7
9
8 changes: 7 additions & 1 deletion testcases/newton.input
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
5 0.00001 2 3 4 5 7
5
0.00001
2
3
4
5
7
12 changes: 11 additions & 1 deletion testcases/sum.input
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
10 1 2 3 4 5 6 7 8 9 10
10
1
2
3
4
5
6
7
8
9
10

0 comments on commit 769a4a5

Please sign in to comment.