adding gem file executable
This commit is contained in:
0
templates/data
Normal file
0
templates/data
Normal file
17
templates/impl.rb
Normal file
17
templates/impl.rb
Normal 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
19
templates/run.rb
Normal 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
22
templates/test.rb
Normal 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
|
||||
Reference in New Issue
Block a user