/
map_spec.rb
61 lines (49 loc) · 1.73 KB
/
map_spec.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
53
54
55
56
57
58
59
60
61
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'map'
describe Map do
describe "non empty 4x4 tiled, 32px tiles map" do
before :each do
@map = Map.new
@map.width = 4
@map.height = 4
@map.tile_size = 32
@map.half_tile_size = 16
end
it "should covert up/left coords to tiles correctly" do
exp = [0,0]
@map.coords_to_tiles(12, 12).should == exp
@map.coords_to_tiles(0, 0).should == exp
@map.coords_to_tiles(15, 15).should == exp
end
it "should covert bottom/left coords to tiles correctly" do
exp = [0,3]
@map.coords_to_tiles(12, 122).should == exp
@map.coords_to_tiles(0, 97).should == exp
@map.coords_to_tiles(31, 127).should == exp
end
it "should covert bottom/right coords to tiles correctly" do
exp = [3,3]
@map.coords_to_tiles(122, 122).should == exp
@map.coords_to_tiles(97, 97).should == exp
@map.coords_to_tiles(127, 127).should == exp
end
it "should covert up/right coords to tiles correctly" do
exp = [3,0]
@map.coords_to_tiles(122, 12).should == exp
@map.coords_to_tiles(97, 0).should == exp
@map.coords_to_tiles(127, 31).should == exp
end
it "should convert up/left tiles to coords correctly" do
@map.tiles_to_coords(0, 0).should == [16,16]
end
it "should convert up/right tiles to coords correctly" do
@map.tiles_to_coords(0, 3).should == [16,112]
end
it "should convert bottom/left tiles to coords correctly" do
@map.tiles_to_coords(3, 0).should == [112,16]
end
it "should convert bottom/right tiles to coords correctly" do
@map.tiles_to_coords(3, 3).should == [112,112]
end
end
end