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
|
require 'terrain'
describe Terrain do
before do
@sut = Terrain.new({:x => 3, :y => 3})
end
describe "when moving forward" do
describe "when the next position is to far east" do
it "should not let you move forward" do
@location[:x].must_equal 3
@location[:y].must_equal 0
end
before do
@heading = fake
@location = {:x => 3, :y => 0}
@heading.stub(:forward).with(@location).and_return({:x => 4, :y => 0})
@sut.move_forward(@heading, @location)
end
end
describe "when the next position is to far west" do
it "should not let you move forward" do
@location[:x].must_equal 0
@location[:y].must_equal 0
end
before do
@heading = fake
@location = {:x => 0, :y => 0}
@heading.stub(:forward).with(@location).and_return({:x => -1, :y => 0})
@sut.move_forward(@heading, @location)
end
end
describe "when the next position is to far north" do
it "should not let you move forward" do
@location[:x].must_equal 0
@location[:y].must_equal 3
end
before do
@heading = fake
@location = {:x => 0, :y => 3}
@heading.stub(:forward).with(@location).and_return({:x => 0, :y => 4})
@sut.move_forward(@heading, @location)
end
end
describe "when the next position is to far south" do
it "should not let you move forward" do
@location[:x].must_equal 0
@location[:y].must_equal 0
end
before do
@heading = fake
@location = {:x => 0, :y => 0}
@heading.stub(:forward).with(@location).and_return({:x => 0, :y => -1})
@sut.move_forward(@heading, @location)
end
end
describe "when the next position is just fine" do
it "should move position forward" do
@location[:x].must_equal 1
@location[:y].must_equal 1
end
before do
@heading = fake
@location = {:x => 0, :y => 0}
@heading.stub(:forward).with(@location).and_return({:x => 1, :y => 1})
@sut.move_forward(@heading, @location)
end
end
end
end
|