Skip to content

Commit

Permalink
some approximation for float precision [1]
Browse files Browse the repository at this point in the history
  • Loading branch information
jGaboardi committed Jun 23, 2024
1 parent 3ddd25d commit 1ce2331
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions fastpair/tests/test_fastpair.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ def setup_method(self):
def test_get_set(self):
known_get = {"dist": 0.6983581029815579, "neigh": (0.5118, 0.9505)}
observed_get = self.fp[(0.2616, 0.2985)]
assert known_get == observed_get
assert known_get == pytest.approx(observed_get)

known_set = {"dist": 0.6983581029815579, "neigh": (19, 99)}
self.fp[(0.2616, 0.2985)].neigh = (19, 99)
observed_set = self.fp[(0.2616, 0.2985)]
assert known_set == observed_set
assert known_set == pytest.approx(observed_set)

def test_get_raise_1(self):
with pytest.raises(KeyError, match=re.escape("('a', 'b') not found")):
Expand Down Expand Up @@ -239,7 +239,10 @@ def test_cp_eq_bf_pair(self):
assert self.cp[1] == self.bf[1]

def test_cp_eq_bf_exact(self):
known = (0.11669811480910905, ((0.8702, 0.2868), (0.956, 0.2077)))
known = (
pytest.approx(0.11669811480910905),
((0.8702, 0.2868), (0.956, 0.2077)),
)
observed_cp = self.cp
observed_bf = self.bf

Expand All @@ -254,7 +257,7 @@ def setup_method(self):
self.cp = self.fp.closest_pair()
self.bf = self.fp.closest_pair_brute_force()
# self.dc = self.fp.closest_pair_divide_conquer() # Maybe different ordering
self.all_closest = [
_all_closest = [
(0.6997697978621256, ((0.637, 0.2698, 0.041), (0.5118, 0.9505, 0.1442))),
(0.859992494153292, ((0.637, 0.2698, 0.041), (0.2616, 0.2985, 0.8142))),
(0.9397803200748566, ((0.637, 0.2698, 0.041), (0.0856, 0.2368, 0.8013))),
Expand All @@ -277,6 +280,7 @@ def setup_method(self):
(0.7488246924347515, ((0.9431, 0.5113, 0.9762), (0.5382, 0.3433, 0.3691))),
(0.5553465944795196, ((0.805, 0.8079, 0.5153), (0.5382, 0.3433, 0.3691))),
]
self.all_closest = [(pytest.approx(i), j) for i, j in _all_closest]

def test_all_closest(self):
known = self.all_closest
Expand Down Expand Up @@ -353,7 +357,10 @@ class TestFastPairCluster:
def test_basic(self):
ps = [(1, 1), (2, 2), (3, 3)]
known_coords = [1.5, 2.25]
known_dists = [1.4142135623730951, 2.121320343559643]
known_dists = [
pytest.approx(1.4142135623730951),
pytest.approx(2.121320343559643),
]

fp = FastPair().build(ps)
for i in range(len(fp) - 1):
Expand Down

0 comments on commit 1ce2331

Please sign in to comment.