Skip to content

Commit

Permalink
tests: compare difference to threshold (#59)
Browse files Browse the repository at this point in the history
* tests: compare difference to threshold rather

* remove spurious comment

* work around pre-3.10 python zip limitations
  • Loading branch information
mklca authored Jul 21, 2022
1 parent 89921ea commit eb32c79
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions tests/pathops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,25 @@ def test_last_implicit_lineTo(self):
('closePath', ())]

@staticmethod
def round(path, ndigits):
for verb, pts in path:
yield verb, tuple(
(round(pt[0], ndigits), round(pt[1], ndigits))
for pt in pts
)
def path_difference(path1, path2):
assert len(path1) == len(path2)
for (v1, pts1), (v2, pts2) in zip(path1, path2):
assert len(pts1) == len(pts2)
yield v1, v2, tuple(
(pt1[0] - pt2[0], pt1[1] - pt2[1])
for (pt1, pt2) in zip(pts1, pts2)
)

@classmethod
def assert_paths_almost_equal(cls, actual, expected, ndigits):
from math import fabs, pow
assert actual.fillType == expected.fillType
actual_coords = tuple(cls.round(actual, ndigits))
expected_coords = tuple(cls.round(expected, ndigits))
print(actual_coords)
print(expected_coords)
assert actual_coords == expected_coords
pd = cls.path_difference(actual, expected)
print(pd)
for (av, ev, deltas) in pd:
assert av == ev
for delta in deltas:
assert max(fabs(delta[0]), fabs(delta[1])) <= pow(10, -ndigits)

def test_transform(self):
path = Path()
Expand Down

0 comments on commit eb32c79

Please sign in to comment.