Skip to content

Commit

Permalink
Refactor day1_solve_part_2 to accept input file path as an argument, …
Browse files Browse the repository at this point in the history
…also add failing tests
  • Loading branch information
samjowen committed Dec 23, 2023
1 parent 87e156e commit e472779
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/advent_of_code2023.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ defmodule AdventOfCode2023 do
Enum.sum(number_list)
end

def day1_solve_part_2() do
string_list = Day1.parse_file("lib/day1/data/input.txt")
def day1_solve_part_2(input_file_path) do
string_list = Day1.parse_file(input_file_path)

replaced_number_list =
Enum.map(string_list, &Day1.convert_substrings_to_integer_strings/1)

number_list = Enum.map(replaced_number_list, &Day1.combine_first_and_last_number/1)
IO.inspect(number_list)
Enum.sum(number_list)
end
end
2 changes: 1 addition & 1 deletion test/day1/day1_solves_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ defmodule Day1SolvesTest do
end

test "solves the day 1 part II puzzle correctly" do

Check failure on line 13 in test/day1/day1_solves_test.exs

View workflow job for this annotation

GitHub Actions / Build and test

test solves the day 1 part II puzzle correctly (Day1SolvesTest)
assert AdventOfsCode2023.day1_solve_part_2("./test/day1/mocks/part1-test-case.txt") == 281
assert AdventOfCode2023.day1_solve_part_2("./test/day1/mocks/part2-test-case.txt") == 281
end
end
11 changes: 11 additions & 0 deletions test/day1/day1_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,15 @@ defmodule Day1Test do
) ==
"0 1 2 3 4 5 6 7 8 9"
end

test "should convert substrings according to a replacement map" do

Check failure on line 65 in test/day1/day1_test.exs

View workflow job for this annotation

GitHub Actions / Build and test

test should convert substrings according to a replacement map (Day1Test)
translation_map = %{
"meow" => "woof",
"woof" => "meow"
}

test_string = "meow woof"

assert Day1.replace_substrings(test_string, translation_map) == "woof meow"

Check warning on line 73 in test/day1/day1_test.exs

View workflow job for this annotation

GitHub Actions / Build and test

Day1.replace_substrings/2 is undefined or private
end
end

0 comments on commit e472779

Please sign in to comment.