예제 #1
0
 def test_same_set(self):
     item_to_set_mask = {
         self.item_a: np.array([True, True, True, True]),
         self.item_b: np.array([True, True, True, True])
     }
     table = jlinkage.JDistTable(item_to_set_mask)
     pair, dist = table.get_nearest_pair()
     self.assertEqual(frozenset(pair), frozenset({self.item_a,
                                                  self.item_b}))
     self.assertAlmostEqual(dist, 0)
예제 #2
0
 def test_happy(self):
     self.item_to_set_mask = {
         self.item_a: np.array([True, True, True, True, True]),
         self.item_b: np.array([False, False, False, False, False]),
         self.item_c: np.array([True, True, False, False, False]),
         self.item_d: np.array([True, True, True, False, False])
     }
     table = jlinkage.JDistTable(self.item_to_set_mask)
     pair, dist = table.get_nearest_pair()
     self.assertEqual(frozenset(pair), frozenset({self.item_c,
                                                  self.item_d}))
     self.assertAlmostEqual(dist, 1 / float(3))
예제 #3
0
 def test_add_item(self):
     table = jlinkage.JDistTable({})
     self.assertEqual(table.get_nearest_pair(), (None, None))
     table.add_item(self.item_a, np.array([True]))
     self.assertEqual(table.get_nearest_pair(), (None, None))
     table.add_item(self.item_b, np.array([False]))
     pair, dist = table.get_nearest_pair()
     self.assertEqual(frozenset(pair), frozenset({self.item_a,
                                                  self.item_b}))
     self.assertAlmostEqual(dist, 1)
     table.add_item(self.item_c, np.array([True]))
     pair, dist = table.get_nearest_pair()
     self.assertEqual(frozenset(pair), frozenset({self.item_a,
                                                  self.item_c}))
     self.assertAlmostEqual(dist, 0)
     self.assertEqual(table.get_all_items(),
                      frozenset({self.item_a, self.item_b, self.item_c}))
예제 #4
0
 def test_remove_item(self):
     item_to_set_mask = {
         self.item_a: np.array([True]),
         self.item_b: np.array([False]),
         self.item_c: np.array([True])
     }
     table = jlinkage.JDistTable(item_to_set_mask)
     pair, dist = table.get_nearest_pair()
     self.assertEqual(frozenset(pair), frozenset({self.item_a,
                                                  self.item_c}))
     self.assertAlmostEqual(dist, 0)
     table.remove_item(self.item_c)
     pair, dist = table.get_nearest_pair()
     self.assertEqual(frozenset(pair), frozenset({self.item_a,
                                                  self.item_b}))
     self.assertAlmostEqual(dist, 1)
     self.assertEqual(table.get_all_items(),
                      frozenset({self.item_a, self.item_b}))
예제 #5
0
 def test_empty(self):
     table = jlinkage.JDistTable({})
     self.assertEqual(table.get_nearest_pair(), (None, None))