class BinaryTests(TestCase): def setUp(self): self.coords1 = set((sin(0.1*t), sin(0.2*t), sin(0.3*t)) for t in xrange(50)) self.o1 = Octree(((-1.0, 1.0), (-1.0, 1.0), (-1.0, 1.0))) self.o1.extend((p, None) for p in self.coords1) self.coords2 = set((sin(0.1*t), sin(0.2*t), sin(0.3*t)) for t in xrange(150, 200)) self.o2 = Octree(((-1.0, 1.0), (-1.0, 1.0), (-1.0, 1.0))) self.o2.extend((p, None) for p in self.coords2) def test_proximity(self): l1 = [] for c1 in self.coords1: (d, c2, _) = self.o2.nearest_to_point(c1) l1.append((d, c1, c2, None, None)) l1.sort() l2 = list(self.o1.by_proximity(self.o2)) self.assertEqual(l1, l2) l1b = list(t for t in l1 if t[0] < 0.1) l2b = list(self.o1.by_proximity(self.o2, 0.1)) self.assertEqual(l1b, l2b) def test_isolation(self): l1 = [] for c1 in self.coords1: (d, c2, _) = self.o2.nearest_to_point(c1) l1.append((d, c1, c2, None, None)) l1.sort(reverse=True) l2 = list(self.o1.by_isolation(self.o2)) self.assertEqual(l1, l2) l1b = list(t for t in l1 if t[0] > 0.3) l2b = list(self.o1.by_isolation(self.o2, 0.3)) self.assertEqual(l1b, l2b) def test_pairs_by_distance(self): l1 = [] for c1 in self.coords1: for c2 in self.coords2: d = euclidean_point_point(c1, c2) if d < 0.1: l1.append((d, c1, c2, None, None)) l1.sort() l2 = list(self.o1.pairs_by_distance(self.o2, 0.1)) self.assertEqual(l1, l2) def test_pairs_nearby(self): s1 = set() for c1 in self.coords1: for c2 in self.coords2: d = euclidean_point_point(c1, c2) if d < 0.1: s1.add((c1, c2, None, None)) s2 = set(self.o1.pairs_nearby(self.o2, 0.1)) self.assertEqual(s1, s2)
class BinaryTests(TestCase): def setUp(self): self.coords1 = set((sin(0.1*t), sin(0.2*t), sin(0.3*t)) for t in range(50)) self.o1 = Octree(((-1.0, 1.0), (-1.0, 1.0), (-1.0, 1.0))) self.o1.extend((p, None) for p in self.coords1) self.coords2 = set((sin(0.1*t), sin(0.2*t), sin(0.3*t)) for t in range(150, 200)) self.o2 = Octree(((-1.0, 1.0), (-1.0, 1.0), (-1.0, 1.0))) self.o2.extend((p, None) for p in self.coords2) def test_proximity(self): l1 = [] for c1 in self.coords1: (d, c2, _) = self.o2.nearest_to_point(c1) l1.append((d, c1, c2, None, None)) l1.sort() l2 = list(self.o1.by_proximity(self.o2)) self.assertEqual(l1, l2) l1b = list(t for t in l1 if t[0] < 0.1) l2b = list(self.o1.by_proximity(self.o2, 0.1)) self.assertEqual(l1b, l2b) def test_isolation(self): l1 = [] for c1 in self.coords1: (d, c2, _) = self.o2.nearest_to_point(c1) l1.append((d, c1, c2, None, None)) l1.sort(reverse=True) l2 = list(self.o1.by_isolation(self.o2)) self.assertEqual(l1, l2) l1b = list(t for t in l1 if t[0] > 0.3) l2b = list(self.o1.by_isolation(self.o2, 0.3)) self.assertEqual(l1b, l2b) def test_pairs_by_distance(self): l1 = [] for c1 in self.coords1: for c2 in self.coords2: d = euclidean_point_point(c1, c2) if d < 0.1: l1.append((d, c1, c2, None, None)) l1.sort() l2 = list(self.o1.pairs_by_distance(self.o2, 0.1)) self.assertEqual(l1, l2) def test_pairs_nearby(self): s1 = set() for c1 in self.coords1: for c2 in self.coords2: d = euclidean_point_point(c1, c2) if d < 0.1: s1.add((c1, c2, None, None)) s2 = set(self.o1.pairs_nearby(self.o2, 0.1)) self.assertEqual(s1, s2)