Beispiel #1
0
 def test_empty_entitylist_reverts_to_weight_zero(self):
     """Check that an empty EntityList calculates its new weight as zero."""
     test_object = EntityList()
     test_object.calculate_new_weight()
     self.assertEqual(0.0, test_object.weight,
                      "Weight should revert to zero")
     self.assertEqual(-1.0, test_object.delta, "Delta should be -1.0")
Beispiel #2
0
 def test_entitylist_reports_zero_weight_for_single_entity_entitylist(self):
     """
     Given a score for an Entity (the only entity in the list), return the
     weight of the list as if that score were not included i.e. zero.
     """
     test_object = EntityList()
     ent1 = Entity("1")
     ent1.score = 96.4
     test_object.append(ent1)
     test_object.calculate_new_weight()
     self.assertAlmostEqual(
         0, test_object.get_corrected_list_weight(ent1.score), 1,
         "Corrected weight should be 0")
Beispiel #3
0
 def test_entitylist_fails_adjusted_weight_on_empty_entitylist(self):
     """
     Check that the get_corrected_list_weight() method fails with an
     exception on an empty list.
     """
     test_object = EntityList()
     ent1 = Entity("1")
     ent1.score = 96.4
     # test_object.append(ent1)
     test_object.calculate_new_weight()
     try:
         test_object.get_corrected_list_weight(ent1.score)
         raise Exception("Should have thrown an Exception")
     except ValueError:
         pass
     except Exception:
         raise Exception("Should have thrown a ValueError")
Beispiel #4
0
 def test_entitylist_reports_adjusted_weight_for_given_score(self):
     """
     Given a score for an Entity (assumed to be in the list), return the
     weight of the list as if that score were not included.
     """
     test_object = EntityList()
     ent1 = Entity("1")
     ent1.score = 2.4
     test_object.append(ent1)
     ent2 = Entity("2")
     ent2.score = 14.2
     test_object.append(ent2)
     test_object.calculate_new_weight()
     self.assertAlmostEqual(
         sqrt(2.4), test_object.get_corrected_list_weight(ent2.score), 1,
         "Corrected weight should be sqrt(2.4)")
     self.assertAlmostEqual(
         sqrt(14.2), test_object.get_corrected_list_weight(ent1.score), 1,
         "Corrected weight should be sqrt(14.2)")
Beispiel #5
0
 def test_entitylist_reset(self):
     """
     Check that an EntityList can be reset having first calculated a weight
     """
     test_object = EntityList()
     ent1 = MagicMock(Entity)
     ent1.score = 2.4
     test_object.append(ent1)
     ent2 = MagicMock(Entity)
     ent2.score = 14.2
     test_object.append(ent2)
     test_object.calculate_new_weight()
     self.assertAlmostEqual(2.88097206, test_object.weight, 8,
                            "Weight should be calculated as 2.88097206")
     self.assertAlmostEqual(1.88097206, test_object.delta, 8,
                            "Delta should be 1.88097206")
     test_object.reset()
     self.assertEqual(1, test_object.weight, "Weight should be reset to 1")
     self.assertIsNone(test_object.delta, "Delta should be reset to None")
     # self.assertEqual(0.0, test_object.__total_entity_weight,
     #                  "Total Entity Weight should be zero")
     ent1.reset.assert_called_once()
     ent2.reset.assert_called_once()
Beispiel #6
0
 def test_entitylist_returns_absolute_delta_value(self):
     """
     Check that an EntityList calculates its new weight from the Entities
     it contains and stores the real delta i.e. delta can be negative
     """
     test_object = EntityList()
     ent1 = Entity("1")
     ent1.score = 0.4
     test_object.append(ent1)
     ent2 = Entity("2")
     ent2.score = 0.3
     test_object.append(ent2)
     returned_delta = test_object.calculate_new_weight()
     self.assertAlmostEqual(0.59160797831, test_object.weight, 8,
                            "Weight should be calculated as 0.59160797831")
     self.assertAlmostEqual(-0.40839202169, test_object.delta, 8,
                            "Delta should be -0.40839202169")
     self.assertAlmostEqual(-0.40839202169, returned_delta, 8,
                            "Returned Delta should be -0.40839202169")
Beispiel #7
0
 def test_entitylist_calculates_weight_from_entities(self):
     """
     Check that an EntityList calculates its new weight from the Entities
     it contains
     """
     test_object = EntityList()
     ent1 = Entity("1")
     ent1.score = 2.4
     test_object.append(ent1)
     ent2 = Entity("2")
     ent2.score = 14.2
     test_object.append(ent2)
     returned_delta = test_object.calculate_new_weight()
     self.assertAlmostEqual(2.88097206, test_object.weight, 8,
                            "Weight should be calculated as 2.88097206")
     self.assertAlmostEqual(1.88097206, test_object.delta, 8,
                            "Delta should be 1.88097206")
     self.assertAlmostEqual(1.88097206, returned_delta, 8,
                            "Returned Delta should be 1.88097206")