コード例 #1
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")
コード例 #2
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")
コード例 #3
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")
コード例 #4
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))
コード例 #5
0
ファイル: test_entitylist.py プロジェクト: baillielab/maic
 def test_category_name_is_trimmed_both(self):
     """Check that an EntityList category name has both leading and
     trailing space trimmed"""
     test_object = EntityList()
     test_object.category_name = "   XYZ   other   "
     self.assertEqual(
         "XYZ   other", test_object.category_name,
         "Category name should have leading and trailing "
         "space trimmed")
コード例 #6
0
ファイル: test_entitylist.py プロジェクト: baillielab/maic
 def test_category_is_trimmed_right(self):
     """
     Check that an EntityList category has trailing space trimmed as a
     by-product of the category name
     """
     test_object = EntityList()
     test_object.category_name = "DEF    "
     # noinspection PyUnresolvedReferences
     self.assertEqual("DEF", test_object.category,
                      "Category should have trailing space trimmed")
コード例 #7
0
ファイル: test_entitylist.py プロジェクト: baillielab/maic
 def test_category_converts_to_uppercase_when_set(self):
     """
     Check that the category of an EntityList can be set as a by-product
     of the category_name and
     the reported value is uppercase
     """
     test_object = EntityList()
     test_object.category_name = "def"
     # noinspection PyUnresolvedReferences
     self.assertEqual("DEF", test_object.category, "Category should be DEF")
コード例 #8
0
ファイル: test_entitylist.py プロジェクト: baillielab/maic
    def test_category_is_trimmed_both_and_internally_subbed(self):
        """
        Check that an EntityList category has all space trimmed/replaced as
        a by-product of the category name.

        Leading/trailing space is discarded and internal spaces are
        converted to hyphens
        """
        test_object = EntityList()
        test_object.category_name = "   XYZ   other   "
        # noinspection PyUnresolvedReferences
        self.assertEqual(
            "XYZ-OTHER", test_object.category,
            "Category name should have leading and trailing "
            "space trimmed")
コード例 #9
0
ファイル: test_entitylist.py プロジェクト: baillielab/maic
 def test_category_name_is_trimmed_right(self):
     """Check that an EntityList category name has trailing space trimmed"""
     test_object = EntityList()
     test_object.category_name = "DEF    "
     self.assertEqual("DEF", test_object.category_name,
                      "Category name should have trailing space trimmed")
コード例 #10
0
ファイル: test_entitylist.py プロジェクト: baillielab/maic
 def test_category_name_is_trimmed_left(self):
     """Check that an EntityList category name has leading space trimmed"""
     test_object = EntityList()
     test_object.category_name = "   ABC"
     self.assertEqual("ABC", test_object.category_name,
                      "Category name should have leading space trimmed")