advent-of-code/2015-elixir/lib/mix/tasks/bootstrap.ex

93 lines
1.9 KiB
Elixir
Raw Normal View History

2021-11-01 16:40:46 +01:00
defmodule Mix.Tasks.Aoc.New do
use Mix.Task
@shortdoc "Bootstrap new solution"
@impl Mix.Task
2021-11-04 08:52:41 +01:00
@year 2021
2021-11-01 16:40:46 +01:00
def run([n, name]) do
id = n |> String.pad_leading(2, "0")
input_file = "./inputs/" <> id <> ".in"
test_file = "./test/day_" <> id <> "_test.exs"
solution_file = "./lib/solutions/day_" <> id <> ".ex"
IO.puts("Creating " <> input_file)
File.touch(input_file)
IO.puts("Creating " <> test_file)
File.write!(test_file, test_file_content(id))
IO.puts("Creating " <> solution_file)
2021-11-04 08:52:41 +01:00
File.write!(solution_file, solution_file_content(name, id, n))
2021-11-01 16:40:46 +01:00
"""
\nDone! Start coding.
Get your puzzle input here:
2021-11-04 08:52:41 +01:00
https://adventofcode.com/#{@year}/day/#{n}/input
2021-11-01 16:40:46 +01:00
mix test -- run tests.
2021-11-04 08:52:41 +01:00
mix aoc.solve_all -- run all puzzles, starting with 1
mix aoc.solve #{id} -- run single puzzle, 1-25
2021-11-01 16:40:46 +01:00
"""
|> IO.puts()
end
defp test_file_content(id) do
"""
defmodule Day#{id}Test do
use ExUnit.Case
doctest Aoc.Solution.Day#{id}
import Aoc.Solution.Day#{id}
test "parses the input" do
expected = 10
assert parse!("10") == expected
end
test "solves first part" do
a = "something" |> parse!() |> solve_first_part()
2021-11-04 08:52:41 +01:00
assert a == :something
2021-11-01 16:40:46 +01:00
end
test "solves second part" do
a = "something" |> parse!() |> solve_second_part()
2021-11-04 08:52:41 +01:00
assert a == :something
2021-11-01 16:40:46 +01:00
end
end
"""
end
2021-11-04 08:52:41 +01:00
defp solution_file_content(name, id, n) do
2021-11-01 16:40:46 +01:00
~s"""
defmodule Aoc.Solution.Day#{id} do
2021-11-04 08:52:41 +01:00
@name "Day #{n}: #{name}"
2021-11-01 16:40:46 +01:00
@behaviour Solution
@impl Solution
def get_name, do: @name
@impl Solution
def parse!(_raw) do
"10"
end
@impl Solution
def solve_first_part(_input) do
"(TBW)"
end
@impl Solution
def solve_second_part(_input) do
"(TBW)"
end
end
"""
end
end