def test_count_multiple_edges_depth_2():
    rule_1 = Rule("bright yellow", [ContainedBag(2, "ocean blue")])
    rule_2 = Rule("ocean blue", [ContainedBag(3, "purple rain")])

    graph = BagGraph([rule_1, rule_2])

    # bright yellow bag contains 2 ocean blue bags, and then 2 * 3 purple rain bags = 8 total bags

    assert 8 == graph.count_contained_bags("bright yellow")
def test_add_empty_rule():
    graph = BagGraph()
    test_rule = Rule("bright yellow", [])

    graph.add_rule(test_rule)

    assert graph.count_containing_bags("bright yellow") == 0
def test_add_single_rule():
    graph = BagGraph()
    test_rule = Rule("bright white", [ContainedBag(1, "shiny gold")])

    graph.add_rule(test_rule)

    assert graph.count_containing_bags("shiny gold") == 1
def test_single_bag_rule():
    text = "bright white bags contain 1 shiny gold bag."

    rule = parse_rule(text)

    expected = Rule("bright white", [ContainedBag(1, "shiny gold")])

    assert expected == rule
def test_empty_bag_rule():
    text = "bright white bags contain no other bags."

    rule = parse_rule(text)

    expected = Rule("bright white", [])

    assert expected == rule
def test_count_multiple_edges_depth1():
    test_rule = Rule(
        "bright yellow",
        [ContainedBag(3, "purple vomit"),
         ContainedBag(5, "ocean blue")],
    )
    graph = BagGraph([test_rule])

    assert 8 == graph.count_contained_bags("bright yellow")
def test_multi_rule():
    text = "muted yellow bags contain 2 shiny gold bags, 9 faded blue bags."

    rule = parse_rule(text)

    expected = Rule(
        "muted yellow",
        [ContainedBag(2, "shiny gold"),
         ContainedBag(9, "faded blue")])

    assert expected == rule
def test_count_single_edge():
    test_rule = Rule("bright yellow", [ContainedBag(3, "purple vomit")])
    graph = BagGraph([test_rule])

    assert 3 == graph.count_contained_bags("bright yellow")