Skip to content

Instantly share code, notes, and snippets.

@marksim
Created July 29, 2013 00:07
Show Gist options
  • Save marksim/6101387 to your computer and use it in GitHub Desktop.
Save marksim/6101387 to your computer and use it in GitHub Desktop.
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
@marksim
Copy link
Author

marksim commented Jul 29, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment