Esempio n. 1
0
 def test_call_and_closest_pair(self, PointSet):
     ps = PointSet
     fp = FastPair().build(ps)
     cp = fp.closest_pair()
     bf = fp.closest_pair_brute_force()
     assert fp() == cp
     assert abs(cp[0] - bf[0]) < 1e-8
     assert cp[1] == bf[1]
Esempio n. 2
0
 def test_call_and_closest_pair(self):
     ps = PointSet()
     fp = FastPair().build(ps)
     cp = fp.closest_pair()
     bf = fp.closest_pair_brute_force()
     assert fp() == cp
     assert abs(cp[0] - bf[0]) < 1e-8
     assert cp[1] == bf[1]
Esempio n. 3
0
 def test_all_closest_pairs(self):
     ps = PointSet()
     fp = FastPair().build(ps)
     cp = fp.closest_pair()
     bf = fp.closest_pair_brute_force()  # Ordering should be the same
     # dc = fp.closest_pair_divide_conquer()  # Maybe different ordering
     assert abs(cp[0] - bf[0]) < 1e-8
     assert cp[1] == bf[1]  # Tuple comparison
     test = min([(fp.dist(a, b), (a, b)) for a, b in combinations(ps, r=2)], key=itemgetter(0))
     assert abs(cp[0] - test[0]) < 1e-8
     assert sorted(cp[1]) == sorted(test[1])  # Tuple comparison
Esempio n. 4
0
 def test_call_and_closest_pair_min_points(self, image_array):
     ps = image_array
     fp = FastPair(dist=image_distance)
     for p in ps:
         fp += p
     assert fp.initialized is False
     assert len(fp) == 6
     cp = fp.closest_pair()
     bf = fp.closest_pair_brute_force()
     assert fp() == cp
     assert abs(cp[0] - bf[0]) < 1e-8
     assert cp[1] == bf[1]
Esempio n. 5
0
 def test_all_closest_pairs(self, PointSet):
     ps = PointSet
     fp = FastPair().build(ps)
     cp = fp.closest_pair()
     bf = fp.closest_pair_brute_force()  # Ordering should be the same
     # dc = fp.closest_pair_divide_conquer()  # Maybe different ordering
     assert abs(cp[0] - bf[0]) < 1e-8
     assert cp[1] == bf[1]  # Tuple comparison
     test = min(
         [(fp.dist(a, b), (a, b)) for a, b in combinations(ps, r=2)],
         key=itemgetter(0),
     )
     assert abs(cp[0] - test[0]) < 1e-8
     assert sorted(cp[1]) == sorted(test[1])  # Tuple comparison