def test_common_count(self):
        groups_from_str = CustomsGroup.multiple_from_str(self.group_of_one_str + "\n\n" + self.group_of_three_str)
        assert sum_common_yes_answers_for_multiple_groups(groups_from_str) == 1
        assert sum_common_yes_answers_for_multiple_groups([self.group_of_one]) == 1
        assert sum_common_yes_answers_for_multiple_groups([self.group_of_three]) == 0

        group1 = CustomsGroup([CustomsForm("ovuxdgiheszjbaltw"), CustomsForm("oxwjiubhfylzavst")])
        group2 = CustomsGroup([CustomsForm("abcdefgxyz"), CustomsForm("abcdefg")])
        group3 = CustomsGroup([CustomsForm("abcdefgxyz"), CustomsForm("abcdfg")])
        group4 = CustomsGroup([CustomsForm("abcdefgxyz"), CustomsForm("acdfg"), CustomsForm("acdf")])
        group5 = CustomsGroup([CustomsForm("abcdefgxyz"), CustomsForm("acdfg"), CustomsForm("acdf"), CustomsForm("y")])
        assert group1.common_yes_count == 14
        assert group2.common_yes_count == 7
        assert group3.common_yes_count == 6
        assert group4.common_yes_count == 4
        assert group5.common_yes_count == 0

        assert sum_common_yes_answers_for_multiple_groups([group1, group2, group3, group4, group5]) == 31
 def test_create_multiple_from_string(self):
     assert CustomsGroup.multiple_from_str(
         self.group_of_one_str + "\n\n" + self.group_of_three_str
     ) == [self.group_of_one, self.group_of_three]
 def test_unique_count(self):
     groups = CustomsGroup.multiple_from_str(self.group_of_one_str + "\n\n" + self.group_of_three_str)
     assert sum_unique_yes_answers_for_multiple_groups(groups) == 10
     assert sum_unique_yes_answers_for_multiple_groups([self.group_of_one]) == 1
     assert sum_unique_yes_answers_for_multiple_groups([self.group_of_three]) == 9
Ejemplo n.º 4
0
def count_common_yes_answers_in_file(filename: str):
    with open(filename) as inputfile:
        encoded_form_groups = inputfile.read()
    all_groups = CustomsGroup.multiple_from_str(encoded_form_groups)
    return sum_common_yes_answers_for_multiple_groups(all_groups)