예제 #1
0
 def test_sub(self):
     ps = PointSet()
     fp = FastPair().build(ps)
     start = fp._find_neighbor(ps[-1])
     fp -= ps[-1]
     end = fp._find_neighbor(start["neigh"])
     assert end["neigh"] != ps[-1]
     # This is risky, because it might legitimately be the same...?
     assert start["dist"] != end["dist"]
     assert len(fp) == len(ps)-1
     with pytest.raises(ValueError):
         fp -= rand_tuple(len(ps[0]))
예제 #2
0
 def test_sub(self, PointSet):
     ps = PointSet
     fp = FastPair().build(ps)
     start = fp._find_neighbor(ps[-1])
     fp -= ps[-1]
     end = fp._find_neighbor(start["neigh"])
     assert end["neigh"] != ps[-1]
     # This is risky, because it might legitimately be the same...?
     assert start["dist"] != end["dist"]
     assert len(fp) == len(ps) - 1
     with pytest.raises(ValueError):
         fp -= rand_tuple(len(ps[0]))
예제 #3
0
 def test_find_neighbor_and_sdist(self, PointSet):
     ps = PointSet
     fp = FastPair().build(ps)
     rando = rand_tuple(len(ps[0]))
     neigh = fp._find_neighbor(rando)  # Abusing find_neighbor!
     dist = fp.dist(rando, neigh["neigh"])
     assert abs(dist - neigh["dist"]) < 1e-8
     assert len(fp) == len(ps)  # Make sure we didn't add a point...
     l = [(fp.dist(a, b), b) for a, b in zip(cycle([rando]), ps)]
     res = min(l, key=itemgetter(0))
     assert abs(res[0] - neigh["dist"]) < 1e-8
     assert res[1] == neigh["neigh"]
     res = min(fp.sdist(rando), key=itemgetter(0))
     assert abs(neigh["dist"] - res[0]) < 1e-8
     assert neigh["neigh"] == res[1]
예제 #4
0
 def test_find_neighbor_and_sdist(self):
     ps = PointSet()
     fp = FastPair().build(ps)
     rando = rand_tuple(len(ps[0]))
     neigh = fp._find_neighbor(rando)  # Abusing find_neighbor!
     dist = fp.dist(rando, neigh["neigh"])
     assert  abs(dist - neigh["dist"]) < 1e-8
     assert len(fp) == len(ps)  # Make sure we didn't add a point...
     l = [(fp.dist(a, b), b) for a, b in zip(cycle([rando]), ps)]
     res = min(l, key=itemgetter(0))
     assert abs(res[0] - neigh["dist"]) < 1e-8
     assert res[1] == neigh["neigh"]
     res = min(fp.sdist(rando), key=itemgetter(0))
     assert abs(neigh["dist"] - res[0]) < 1e-8
     assert neigh["neigh"] == res[1]