diff --git a/.gitignore b/.gitignore index 5e56e040..81631c69 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /bin +/build diff --git a/tests/execute.py b/tests/execute.py index 5c1e9744..48e33169 100644 --- a/tests/execute.py +++ b/tests/execute.py @@ -5,6 +5,7 @@ import os import re import subprocess +from math import isclose floatPattern = re.compile("""( @@ -45,8 +46,9 @@ def lineEquivalence(ref, trial, n, relativeError=1E-9, absoluteError=1E-10): else: # Look at all the floats on the lines for rF, tF in zip(refFloats, trialFloats): - equal = fuzzyDiff(makeFloat(rF), makeFloat(tF), - relativeError, absoluteError) + equal = isclose( makeFloat(rF), makeFloat(tF), + rel_tol = relativeError, + abs_tol = absoluteError ) if not equal: print("{} and {} are not equal".format( rF[0], tF[0])) @@ -82,6 +84,7 @@ def identicalLines(refLines, trialLines, diffFile, for n, (ref, trial) in enumerate(zip(refLines, trialLines)): equivalent = lineEquivalence(ref, trial, n, relativeError, absoluteError) + if not equivalent: fullEquivalence = False writeDiff(diffFile, ref, trial, n) @@ -112,15 +115,6 @@ def writeDiff(diff_file, refLine, trialLine, lineNumber): diff_file.write("!{}".format(trialLine)) -def fuzzyDiff(a, b, relativeError=1E-9, absoluteError=1E-10): - """ - fuzzDiff will compare to numbers (a and b) to see if they are identical - within the given tolerance. Returns bool. - """ - delta = max(abs(a), abs(b))*relativeError + absoluteError - return (abs(a - b) <= abs(delta)) - - retained_tapes = set(glob.glob('tape*')) reference_tapes = glob.glob('referenceTape*') @@ -152,7 +146,7 @@ def fuzzyDiff(a, b, relativeError=1E-9, absoluteError=1E-10): diff_file.write("--- {} ---\n".format(trial_tape)) identical = identicalLines( - reference_lines, trial_lines, diff_file, 1E-7, 1E-7) + reference_lines, trial_lines, diff_file, 1E-9, 1e-10) should_exit = not identical if should_exit: