mormon 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+ require 'mormon'
3
+
4
+ describe Mormon::Weight do
5
+ it "get (transport, way type) must to return a value" do
6
+ Mormon::Weight.get(:car, :primary).should eq(2)
7
+ end
8
+ end
9
+
10
+ describe Mormon::Tile::Data do
11
+ before :each do
12
+ @tiledata = Mormon::Tile::Data.new :reset_cache => true
13
+ end
14
+
15
+ it "download a tile should not work at the moment" do
16
+ @tiledata.get_osm(15, 16218, 10741).should match(/Tile not found/)
17
+ end
18
+ end
19
+
20
+ describe Mormon::Tile::Name do
21
+ before :each do
22
+ @tilename = Mormon::Tile::Name.new
23
+ end
24
+
25
+ it "should return the correct xy coordinates" do
26
+ @tilename.xy(51.50610, -0.119888, 16).should eq([32746, 21792])
27
+ end
28
+
29
+ it "should return the correct edges" do
30
+ x, y = @tilename.xy(51.50610, -0.119888, 16)
31
+ @tilename.edges(x, y, 16).should eq([51.505323411493336, -0.120849609375, 51.50874245880333, -0.1153564453125])
32
+ end
33
+
34
+ it "should return the correct url for the tile" do
35
+ @tilename.url(51.50610, -0.119888, 16, :tah).should eq("http://a.tile.openstreetmap.org/16/51/0.png")
36
+ end
37
+ end
38
+
39
+ describe Mormon::OSM::Loader do
40
+ before :each do
41
+ @loader = Mormon::OSM::Loader.new File.dirname(__FILE__) + "/spec.osm"
42
+ end
43
+
44
+ it "should load the correct data" do
45
+ @loader.nodes.keys.size.should eq 534
46
+ @loader.ways.keys.size.should eq 135
47
+
48
+ @loader.routing[:cycle].keys.size.should eq 240
49
+ @loader.routing[:car].keys.size.should eq 240
50
+ @loader.routing[:train].keys.size.should eq 0
51
+ @loader.routing[:foot].keys.size.should eq 281
52
+ @loader.routing[:horse].keys.size.should eq 216
53
+ end
54
+
55
+ it "should has the correct nodes" do
56
+ map = { "448193026" => 1, "448193243" => 1, "448193220" => 1, "318099173" => 1 }
57
+ @loader.routing[:foot]["448193024"].should eq(map)
58
+ end
59
+ end
60
+
61
+ describe Mormon::OSM::Router do
62
+ before :each do
63
+ @loader = Mormon::OSM::Loader.new File.dirname(__FILE__) + "/spec.osm"
64
+ @router = Mormon::OSM::Router.new @loader
65
+ end
66
+
67
+ it "should do the routing without problems" do
68
+ response, route = @router.find_route 448193311, 453397968, :car
69
+ response.should eq "success"
70
+ route.should eq [
71
+ [-37.322900199999999, -59.1277355],
72
+ [-37.3234584, -59.1292045],
73
+ [-37.324045300000002, -59.130744],
74
+ [-37.324662600000003, -59.132366099999999],
75
+ [-37.325214799999998, -59.133816899999999],
76
+ [-37.3263769, -59.133125100000001],
77
+ [-37.327769600000003, -59.132296199999999],
78
+ [-37.328298599999997, -59.133707200000003],
79
+ [-37.328858799999999, -59.135200400000002]
80
+ ]
81
+ end
82
+
83
+ it "should find the route in tandil map" do
84
+ @loader = Mormon::OSM::Loader.new File.dirname(__FILE__) + "/tandil.osm"
85
+ @router = Mormon::OSM::Router.new @loader
86
+
87
+ response, route = @router.find_route 1355012894, 1527759159, :car
88
+ response.should eq "success"
89
+ route.should eq [
90
+ [-37.314227500000001, -59.083028499999998], [-37.315150099999997, -59.084156299999997], [-37.314264299999998, -59.085288499999997], [-37.315238600000001, -59.086456400000003], [-37.316189199999997, -59.087621499999997], [-37.317135299999997, -59.088781099999999], [-37.318047200000002, -59.0898988], [-37.3189803, -59.091042600000002], [-37.319898500000001, -59.092168000000001], [-37.320787299999999, -59.093257399999999], [-37.322678799999998, -59.0955759], [-37.324257199999998, -59.097501700000002], [-37.324342399999999, -59.0976675], [-37.323442, -59.0988349], [-37.322537599999997, -59.099982900000001], [-37.320699099999999, -59.102316899999998], [-37.322715600000002, -59.104815500000001], [-37.325489699999999, -59.1082538], [-37.324572699999997, -59.109404599999998], [-37.325524700000003, -59.1105327], [-37.326417999999997, -59.111670400000001], [-37.325528499999997, -59.112850700000003], [-37.326433199999997, -59.113965700000001], [-37.3267904, -59.114365900000003], [-37.326863699999997, -59.114550399999999], [-37.327440500000002, -59.116081100000002], [-37.327991900000001, -59.1175444], [-37.328552999999999, -59.119033799999997], [-37.329104200000003, -59.120496600000003], [-37.329658899999998, -59.121968600000002], [-37.330206199999999, -59.123420899999999], [-37.330755799999999, -59.124884399999999], [-37.331353300000004, -59.126429899999998], [-37.331652400000003, -59.127241400000003], [-37.331941100000002, -59.128025000000001], [-37.332166700000002, -59.1286238], [-37.332491400000002, -59.129485500000001], [-37.333024999999999, -59.130901999999999], [-37.333594699999999, -59.132413800000002], [-37.333622300000002, -59.132487500000003], [-37.334096700000003, -59.133752299999998], [-37.3345178, -59.134863600000003], [-37.335070399999999, -59.136329799999999], [-37.335618599999997, -59.137819700000001], [-37.3361801, -59.139275699999999], [-37.336721400000002, -59.140712100000002], [-37.337293500000001, -59.1422308], [-37.337850899999999, -59.143710200000001], [-37.338389300000003, -59.145182900000002], [-37.3386736, -59.145893600000001], [-37.338952499999998, -59.146633899999998], [-37.339135499999998, -59.147119699999998], [-37.3394239, -59.147885199999997], [-37.339503100000002, -59.148095499999997], [-37.339592099999997, -59.148331900000002], [-37.339890400000002, -59.149123400000001], [-37.340051299999999, -59.149550599999998], [-37.340075400000003, -59.149608000000001], [-37.340349500000002, -59.150260299999999], [-37.340552099999996, -59.150748700000001], [-37.3406783, -59.151004299999997], [-37.340945599999998, -59.151422500000002], [-37.343685100000002, -59.155270399999999], [-37.343783000000002, -59.155505300000002], [-37.344689199999998, -59.159352699999999], [-37.344747900000002, -59.159703200000003], [-37.344740799999997, -59.159876199999999], [-37.344758900000002, -59.159840699999997], [-37.344792099999999, -59.159806099999997], [-37.344832799999999, -59.159787899999998], [-37.344866199999998, -59.159786500000003], [-37.3449077, -59.159801299999998], [-37.344942699999997, -59.1598331], [-37.344966999999997, -59.159877999999999], [-37.344977100000001, -59.159948700000001], [-37.345046400000001, -59.159815899999998], [-37.345127400000003, -59.159665699999998], [-37.346329400000002, -59.158131699999998], [-37.347191299999999, -59.157031799999999], [-37.348837400000001, -59.154906699999998]
91
+ ]
92
+ end
93
+
94
+ end