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")
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")
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")
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))
def test_calculate_new_score_drops_to_zero(self): """ Test that an Entity calculates its new score as zero by default. A default Entity has no lists to which it belongs thus its score is zero. """ test_object = Entity("BB") test_object.calculate_new_score() self.assertEqual(0, test_object.score, "Score should now be zero")
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")