Skip to content

Commit

Permalink
Updated comparison function (see comments)
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed Jan 6, 2021
1 parent 6f1e051 commit e78628a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/bin
/build
18 changes: 6 additions & 12 deletions tests/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import re
import subprocess
from math import isclose


floatPattern = re.compile("""(
Expand Down Expand Up @@ -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]))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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*')

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e78628a

Please sign in to comment.