Created
October 21, 2014 20:12
-
-
Save changemewtf/44e45fe005bd1b3336ca to your computer and use it in GitHub Desktop.
Little test scaffold for Project Euler problems.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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