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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
require 'rover'
describe Rover do
def create_sut(heading, x = 0, y = 0)
Rover.new heading,{ :x =>x,:y => y }
end
describe "when facing north" do
before do
@sut = create_sut :north, 0, 0
end
describe "when turning right" do
it "should face east" do
@sut.turn_right
@sut.heading.must_equal :east
end
end
describe "when turning left" do
it "should face west" do
@sut.turn_left
@sut.heading.must_equal :west
end
end
describe "when driving forward" do
before do
@sut.move_forward(@terrain)
end
it "should increment the y coordinate on the terrain" do
@sut.location.must_equal({:x => 0, :y => 1})
end
end
end
describe "when facing south" do
before do
@sut = create_sut :south, 0, 3
end
describe "when turning right" do
it "should face west" do
@sut.turn_right
@sut.heading.must_equal :west
end
end
describe "when turning left" do
it "should face east" do
@sut.turn_left
@sut.heading.must_equal :east
end
end
describe "when driving forward" do
before do
@sut.move_forward(@terrain)
end
it "should decrement the y coordinate on the terrain" do
@sut.location.must_equal({:x => 0, :y => 2})
end
end
end
describe "when facing east" do
before do
@sut = create_sut :east
end
describe "when turning right" do
it "should face south" do
@sut.turn_right
@sut.heading.must_equal :south
end
end
describe "when turning left" do
it "should face north" do
@sut.turn_left
@sut.heading.must_equal :north
end
end
describe "when driving forward" do
before do
@sut.move_forward(@terrain)
end
it "should increment the x coordinate on the terrain" do
@sut.location.must_equal({:x => 1, :y => 0})
end
end
end
describe "when facing west" do
before do
@sut = create_sut :west, 1, 0
end
describe "when turning right" do
it "should face north" do
@sut.turn_right
@sut.heading.must_equal :north
end
end
describe "when turning left" do
it "should face south" do
@sut.turn_left
@sut.heading.must_equal :south
end
end
describe "when driving forward" do
before do
@sut.move_forward(@terrain)
end
it "should decrement the x coordinate on the terrain" do
@sut.location.must_equal({:x => 0, :y => 0})
end
end
end
end
|