Skip to content

Commit

Permalink
add test runs to 2021 elixir
Browse files Browse the repository at this point in the history
  • Loading branch information
Magiczne committed Dec 12, 2024
1 parent f87d5f3 commit 5a29f44
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions 2021/d01/main.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ defmodule Aoc.Day01 do
end
end

Aoc.Core.run_examples("01", &Aoc.Day01.reader/1, &Aoc.Day01.part1/1, &Aoc.Day01.part2/1)
Aoc.Core.run_solution("01", &Aoc.Day01.reader/1, &Aoc.Day01.part1/1, &Aoc.Day01.part2/1)
1 change: 1 addition & 0 deletions 2021/d02/main.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ defmodule Aoc.Day02 do
end
end

Aoc.Core.run_examples("02", &Aoc.Day02.reader/1, &Aoc.Day02.part1/1, &Aoc.Day02.part2/1)
Aoc.Core.run_solution("02", &Aoc.Day02.reader/1, &Aoc.Day02.part1/1, &Aoc.Day02.part2/1)
1 change: 1 addition & 0 deletions 2021/d03/main.exs
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@ defmodule Aoc.Day03 do
end
end

Aoc.Core.run_examples("03", &Aoc.Day03.reader/1, &Aoc.Day03.part1/1, &Aoc.Day03.part2/1)
Aoc.Core.run_solution("03", &Aoc.Day03.reader/1, &Aoc.Day03.part1/1, &Aoc.Day03.part2/1)
31 changes: 19 additions & 12 deletions 2021/framework/framework.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,31 @@ defmodule Aoc.Core do
)
end

def run_example do
def run_examples(day, reader, part1, part2) do
directory = "2021/d#{day}/test-runs"

if File.exists?(directory) do
File.ls!(directory)
|> Enum.each(fn file ->
testData = reader.("#{directory}/#{file}")

{duration1microSeconds, resultPart1} = :timer.tc(part1, [testData])
example_part1(resultPart1, file, duration1microSeconds / 1000)

{duration2microSeconds, resultPart2} = :timer.tc(part2, [testData])
example_part2(resultPart2, file, duration2microSeconds / 1000)
end)
end
end

def run_solution(day, reader, part1, part2) do
filePath = "2021/d#{day}/input.txt"
data = reader.(filePath)

# TODO: Timing
resultPart1 = part1.(data)
solution_part1(resultPart1, 0)

resultPart2 = part2.(data)
solution_part1(resultPart2, 0)

# {timePart1, resultPart1} = :timer.tc(part1, data)
# solution_part1(resultPart1, timePart1)
{duration1microSeconds, resultPart1} = :timer.tc(part1, [data])
solution_part1(resultPart1, duration1microSeconds / 1000)

# {timePart2, resultPart2} = :timer.tc(part2, data)
# solution_part2(resultPart2, timePart2)
{duration2microSeconds, resultPart2} = :timer.tc(part2, [data])
solution_part2(resultPart2, duration2microSeconds / 1000)
end
end
5 changes: 4 additions & 1 deletion turbo/generators/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export default function generator(plop: PlopTypes.NodePlopAPI): void {
type: 'input',
name: 'day',
message: 'Enter day which you are working on',
default: (new Date()).getDate().toString().padStart(2, '0')
default: (new Date()).getDate().toString().padStart(2, '0'),
transformer(input, answers, flags) {
return input.toString().padStart(2, '0')
},
},
{
type: 'list',
Expand Down

0 comments on commit 5a29f44

Please sign in to comment.