Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion source/fortran/output.f90
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,11 @@ subroutine ovarre(file,descr,varnam,value,output_flag)
call underscore(dum20)
write(mfile,10) dum72, dum20, value, flag

10 format(1x,a,t75,a,t110,1pe11.4," ",a,t10)
! MFILE.DAT format
! Machine epsilon for double ~2.22e-16, hence require 17 sig figs in significand
! for full precision of a double float
10 format(1x,a,t75,a,t110,ES23.16e2," ",a,t10)
! OUT.DAT format
20 format(1x,a,t75,a,t100,1pe10.3, t112, a)

end subroutine ovarre
Expand Down
54 changes: 30 additions & 24 deletions tests/regression/test_process_input_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,8 @@ def mfile_value_changes(
if re.match(exclusions, key) is not None:
continue

# no need to carry on if the variables are exactly the same
if (ref_value := ref.data[key].get_scan(-1)) == (
new_value := new.data[key].get_scan(-1)
):
continue
ref_value = ref.data[key].get_scan(-1)
new_value = new.data[key].get_scan(-1)

try:
ref_value = float(ref_value)
Expand All @@ -180,28 +177,37 @@ def mfile_value_changes(
# only compare float-able values
continue

# NOTE: the percentage change for a value that was
# originally 0 is 100% NOT 0% because this allows it
# to get picked up by various checks below
percentage_change = (
100.0 * (new_value - ref_value) / abs(ref_value)
if ref_value != 0
else 100.0
)
# Define relative tolerance
if tolerance == 0:
# Use pytest's default relative tolerance (1e-6)
# 0 tolerance causes floating-point discrepancies
# between local and CI runs
rel_tolerance = None
else:
# tolerance is a percentage, rel arg takes a fraction
rel_tolerance = tolerance / 100

# ignore the difference between the variables if its below
# tolerance
if percentage_change <= tolerance:
continue
try:
# Use pytest.approx for relative and absolute comparisons:
# handles values close to 0
assert new_value == pytest.approx(ref_value, rel=rel_tolerance)
except AssertionError:
# NOTE: the percentage change for a value that was originally 0
# is 100% NOT 0% because this indicates the change better
percentage_change = (
100.0 * (new_value - ref_value) / abs(ref_value)
if ref_value != 0
else 100.0
)

diffs.append(
MFileVariableDifference(
key,
ref_value,
new_value,
percentage_change,
diffs.append(
MFileVariableDifference(
key,
ref_value,
new_value,
percentage_change,
)
)
)

return diffs

Expand Down