-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoy_robot_simulator_test.rb
52 lines (46 loc) · 1.1 KB
/
toy_robot_simulator_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'minitest/autorun'
require 'stringio'
require_relative 'toy_robot_simulator'
class ToyRobotSimulatorTest < Minitest::Test
def test_move
robot = ToyRobotSimulator::Robot.new(0, 0, 'NORTH')
robot.move
assert_equal '0,1,NORTH', robot.report
end
def test_left
robot = ToyRobotSimulator::Robot.new(0, 0, 'NORTH')
robot.left
robot.left
assert_equal '0,0,SOUTH', robot.report
end
def test_right
robot = ToyRobotSimulator::Robot.new(0, 0, 'WEST')
robot.right
robot.right
assert_equal '0,0,EAST', robot.report
end
def test_west_edge
robot = ToyRobotSimulator::Robot.new(1, 0, 'WEST')
robot.move
robot.move
assert_equal '0,0,WEST', robot.report
end
def test_east_edge
robot = ToyRobotSimulator::Robot.new(3, 0, 'EAST')
robot.move
robot.move
assert_equal '4,0,EAST', robot.report
end
def test_stdin
$stdin = StringIO.open do |s|
s.puts 'MOVE'
s.puts 'PLACE 0,0,NORTH'
s.puts 'REPORT'
s.string
end
assert_output("0,0,NORTH\n") do
ToyRobotSimulator.run
end
$stdin = STDIN
end
end