Ejemplo n.º 1
0
 def test_list(self):
     # same length
     self.assertEqual(distance_metric(self.list_a, self.list_b), 4.4)
     # different length
     self.assertEqual(distance_metric(self.list_b, self.list_c), 1.0)
     # sanity check, same objects
     self.assertEqual(distance_metric(self.list_b, self.list_b), 0.0)
Ejemplo n.º 2
0
 def test_array(self):
     # same length
     self.assertEqual(
         distance_metric(np.array(self.list_a), np.array(self.list_b)), 4.4)
     # different length
     self.assertEqual(
         distance_metric(
             np.array(self.list_b).reshape(1, 3), np.array(self.list_c)),
         1.0,
     )
     # sanity check, same objects
     self.assertEqual(
         distance_metric(np.array(self.list_b), np.array(self.list_b)), 0.0)
Ejemplo n.º 3
0
    def test_hark_object_distance(self):
        self.obj_a.distance_criteria = ["var_1", "var_2", "var_3"]
        self.obj_b.distance_criteria = ["var_1", "var_2", "var_3"]
        self.obj_c.distance_criteria = ["var_5"]
        # if attributes don't exist or don't match
        self.assertEqual(distance_metric(self.obj_a, self.obj_b), 1000.0)
        self.assertEqual(distance_metric(self.obj_a, self.obj_c), 1000.0)
        # add single numbers to attributes
        self.obj_a.var_1, self.obj_a.var_2, self.obj_a.var_3 = 0.1, 1, 2.1
        self.obj_b.var_1, self.obj_b.var_2, self.obj_b.var_3 = 1.8, -1, 0.1
        self.assertEqual(distance_metric(self.obj_a, self.obj_b), 2.0)

        # sanity check - same objects
        self.assertEqual(distance_metric(self.obj_a, self.obj_a), 0.0)