Skip to content

Commit

Permalink
Add failing tests (read the question better next time!)
Browse files Browse the repository at this point in the history
  • Loading branch information
samjowen committed Dec 28, 2023
1 parent c2bde07 commit 45cc5a3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/advent_of_code2023.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ defmodule AdventOfCode2023 do

# Day 2
def day2_solve_part2(input_file_path) do

Check warning on line 21 in lib/advent_of_code2023.ex

View workflow job for this annotation

GitHub Actions / Build and test

variable "input_file_path" is unused (if the variable is not meant to be used, prefix it with an underscore)
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
6 changes: 6 additions & 0 deletions lib/day2/day2.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ defmodule Day2 do
false -> true
end
end

def validate_set_by_colour_and_amount(game_set_string, cube_map) do

Check warning on line 72 in lib/day2/day2.ex

View workflow job for this annotation

GitHub Actions / Build and test

variable "cube_map" is unused (if the variable is not meant to be used, prefix it with an underscore)
# cube_map will be in the shape of a %{:red => x, :blue => y...}
set_cube_map = parse_game_set_amounts(game_set_string)

Check warning on line 74 in lib/day2/day2.ex

View workflow job for this annotation

GitHub Actions / Build and test

variable "set_cube_map" is unused (if the variable is not meant to be used, prefix it with an underscore)

end
end
24 changes: 24 additions & 0 deletions test/day2/day2_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Check warning on line 110 in test/day2/day2_test.exs

View workflow job for this annotation

GitHub Actions / Build and test

variable "thirty_cube_set_str" is unused (if the variable is not meant to be used, prefix it with an underscore)

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"

Check warning on line 122 in test/day2/day2_test.exs

View workflow job for this annotation

GitHub Actions / Build and test

variable "thirty_cube_set_str" is unused (if the variable is not meant to be used, prefix it with an underscore)

cube_map = %{
:red => 7,
:green => 13,
:blue => 14
}

assert Day2.validate_set_by_colour_and_amount(game_set_string, cube_map) == false
end
end

0 comments on commit 45cc5a3

Please sign in to comment.