Пример #1
0
    def test_weight_for_entity_reports_zero_for_noncontained_entity(self):
        """Check that an EntityList returns zero when asked for the
        weight for a Entity that is not in its list of Entities"""
        test_object = EntityList()
        ent1 = Entity("1")
        test_object.append(ent1)

        ent2 = Entity("2")
        test_object.append(ent2)

        uncontained = Entity("3")
        self.assertEqual(0.0, test_object.get_weight_for_entity(uncontained),
                         "Should return zero for a entity not in the list")
Пример #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")
Пример #3
0
    def test_unranked_list_names_self_correctly(self):
        """Check that an unranked list correctly reports itself using the
        string naming convention"""
        from random import randint

        test_object = EntityList()
        test_object.is_ranked = False

        list_count = randint(1, 20)
        for x in range(0, list_count):
            entity = Entity(str(x))
            test_object.append(entity)

        self.assertEqual(
            str(list_count) + "u", test_object.code_string(),
            "Got an unexpected code_string")
Пример #4
0
    def test_weight_for_entity_returns_list_weight_for_contained_entity(self):
        """Check that an EntityList returns the list weight when asked for the
        weight for a Entity that is in its list of Entities"""

        test_object = EntityList()
        test_object.weight = 1234.567

        ent1 = Entity("1")
        test_object.append(ent1)

        ent2 = Entity("2")
        test_object.append(ent2)

        returned_value = test_object.get_weight_for_entity(ent2)
        self.assertEqual(
            1234.567, returned_value, "Should return the list weight for a"
            "contained Entity")
Пример #5
0
 def test_entity_can_be_appended_to_entitylist(self):
     """
     Check that appending an Entity to the List extends the list and stores
     reference to the list in the Entity.
     """
     test_entity = Entity("D")
     test_object = EntityList()
     test_object.append(test_entity)
     self.assertTrue(test_object, "List should now be true")
     self.assertEqual(1, len(test_object),
                      "List should contain one element")
     self.assertTrue(test_entity in test_object,
                     "Entity should be in the EntityList")
     self.assertTrue(test_entity.lists, "Entity's lists should now be True")
     self.assertEqual(1, len(test_entity.lists),
                      "Entity's List of Lists should contain one element")
     self.assertTrue(test_object in test_entity.lists,
                     "EntityList should be in the Entity's List of Lists")
Пример #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")
Пример #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")
Пример #8
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)")
Пример #9
0
    def test_reset(self):
        """Check that we can reset an Entity score and other parameters in
        readiness for another analysis run"""
        test_object = Entity("BB")
        list1 = EntityList()
        list1.category_name = "type1"
        list1.weight = 1.7
        list1.append(test_object)

        list2 = EntityList()
        list2.category_name = "type2"
        list2.weight = 6.112
        list2.append(test_object)

        list3 = EntityList()
        list3.category_name = "type2"
        list3.weight = 9.3
        list3.append(test_object)

        test_object.calculate_new_score()
        self.assertAlmostEqual(
            11.0, test_object.score, 1,
            "Score should now be the sum of the highest list scores in"
            "each category {}".format(test_object.score))

        test_object.reset()
        self.assertAlmostEqual(1, test_object.score, 10,
                               "Score should now be reset to 1")
        self.assertEqual(0.0, test_object.score_from_list(list1),
                         "Expected 4.3 from list1")
        self.assertEqual(0.0, test_object.score_from_list(list2),
                         "Expected 0.0 from list2")
        self.assertEqual(0.0, test_object.score_from_list(list3),
                         "Expected 9.3 from list3")
Пример #10
0
    def test_entity_reports_raw_scores(self):
        """Check that an Entity reports the scores from each list regardless
        of winning category"""
        test_object = Entity("DD")
        list1 = EntityList()
        list1.category_name = "type1"
        list1.weight = 4.3
        list1.append(test_object)

        list2 = EntityList()
        list2.category_name = "type2"
        list2.weight = 6.112
        list2.append(test_object)

        list3 = EntityList()
        list3.category_name = "type2"
        list3.weight = 9.3
        list3.append(test_object)

        unrelated_list = EntityList()
        unrelated_list.category_name = "type1"
        unrelated_list.weight = 99.42

        test_object.calculate_new_score()

        self.assertEqual(4.3, test_object.raw_score_from_list(list1),
                         "Expected 4.3 from list1")
        self.assertEqual(6.112, test_object.raw_score_from_list(list2),
                         "Expected 6.112 from list2")
        self.assertEqual(9.3, test_object.raw_score_from_list(list3),
                         "Expected 9.3 from list3")
        self.assertEqual(0.0, test_object.raw_score_from_list(unrelated_list),
                         "Expected 0.0 from unrelated_list")
Пример #11
0
    def test_entity_knows_contributing_list_components(self):
        """Check that an Entity knows which lists contributed what weights to
        its overall score"""
        test_object = Entity("DD")
        list1 = EntityList()
        list1.category_name = "type1"
        list1.weight = 4.3
        list1.append(test_object)

        list2 = EntityList()
        list2.category_name = "type2"
        list2.weight = 6.112
        list2.append(test_object)

        list3 = EntityList()
        list3.category_name = "type2"
        list3.weight = 9.3
        list3.append(test_object)

        unrelated_list = EntityList()
        unrelated_list.category_name = "type1"
        unrelated_list.weight = 99.42

        test_object.calculate_new_score()

        self.assertEqual(4.3, test_object.score_from_list(list1),
                         "Expected 4.3 from list1")
        self.assertEqual(0.0, test_object.score_from_list(list2),
                         "Expected 0.0 from list2")
        self.assertEqual(9.3, test_object.score_from_list(list3),
                         "Expected 9.3 from list3")
        self.assertEqual(0.0, test_object.score_from_list(unrelated_list),
                         "Expected 0.0 from unrelated_list")
Пример #12
0
    def test_calculate_new_score_accounts_for_categories_opposite_order(self):
        """
        Test that an Entity calculates its new score as the sum of the
        scores of the lists that mention it, regardless of the order of the
        EntityList objects
        """
        test_object = Entity("BB")
        list1 = EntityList()
        list1.category_name = "type1"
        list1.weight = 1.7
        list1.append(test_object)

        list2 = EntityList()
        list2.category_name = "type2"
        list2.weight = 6.112
        list2.append(test_object)

        list3 = EntityList()
        list3.category_name = "type2"
        list3.weight = 9.3
        list3.append(test_object)

        test_object.calculate_new_score()
        self.assertAlmostEqual(
            11.0, test_object.score, 1,
            "Score should now be the sum of the highest list scores in"
            "each category {}".format(test_object.score))
Пример #13
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()
Пример #14
0
    def test_calculate_new_score_sums_list_scores_correctly(self):
        """
        Test that an Entity calculates its new score as the sum of the scores
        of the lists that mention it.
        """
        test_object = Entity("BB")
        list1 = EntityList()
        list1.weight = 1.7
        list1.append(test_object)

        list2 = EntityList()
        list2.weight = 9.3
        list2.append(test_object)

        list3 = EntityList()
        list3.weight = 6.112
        list3.append(test_object)

        test_object.calculate_new_score()
        self.assertAlmostEqual(
            17.112, test_object.score, 3,
            "Score should now be the sum of the list scores")