Skip to content

Commit

Permalink
splitting lines when needed to check floats
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell committed May 27, 2024
1 parent ffab0d0 commit b202289
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/test_convert.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import math
from pathlib import Path

import pytest
Expand Down Expand Up @@ -236,6 +237,14 @@ def test_new_mc_files_match_original(suffix, input_step_file):
You might want to update the MC text file in the regression test folder with the 'tests/update_regression_test_files.py' script.
"""


def is_float(n):
try:
float(n)
except ValueError:
return False
return True

# sets up an output folder for the results
regression_test_file = (
Path("tests/regression_test_files")
Expand All @@ -259,5 +268,19 @@ def test_new_mc_files_match_original(suffix, input_step_file):
and " Original Step file : " not in line_new
and " Original Step file : " not in line_original
):
assert line_new == line_original

# checks the lines match or are close enough (within floating point accuracy)
if line_new == line_original:
assert True
else:
new_segments = line_new.split(' ')
old_segments = line_original.split(' ')
assert len(new_segments) == len(old_segments)
for new_segment, old_segment in zip(new_segments, old_segments):
if new_segment != old_segment:
if is_float(new_segment) and is_float(old_segment):
assert math.isclose(float(new_segment), float(old_segment), rel_tol=1e-09)
else:
assert new_segment == old_segment

assert len(file_new) == len(file_original)

0 comments on commit b202289

Please sign in to comment.