Skip to content

Commit 769a4a5

Browse files
committed
Merge branch 'fix/mips' of github.com:wokron/tolangc into fix/mips
2 parents a3a486f + 3f26621 commit 769a4a5

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

scripts/test.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,29 @@ def general_test(test_files: list[pathlib.Path], preprocess_fn, run_fn, compare_
7979

8080

8181
def compare(test_result_file: pathlib.Path, output_file: pathlib.Path):
82+
def convert_to_float(text):
83+
try:
84+
val = float(text)
85+
except ValueError:
86+
val = f"'{text}'"
87+
return val
88+
8289
with open(test_result_file, "r") as f:
83-
test_results = map(float, f.readlines())
90+
test_results = map(convert_to_float, f.readlines())
8491
with open(output_file, "r") as f:
85-
expected_results = map(float, f.readlines())
92+
expected_results = map(convert_to_float, f.readlines())
8693

8794
is_success = True
88-
for no, (test_result, expected_result) in enumerate(
89-
zip(test_results, expected_results)
90-
):
91-
if abs(test_result - expected_result) > 1e-6:
92-
is_success = False
93-
print(f"line {no + 1}: {test_result} != {expected_result}")
95+
try:
96+
for no, (test_result, expected_result) in enumerate(
97+
zip(test_results, expected_results, strict=True)
98+
):
99+
if type(test_result) != float or abs(test_result - expected_result) > 1e-6:
100+
is_success = False
101+
print(f"line {no + 1}: {test_result} != {expected_result}")
102+
except ValueError:
103+
is_success = False
104+
print("result number not matched")
94105

95106
return is_success
96107

testcases/fibo.input

+6-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
5 1 3 5 7 9
1+
5
2+
1
3+
3
4+
5
5+
7
6+
9

testcases/newton.input

+7-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
5 0.00001 2 3 4 5 7
1+
5
2+
0.00001
3+
2
4+
3
5+
4
6+
5
7+
7

testcases/sum.input

+11-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
10 1 2 3 4 5 6 7 8 9 10
1+
10
2+
1
3+
2
4+
3
5+
4
6+
5
7+
6
8+
7
9+
8
10+
9
11+
10

0 commit comments

Comments
 (0)