B:BD[
3.156] → [
3.156:230]
test "greets the world" do
assert HandyHaversacks.hello() == :world
@example_rules [
{"light red", ["bright white", "muted yellow"]},
{"dark orange", ["bright white", "muted yellow"]},
{"bright white", ["shiny gold"]},
{"muted yellow", ["shiny gold", "faded blue"]},
{"shiny gold", ["dark olive", "vibrant plum"]},
{"dark olive", ["faded blue", "dotted black"]},
{"vibrant plum", ["faded blue", "dotted black"]},
{"faded blue", []},
{"dotted black", []}
]
test "parse rule" do
assert HandyHaversacks.parse_rule(
"light red bags contain 1 bright white bag, 2 muted yellow bags."
) == {"light red", ["bright white", "muted yellow"]}
assert HandyHaversacks.parse_rule(
"dark orange bags contain 3 bright white bags, 4 muted yellow bags."
) == {"dark orange", ["bright white", "muted yellow"]}
end
test "find_container" do
assert HandyHaversacks.contains({"light red", ["bright white", "muted yellow"]}, "shiny gold") ==
false
assert HandyHaversacks.contains({"muted yellow", ["shiny gold", "faded blue"]}, "shiny gold") ==
true
assert HandyHaversacks.containers_of(
[{"muted yellow", ["shiny gold", "faded blue"]}],
"shiny gold"
) == ["muted yellow"]
assert HandyHaversacks.containers_of(@example_rules, "shiny gold") == [
"bright white",
"muted yellow"
]
end
test "recursive_find_containers" do
assert HandyHaversacks.rcontainers_of(
[{"muted yellow", ["shiny gold", "faded blue"]}],
"shiny gold"
) == ["muted yellow"]
assert HandyHaversacks.rcontainers_of(@example_rules, "shiny gold") ==
[
"bright white",
"muted yellow",
"dark orange",
"light red"
]
|> Enum.sort()
end
test "example" do
assert File.read!("example")
|> String.split("\n", trim: true)
|> Enum.map(&HandyHaversacks.parse_rule/1)
|> HandyHaversacks.rcontainers_of("shiny gold")
|> Enum.count() == 4