Created
July 29, 2013 00:07
-
-
Save marksim/6101387 to your computer and use it in GitHub Desktop.
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
require 'minitest/autorun' | |
require 'minitest/pride' | |
require_relative 'robot' | |
class RobotTest < MiniTest::Unit::TestCase | |
def test_has_name | |
assert_match /\w{2}\d{3}/, Robot.new.name | |
end | |
def test_name_sticks | |
robot = Robot.new | |
robot.name | |
assert_equal robot.name, robot.name | |
end | |
def test_different_robots_have_different_names | |
assert Robot.new.name != Robot.new.name | |
end | |
def test_reset_name | |
robot = Robot.new | |
name = robot.name | |
robot.reset | |
name2 = robot.name | |
assert name != name2 | |
assert_match /\w{2}\d{3}/, name2 | |
end | |
def test_instruction_count | |
robot = Robot.new | |
robot.name | |
robot.reset | |
robot.name | |
assert_equal robot.instruction_count, 2 | |
end | |
def test_timers | |
t = Time.now | |
reset_at = t + 3 | |
queried_at = t + 6 | |
robot = Robot.new(t) | |
robot.reset(reset_at) | |
assert_equal robot.timers(queried_at), | |
"3 seconds since last boot, 6 seconds since creation" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Considered using just Time.now since it wouldn't require injected times, but it slows down testing and is brittle. Not sure how better to do it.