Skip to content

Commit eb32c79

Browse files
authored
tests: compare difference to threshold (#59)
* tests: compare difference to threshold rather * remove spurious comment * work around pre-3.10 python zip limitations
1 parent 89921ea commit eb32c79

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

tests/pathops_test.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,25 @@ def test_last_implicit_lineTo(self):
120120
('closePath', ())]
121121

122122
@staticmethod
123-
def round(path, ndigits):
124-
for verb, pts in path:
125-
yield verb, tuple(
126-
(round(pt[0], ndigits), round(pt[1], ndigits))
127-
for pt in pts
128-
)
123+
def path_difference(path1, path2):
124+
assert len(path1) == len(path2)
125+
for (v1, pts1), (v2, pts2) in zip(path1, path2):
126+
assert len(pts1) == len(pts2)
127+
yield v1, v2, tuple(
128+
(pt1[0] - pt2[0], pt1[1] - pt2[1])
129+
for (pt1, pt2) in zip(pts1, pts2)
130+
)
129131

130132
@classmethod
131133
def assert_paths_almost_equal(cls, actual, expected, ndigits):
134+
from math import fabs, pow
132135
assert actual.fillType == expected.fillType
133-
actual_coords = tuple(cls.round(actual, ndigits))
134-
expected_coords = tuple(cls.round(expected, ndigits))
135-
print(actual_coords)
136-
print(expected_coords)
137-
assert actual_coords == expected_coords
136+
pd = cls.path_difference(actual, expected)
137+
print(pd)
138+
for (av, ev, deltas) in pd:
139+
assert av == ev
140+
for delta in deltas:
141+
assert max(fabs(delta[0]), fabs(delta[1])) <= pow(10, -ndigits)
138142

139143
def test_transform(self):
140144
path = Path()

0 commit comments

Comments
 (0)