adding gem file executable

This commit is contained in:
2022-12-02 19:42:16 +01:00
parent cee9087661
commit 13851a980c
15 changed files with 138 additions and 22 deletions

0
templates/data Normal file
View File

17
templates/impl.rb Normal file
View File

@@ -0,0 +1,17 @@
#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

19
templates/run.rb Normal file
View File

@@ -0,0 +1,19 @@
require_relative "impl"
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

22
templates/test.rb Normal file
View File

@@ -0,0 +1,22 @@
require_relative "impl"
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"
else
puts "Test failed"
puts "expected \"#{RESULT}\" got \"#{result}\""
end
end
test_example