Skip to content

Commit

Permalink
Pass test: "opens file and writes each line to a list of strings"
Browse files Browse the repository at this point in the history
(Remember that filepaths in Elixir projects are from the root and are not relative to the source code reading the file)
  • Loading branch information
samjowen committed Dec 21, 2023
1 parent 5741a43 commit 8105d68
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/day1/day1.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,13 @@ defmodule Day1 do

{List.first(numbers), List.last(numbers)}
end

def parse_file(file_path, return_type) do
case return_type do
:string ->
file_path
|> File.read!()
|> String.split("\n", trim: true)
end
end
end
2 changes: 1 addition & 1 deletion lib/day1/day1_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Day1Test do
end

test "opens file and writes each line to a list of strings" do
assert Day1.parse_file("test/day1_test.txt", :string) == [
assert Day1.parse_file("./lib/day1/mocks/lines_of_text.txt", :string) == [
"first line of the file",
"second line of the file",
"third line of the file"
Expand Down

0 comments on commit 8105d68

Please sign in to comment.