Skip to content

Instantly share code, notes, and snippets.

@changemewtf
Created October 21, 2014 20:12
Show Gist options
  • Save changemewtf/44e45fe005bd1b3336ca to your computer and use it in GitHub Desktop.
Save changemewtf/44e45fe005bd1b3336ca to your computer and use it in GitHub Desktop.
Little test scaffold for Project Euler problems.
if __FILE__ == $0
require 'minitest/autorun'
require 'benchmark'
require 'logger'
output = StringIO.new
logger = Logger.new output
logger.formatter = ->(severity, datetime, progname, msg) { msg + "\n" }
describe "solution" do
before :each do
logger.info "Running #{name}..."
end
CASES.each do |label, work|
it "should calculate the #{label} case" do
assert_equal ANSWERS[label], work.call()
end
it "should calculate the #{label} case in less than one minute" do
report = Benchmark.measure &work
logger.debug report.to_s.strip
assert_operator report.real, :<=, 60.0
end
end
end
if ENV['DEBUG']
Minitest.after_run do
puts
output.rewind
print output.read
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment