def test_parse_simple_graph(): lines = ["light red bags contain 1 bright white bag, 2 muted yellow bags."] graph = parse_lines(lines) assert 1 == len(graph.keys()) for k in graph.keys(): assert k == "light red"
def test_three_colors(): lines = ["bright white bags contain 1 shiny gold bag.",\ "muted yellow bags contain 2 shiny gold bags, 9 faded blue bags.", "faded brown bags contain 1 muted yellow bag."] graph = parse_lines(lines) valid_colors = find_valid_different_colors_holding_shiny_bag(graph) assert 3 == valid_colors
def main(): filename = "input" with open(filename) as f: lines = f.readlines() graph = parse_lines(lines) valid_colors = find_valid_different_colors_holding_shiny_bag(graph) print("Valid colors of outermost bags:", valid_colors)
def test_input_test_file(): filename = "day7-py/input_test" with open(filename) as f: lines = f.readlines() graph = parse_lines(lines) valid_colors = find_valid_different_colors_holding_shiny_bag(graph) assert 4 == valid_colors
def test_one_node_four_leaves(): lines = [ "dark olive bags contain 3 faded blue bags, 4 dotted black bags.", "dark olive bags contain 3 bright white bags, 4 muted yellow bags." ] graph = parse_lines(lines) assert 4 == len(graph.get("dark olive"))
def test_two_leaves_same_node(): lines = [ "dark olive bags contain 3 faded blue bags, 4 dotted black bags.", "dark olive bags contain 3 bright white bags, 4 muted yellow bags." ] graph = parse_lines(lines) assert 1 == len(graph.keys())
def test_simple_file(): lines = [ "shiny gold bags contain 2 dark red bags.", "dark red bags contain 2 dark orange bags." ] graph = parse_lines(lines) no_of_bags = get_number_of_contained_bags(graph) assert 6 == no_of_bags
def test_part2_test_file(): filename = "day7-py/input_test_part2" with open(filename) as f: lines = f.readlines() graph = parse_lines(lines) no_of_bags = get_number_of_contained_bags(graph) assert 126 == no_of_bags
def main(): filename = "input" with open(filename) as f: lines = f.readlines() graph = parse_lines(lines) no_of_bags = get_number_of_contained_bags(graph) print("Number of individual bags inside of shiny bag:", no_of_bags)
def test_parse_two_nodes(): lines = ["light red bags contain 1 bright white bag, 2 muted yellow bags.",\ "dark orange bags contain 3 bright white bags, 4 muted yellow bags."] graph = parse_lines(lines) test_keys = ["light red", "dark orange"] for k in graph.keys(): test_keys.remove(k) assert 0 == len(test_keys) # test if all test keys are removed
def test_hold_one_bag(): lines = ["bright white bags contain 1 shiny gold bag."] graph = parse_lines(lines) valid_colors = find_valid_different_colors_holding_shiny_bag(graph) assert 1 == valid_colors