From 45cc5a344893ac129216c066f9a1132afab69f0e Mon Sep 17 00:00:00 2001 From: Samuel Owen Date: Thu, 28 Dec 2023 00:58:54 +0000 Subject: [PATCH] Add failing tests (read the question better next time!) --- lib/advent_of_code2023.ex | 11 ++++++++++- lib/day2/day2.ex | 6 ++++++ test/day2/day2_test.exs | 24 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/advent_of_code2023.ex b/lib/advent_of_code2023.ex index 674e1e6..c2d0b5a 100644 --- a/lib/advent_of_code2023.ex +++ b/lib/advent_of_code2023.ex @@ -19,6 +19,15 @@ defmodule AdventOfCode2023 do # Day 2 def day2_solve_part2(input_file_path) do - Day1.parse_file(input_file_path) + # games_list = Day1.parse_file(input_file_path) + # accumulator = %{} + + # Enum.reduce(games_list, accumulator, fn game, accumulator -> + # game_number = Day2.parse_game_number(game) + # game_sets = Day2.parse_game_sets(game) + # set_validity_list = Enum.map(game_sets, &Day2.validate_set(&1, 13)) + + # Map.put(accumulator, game_number, game_set_amounts_sum) + # end) end end diff --git a/lib/day2/day2.ex b/lib/day2/day2.ex index 6bdf245..a566137 100644 --- a/lib/day2/day2.ex +++ b/lib/day2/day2.ex @@ -68,4 +68,10 @@ defmodule Day2 do false -> true end end + + def validate_set_by_colour_and_amount(game_set_string, cube_map) do + # cube_map will be in the shape of a %{:red => x, :blue => y...} + set_cube_map = parse_game_set_amounts(game_set_string) + + end end diff --git a/test/day2/day2_test.exs b/test/day2/day2_test.exs index 48c8336..d6f304b 100644 --- a/test/day2/day2_test.exs +++ b/test/day2/day2_test.exs @@ -105,4 +105,28 @@ defmodule Day2Test do assert Day2.validate_set(missing_color_exceeding_limit_set_str, cube_limit) == false end + + test "it can validate a valid game set by the number of cubes and their colurs" do + thirty_cube_set_str = "7 red, 15 blue, 8 green" + + cube_map = %{ + :red => 12, + :green => 13, + :blue => 14 + } + + assert Day2.validate_set_by_colour_and_amount(game_set_string, cube_map) == true + end + + test "it can validate an invalid game set by the number of cubes and their colurs" do + thirty_cube_set_str = "12 red, 12 blue, 15 green" + + cube_map = %{ + :red => 7, + :green => 13, + :blue => 14 + } + + assert Day2.validate_set_by_colour_and_amount(game_set_string, cube_map) == false + end end