From 5a29f44b236062beb8fd72513e64b633d95daa54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kleszczy=C5=84ski?= Date: Wed, 11 Dec 2024 22:24:15 +0100 Subject: [PATCH] add test runs to 2021 elixir --- 2021/d01/main.exs | 1 + 2021/d02/main.exs | 1 + 2021/d03/main.exs | 1 + 2021/framework/framework.exs | 31 +++++++++++++++++++------------ turbo/generators/config.ts | 5 ++++- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/2021/d01/main.exs b/2021/d01/main.exs index 208f04f..02854fa 100644 --- a/2021/d01/main.exs +++ b/2021/d01/main.exs @@ -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) diff --git a/2021/d02/main.exs b/2021/d02/main.exs index 94aa6d9..07d7313 100644 --- a/2021/d02/main.exs +++ b/2021/d02/main.exs @@ -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) diff --git a/2021/d03/main.exs b/2021/d03/main.exs index e65ac82..0928459 100644 --- a/2021/d03/main.exs +++ b/2021/d03/main.exs @@ -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) diff --git a/2021/framework/framework.exs b/2021/framework/framework.exs index 373bef0..aae5f4e 100644 --- a/2021/framework/framework.exs +++ b/2021/framework/framework.exs @@ -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 diff --git a/turbo/generators/config.ts b/turbo/generators/config.ts index 4f3d7c5..ac233c7 100644 --- a/turbo/generators/config.ts +++ b/turbo/generators/config.ts @@ -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',