added a verify command to our makefile. so for future variants we can just use...

This commit is contained in:
Linus Baumberger
2026-05-19 07:45:02 +02:00
parent ae3bb8a034
commit de2d2c7be8
3 changed files with 51 additions and 6 deletions
+35
View File
@@ -0,0 +1,35 @@
import sys
import csv
import math
if len(sys.argv) < 3:
sys.exit("Use it like: python verify.py reference.csv generated.csv [tol]")
# We can use this later in case that we wanna compare something with a tolerance
tol = float(sys.argv[3]) if len(sys.argv) > 3 else 0.0
with open(sys.argv[1], newline="") as f:
ref = list(csv.reader(f))
with open(sys.argv[2], newline="") as f:
gen = list(csv.reader(f))
if len(ref) != len(gen):
sys.exit(f"row count differs: ref={len(ref)} got={len(gen)}")
header = ref[0]
for i in range(len(ref)):
if len(ref[i]) != len(gen[i]):
sys.exit(f"line {i+1}: column count differs")
for j in range(len(ref[i])):
a = ref[i][j].strip()
b = gen[i][j].strip()
if a == b:
continue
# in case that we wanna use tolerance
if tol > 0:
try:
if math.isclose(float(a), float(b), abs_tol=tol):
continue
except ValueError:
pass
col = header[j] if j < len(header) else f"col{j}"
sys.exit(f"mismatch at line {i+1}, col {j} ('{col}'): ref='{a}' got='{b}'")