added part2 impl

main
Guido Schweizer 2022-12-03 11:47:03 +01:00
parent 13851a980c
commit 65161ec1a0
4 changed files with 30 additions and 9 deletions

Binary file not shown.

View File

@ -6,7 +6,6 @@ require_relative("templates")
def new_day(prompt, day)
input = prompt.multiline("Example input").join("")
print input
result = prompt.ask("Example result")
day_name = "day_#{day}"
@ -19,7 +18,7 @@ def new_day(prompt, day)
TTY::File.replace_in_file "#{day_name}/run.rb", /%day_name%/, day_name
TTY::File.replace_in_file "#{day_name}/test.rb", /%day_name%/, day_name
TTY::File.replace_in_file "#{day_name}/test.rb", /%example_result%/, result
TTY::File.replace_in_file "#{day_name}/test.rb", /%example_result_1%/, result
TTY::File.replace_in_file "#{day_name}/test.rb", /%example_input%/, input
puts "Done - run with:"

View File

@ -1,5 +1,17 @@
require "tty-prompt"
require "tty-file"
require "ostruct"
require_relative("templates")
def part_two(prompt, day)
prompt.say("part two not yet supported")
end
result = prompt.ask("Part two example result")
day_name = "day_#{day}"
TTY::File.copy_file("#{day_name}/impl.rb","#{day_name}/impl_2.rb")
TTY::File.replace_in_file "#{day_name}/test.rb", /example_result_2/, result
puts "Done - run with:"
puts "ruby #{day_name}/test.rb 2"
end

View File

@ -1,20 +1,25 @@
TEST_RB = <<~'TEST'
require_relative "impl"
if ARGV[0] == "2"
require_relative "impl_2"
RESULT = example_result_2
else
require_relative "impl"
RESULT = %example_result_1%
end
INPUT = <<~IN
%example_input%
IN
RESULT = %example_result%
def test_example
parsed = parse(INPUT)
result = calculate(parsed)
if result == RESULT
puts "Test successful. Now run with real input"
puts "ruby %day_name%/run.rb"
puts "ruby %day_name%/run.rb #{ARGV[0]}"
else
puts "Test failed"
puts "expected \"#{RESULT}\" got \"#{result}\""
@ -25,7 +30,12 @@ test_example
TEST
RUN_RB = <<~'RUN'
require_relative "impl"
if ARGV[0] == "2"
require_relative "impl_2"
else
require_relative "impl"
end
def print(result)
if result.is_a? Array