2022-12-02 19:42:16 +01:00
|
|
|
|
|
|
|
TEST_RB = <<~'TEST'
|
2022-12-03 11:47:03 +01:00
|
|
|
if ARGV[0] == "2"
|
|
|
|
require_relative "impl_2"
|
|
|
|
RESULT = example_result_2
|
|
|
|
else
|
|
|
|
require_relative "impl"
|
|
|
|
RESULT = %example_result_1%
|
|
|
|
end
|
|
|
|
|
2022-12-02 19:42:16 +01:00
|
|
|
|
|
|
|
INPUT = <<~IN
|
|
|
|
%example_input%
|
|
|
|
IN
|
|
|
|
|
|
|
|
def test_example
|
|
|
|
parsed = parse(INPUT)
|
|
|
|
result = calculate(parsed)
|
|
|
|
|
|
|
|
if result == RESULT
|
|
|
|
puts "Test successful. Now run with real input"
|
2022-12-03 11:47:03 +01:00
|
|
|
puts "ruby %day_name%/run.rb #{ARGV[0]}"
|
2022-12-02 19:42:16 +01:00
|
|
|
else
|
|
|
|
puts "Test failed"
|
|
|
|
puts "expected \"#{RESULT}\" got \"#{result}\""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test_example
|
|
|
|
TEST
|
|
|
|
|
|
|
|
RUN_RB = <<~'RUN'
|
2022-12-03 11:47:03 +01:00
|
|
|
if ARGV[0] == "2"
|
|
|
|
require_relative "impl_2"
|
|
|
|
else
|
|
|
|
require_relative "impl"
|
|
|
|
end
|
|
|
|
|
2022-12-02 19:42:16 +01:00
|
|
|
|
|
|
|
def print(result)
|
|
|
|
if result.is_a? Array
|
|
|
|
result.map! {|l| "#{l}\n" }
|
|
|
|
end
|
|
|
|
|
|
|
|
puts result
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
puts "running your implementation"
|
|
|
|
input = File.new("%day_name%/data").read
|
|
|
|
data = parse(input)
|
|
|
|
result = calculate(data)
|
|
|
|
print(result)
|
|
|
|
end
|
|
|
|
|
|
|
|
run
|
|
|
|
RUN
|
|
|
|
|
|
|
|
IMPL_RB = <<~'IMPL'
|
|
|
|
#prepare the input which is a string containing new lines
|
|
|
|
def parse(input)
|
|
|
|
data = []
|
|
|
|
input.each_line do |line|
|
|
|
|
data << line
|
|
|
|
end
|
|
|
|
data
|
|
|
|
end
|
|
|
|
|
|
|
|
# result should a single string or integer
|
|
|
|
def calculate(data)
|
|
|
|
result = ""
|
|
|
|
data.each do |d|
|
|
|
|
result = d
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
|
|
|
IMPL
|