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
|
require 'rover'
require 'north'
require 'east'
require 'west'
require 'south'
describe Rover do
def create_sut(heading, x = 0, y = 0)
directions = {:north => North.new, :east => East.new, :west => West.new, :south => South.new}
Rover.new directions[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
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
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
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
end
describe "when driving forward" do
it "should move forward along the terrain" do
@terrain.received(:move_forward).called_with(@sut.instance_variable_get(:@heading), @sut.location).wont_be_nil
end
before do
@terrain = fake
@sut = create_sut(:north)
@sut.move_forward(@terrain)
end
end
end
|