added part2 impl
parent
13851a980c
commit
65161ec1a0
Binary file not shown.
|
@ -6,7 +6,6 @@ require_relative("templates")
|
||||||
|
|
||||||
def new_day(prompt, day)
|
def new_day(prompt, day)
|
||||||
input = prompt.multiline("Example input").join("")
|
input = prompt.multiline("Example input").join("")
|
||||||
print input
|
|
||||||
result = prompt.ask("Example result")
|
result = prompt.ask("Example result")
|
||||||
|
|
||||||
day_name = "day_#{day}"
|
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}/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", /%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
|
TTY::File.replace_in_file "#{day_name}/test.rb", /%example_input%/, input
|
||||||
|
|
||||||
puts "Done - run with:"
|
puts "Done - run with:"
|
||||||
|
|
|
@ -1,5 +1,17 @@
|
||||||
require "tty-prompt"
|
require "tty-prompt"
|
||||||
|
require "tty-file"
|
||||||
|
require "ostruct"
|
||||||
|
|
||||||
|
require_relative("templates")
|
||||||
|
|
||||||
def part_two(prompt, day)
|
def part_two(prompt, day)
|
||||||
prompt.say("part two not yet supported")
|
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
|
end
|
|
@ -1,20 +1,25 @@
|
||||||
|
|
||||||
TEST_RB = <<~'TEST'
|
TEST_RB = <<~'TEST'
|
||||||
|
if ARGV[0] == "2"
|
||||||
|
require_relative "impl_2"
|
||||||
|
RESULT = example_result_2
|
||||||
|
else
|
||||||
require_relative "impl"
|
require_relative "impl"
|
||||||
|
RESULT = %example_result_1%
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
INPUT = <<~IN
|
INPUT = <<~IN
|
||||||
%example_input%
|
%example_input%
|
||||||
IN
|
IN
|
||||||
|
|
||||||
RESULT = %example_result%
|
|
||||||
|
|
||||||
def test_example
|
def test_example
|
||||||
parsed = parse(INPUT)
|
parsed = parse(INPUT)
|
||||||
result = calculate(parsed)
|
result = calculate(parsed)
|
||||||
|
|
||||||
if result == RESULT
|
if result == RESULT
|
||||||
puts "Test successful. Now run with real input"
|
puts "Test successful. Now run with real input"
|
||||||
puts "ruby %day_name%/run.rb"
|
puts "ruby %day_name%/run.rb #{ARGV[0]}"
|
||||||
else
|
else
|
||||||
puts "Test failed"
|
puts "Test failed"
|
||||||
puts "expected \"#{RESULT}\" got \"#{result}\""
|
puts "expected \"#{RESULT}\" got \"#{result}\""
|
||||||
|
@ -25,7 +30,12 @@ test_example
|
||||||
TEST
|
TEST
|
||||||
|
|
||||||
RUN_RB = <<~'RUN'
|
RUN_RB = <<~'RUN'
|
||||||
|
if ARGV[0] == "2"
|
||||||
|
require_relative "impl_2"
|
||||||
|
else
|
||||||
require_relative "impl"
|
require_relative "impl"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def print(result)
|
def print(result)
|
||||||
if result.is_a? Array
|
if result.is_a? Array
|
||||||
|
|
Loading…
Reference in New Issue