active_road 0.0.2 → 0.0.3

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.
Files changed (76) hide show
  1. checksums.yaml +15 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +7 -2
  4. data/Gemfile +8 -2
  5. data/Guardfile +2 -6
  6. data/README.md +69 -9
  7. data/Rakefile +8 -7
  8. data/active_road.gemspec +19 -15
  9. data/app/models/active_road/access_link.rb +4 -4
  10. data/app/models/active_road/access_point.rb +5 -9
  11. data/app/models/active_road/boundary.rb +41 -0
  12. data/app/models/active_road/junction.rb +4 -18
  13. data/app/models/active_road/junction_conditionnal_cost.rb +2 -0
  14. data/app/models/active_road/junctions_physical_road.rb +5 -0
  15. data/app/models/active_road/logical_road.rb +5 -4
  16. data/app/models/active_road/osm_pbf_importer.rb +293 -0
  17. data/app/models/active_road/osm_pbf_importer_level_db.rb +784 -0
  18. data/app/models/active_road/path.rb +40 -9
  19. data/app/models/active_road/physical_road.rb +22 -27
  20. data/app/models/active_road/physical_road_conditionnal_cost.rb +3 -1
  21. data/app/models/active_road/request_conditionnal_cost_linker.rb +59 -0
  22. data/app/models/active_road/street_number.rb +60 -57
  23. data/app/models/active_road/terra_importer.rb +161 -0
  24. data/db/migrate/20120419093427_add_kind_to_physical_roads.rb +2 -2
  25. data/db/migrate/20140206091734_create_boundaries.rb +16 -0
  26. data/db/migrate/20140210132933_add_attributes_to_physical_road.rb +9 -0
  27. data/db/migrate/20140219095521_add_boundary_id_to_logical_road.rb +5 -0
  28. data/db/migrate/20140228072448_add_boundary_id_to_physical_road.rb +5 -0
  29. data/db/migrate/20140304141150_add_marker_to_physical_road.rb +5 -0
  30. data/db/migrate/20140310083550_add_tags_to_street_number.rb +5 -0
  31. data/db/migrate/20140317153437_add_index_to_conditionnal_costs.rb +6 -0
  32. data/db/migrate/20140602160047_add_physical_road_index_to_junctions_physical_road.rb +5 -0
  33. data/lib/active_road.rb +8 -2
  34. data/lib/active_road/engine.rb +4 -1
  35. data/lib/active_road/shortest_path/finder.rb +37 -46
  36. data/lib/active_road/simulation_tool.rb +73 -0
  37. data/lib/active_road/version.rb +1 -1
  38. data/lib/tasks/activeroad_tasks.rake +88 -4
  39. data/script/benchmark_import_kyotocabinet.rb +148 -0
  40. data/script/benchmark_shortest_path.rb +22 -0
  41. data/script/count_tag_in_osm_data.rb +114 -0
  42. data/script/import-tiger-numbers +3 -3
  43. data/spec/dummy/db/schema.rb +2 -1
  44. data/spec/dummy/db/structure.sql +100 -11
  45. data/spec/factories/boundary.rb +8 -0
  46. data/spec/factories/junction.rb +1 -1
  47. data/spec/factories/physical_road.rb +1 -2
  48. data/spec/fixtures/test.osm +120 -0
  49. data/spec/fixtures/test.osm.bz2 +0 -0
  50. data/spec/fixtures/test.osm.pbf +0 -0
  51. data/spec/lib/active_road/shortest_path/finder_spec.rb +143 -90
  52. data/spec/lib/active_road/shortest_path/performance_finder_spec.rb +59 -0
  53. data/spec/models/active_road/access_point_spec.rb +9 -18
  54. data/spec/models/active_road/junction_conditionnal_cost_spec.rb +4 -4
  55. data/spec/models/active_road/junction_spec.rb +34 -11
  56. data/spec/models/active_road/logical_road_spec.rb +20 -19
  57. data/spec/models/active_road/osm_pbf_importer_level_db_spec.rb +410 -0
  58. data/spec/models/active_road/path_spec.rb +1 -1
  59. data/spec/models/active_road/physical_road_conditionnal_cost_spec.rb +4 -4
  60. data/spec/models/active_road/physical_road_spec.rb +14 -3
  61. data/spec/models/active_road/request_conditionnal_cost_linker_spec.rb +65 -0
  62. data/spec/models/active_road/shared_examples/osm_pbf_importer_spec.rb +148 -0
  63. data/spec/models/active_road/street_number_spec.rb +58 -58
  64. data/spec/models/active_road/terra_importer_spec.rb +140 -0
  65. data/spec/spec_helper.rb +14 -9
  66. data/spec/support/geometry_support.rb +36 -0
  67. data/spec/support/profile.rb +19 -0
  68. data/tmp/performance/.gitignore +0 -0
  69. data/travis/before_install.sh +5 -9
  70. data/travis/before_script.sh +7 -7
  71. metadata +118 -121
  72. data/app/models/active_road/physical_road_filter.rb +0 -41
  73. data/app/models/active_road/terra_import.rb +0 -148
  74. data/spec/models/active_road/physical_road_filter_spec.rb +0 -85
  75. data/spec/models/active_road/terra_import_spec.rb +0 -113
  76. data/spec/support/georuby_ext.rb +0 -15
@@ -2,101 +2,140 @@ require 'spec_helper'
2
2
 
3
3
  describe ActiveRoad::ShortestPath::Finder do
4
4
 
5
- # Path schema
6
- #
7
- # E-----------------F
8
- # | _______________/|
9
- # |/ |
10
- # C-----------------D
11
- # | |
12
- # | |
13
- # A-----------------B
14
- #
15
-
16
- let(:departure) { point(-0.1, 0.1) }
17
- let(:arrival) { point(1, 2) }
18
- let(:speed) { 4 }
19
- let(:constraints) { {:transport_mode => [:pedestrian, nil]} }
20
-
21
- let(:ab) { create(:physical_road, :objectid => "ab", :geometry => line_string( "0 0,1 0" ) ) }
22
- let(:cd) { create(:physical_road, :objectid => "cd", :geometry => line_string( "0 1,1 1" ) ) }
23
- let(:ef) { create(:physical_road, :objectid => "ef", :geometry => line_string( "0 2,1 2" ) ) }
24
- let(:ac) { create(:physical_road, :objectid => "ac", :geometry => line_string( "0 0,0 1" ), :uphill => 2 ) }
25
- let(:bd) { create(:physical_road, :objectid => "bd", :geometry => line_string( "1 0,1 1" ) ) }
26
- let(:ce) { create(:physical_road, :objectid => "ce", :geometry => line_string( "0 1,0 2" ), :uphill => 2 ) }
27
- let(:df) { create(:physical_road, :objectid => "df", :geometry => line_string( "1 1,1 2" ) ) }
28
- let(:cf) { create(:physical_road, :objectid => "cf", :geometry => line_string( "0 1,1 2" ), :transport_mode => :bike, :uphill => 2 ) }
29
-
30
- let!(:a) { create(:junction, :geometry => point(0, 0), :physical_roads => [ ab, ac ] ) }
31
- let!(:b) { create(:junction, :geometry => point(1, 0), :physical_roads => [ ab, bd ] ) }
32
- let!(:c) { create(:junction, :geometry => point(0, 1), :physical_roads => [ cd, ac, ce, cf ] ) }
33
- let!(:d) { create(:junction, :geometry => point(1, 1), :physical_roads => [ cd, bd, df ] ) }
34
- let!(:e) { create(:junction, :geometry => point(0, 2), :physical_roads => [ ce, ef ] ) }
35
- let!(:f) { create(:junction, :geometry => point(1, 2), :physical_roads => [ ef, df, cf ] ) }
36
-
37
- it "should find a solution between first and last road with with no constraints" do
38
- subject = ActiveRoad::ShortestPath::Finder.new departure, arrival, 4
39
- subject.path.should_not be_blank
40
- subject.path.size.should == 6
41
- subject.path[2].physical_road.objectid.should == "ac"
42
- subject.path[3].physical_road.objectid.should == "cf"
43
- end
44
-
45
- it "should find a solution between first and last road with physical_road filter in constraints" do
46
- subject = ActiveRoad::ShortestPath::Finder.new departure, arrival, 4, constraints
47
- subject.path.should_not be_blank
48
- subject.path.size.should == 7
49
- subject.path[2].physical_road.objectid.should == "ac"
50
- subject.path[3].physical_road.objectid.should == "ce"
51
- subject.path[4].physical_road.objectid.should == "ef"
5
+ shared_context "shared simple graph" do
6
+ # Path schema
7
+ #
8
+ # E-----------------F
9
+ # | _______________/|
10
+ # |/ |
11
+ # C-----------------D
12
+ # | |
13
+ # | |
14
+ # A-----------------B
15
+ #
16
+ let!(:ab) { create(:physical_road, :objectid => "ab", :geometry => line_string( "0.0 0.0,1.0 0.0" ) ) }
17
+ let!(:cd) { create(:physical_road, :objectid => "cd", :geometry => line_string( "0.0 1.0,1.0 1.0" ) ) }
18
+ let!(:ef) { create(:physical_road, :objectid => "ef", :geometry => line_string( "0.0 2.0,1.0 2.0" ) ) }
19
+ let!(:ac) { create(:physical_road, :objectid => "ac", :geometry => line_string( "0.0 0.0,0.0 1.0" ) ) }
20
+ let!(:bd) { create(:physical_road, :objectid => "bd", :geometry => line_string( "1.0 0.0,1.0 1.0" ) ) }
21
+ let!(:ce) { create(:physical_road, :objectid => "ce", :geometry => line_string( "0.0 1.0,0.0 2.0" ) ) }
22
+ let!(:df) { create(:physical_road, :objectid => "df", :geometry => line_string( "1.0 1.0,1.0 2.0" ) ) }
23
+ let!(:cf) { create(:physical_road, :objectid => "cf", :geometry => line_string( "0.0 1.0,1.0 2.0" ) ) }
24
+
25
+ let!(:a) { create(:junction, :objectid => "a", :geometry => point(0.0, 0.0), :physical_roads => [ ab, ac ] ) }
26
+ let!(:b) { create(:junction, :objectid => "b", :geometry => point(1.0, 0.0), :physical_roads => [ ab, bd ] ) }
27
+ let!(:c) { create(:junction, :objectid => "c", :geometry => point(0.0, 1.0), :physical_roads => [ cd, ac, ce, cf ] ) }
28
+ let!(:d) { create(:junction, :objectid => "d", :geometry => point(1.0, 1.0), :physical_roads => [ cd, bd, df ] ) }
29
+ let!(:e) { create(:junction, :objectid => "e", :geometry => point(0.0, 2.0), :physical_roads => [ ce, ef ] ) }
30
+ let!(:f) { create(:junction, :objectid => "f", :geometry => point(1.0, 2.0), :physical_roads => [ ef, df, cf ] ) }
31
+
52
32
  end
53
33
 
54
- it "should find a solution between first and last road with context arguments in constraints" do
55
- subject = ActiveRoad::ShortestPath::Finder.new departure, arrival, 4, { :uphill => 3 }
56
- subject.path.should_not be_blank
57
- subject.path.size.should == 7
58
- subject.path[2].physical_road.objectid.should == "ac"
59
- subject.path[3].physical_road.objectid.should == "cd"
60
- subject.path[4].physical_road.objectid.should == "df"
61
- end
62
-
63
- it "should return something when no solution" do
64
- subject = ActiveRoad::ShortestPath::Finder.new departure, arrival, 4, constraints
65
- end
66
-
67
-
68
- # describe "Shortest path with weights" do
34
+ let(:departure) { point(-0.0005, 0.0005) }
35
+ let(:arrival) { point(1.0005, 1.98) }
36
+ let(:speed) { 4 }
37
+ let(:constraints) { ["bike"] }
69
38
 
70
- # it "should find a solution between first and last road with weights" do
71
- # subject = ActiveRoad::ShortestPath::Finder.new source, destination, 4
72
- # subject.path.should_not be_blank
73
- # subject.path.size.should == 7
74
- # subject.path[3].physical_road.objectid.should == "bc"
75
- # subject.path[4].physical_road.objectid.should == "cd"
76
- # end
39
+ describe "#path" do
40
+ include_context "shared simple graph"
41
+
42
+ it "should find a solution between first and last road with with no constraints" do
43
+ path = ActiveRoad::ShortestPath::Finder.new(departure, arrival, 4).path
44
+ expect(path.size).to eq(8)
45
+ expect(path[0]).to eq(departure)
46
+ expect(path[1].class).to eq(ActiveRoad::AccessLink)
47
+ expect(path[2].physical_road.objectid).to eq("ab")
48
+ expect(path[3].physical_road.objectid).to eq("ac")
49
+ expect(path[4].physical_road.objectid).to eq("cf")
50
+ expect(path[5].physical_road.objectid).to eq("df")
51
+ expect(path[6].class).to eq(ActiveRoad::AccessLink)
52
+ expect(path[7]).to eq(arrival)
53
+ end
54
+
55
+ it "should find a solution between first and last road with constraints" do
56
+ cf_conditionnal_costs = create(:physical_road_conditionnal_cost, :physical_road => cf, :tags => "bike", :cost => 0.7)
57
+ path = ActiveRoad::ShortestPath::Finder.new(departure, arrival, 4, ["bike"]).path
58
+ expect(path.size).to eq(8)
59
+ expect(path[0]).to eq(departure)
60
+ expect(path[1].class).to eq(ActiveRoad::AccessLink)
61
+ expect(path[2].physical_road.objectid).to eq("ab")
62
+ expect(path[3].physical_road.objectid).to eq("ac")
63
+ expect(path[4].physical_road.objectid).to eq("cd")
64
+ expect(path[5].physical_road.objectid).to eq("df")
65
+ expect(path[6].class).to eq(ActiveRoad::AccessLink)
66
+ expect(path[7]).to eq(arrival)
67
+ end
68
+
69
+ it "should find a solution between first and last road with constraints which block the itinerary" do
70
+ cf_conditionnal_costs = create(:physical_road_conditionnal_cost, :physical_road => cf, :tags => "bike", :cost => 0)
71
+ path = ActiveRoad::ShortestPath::Finder.new(departure, arrival, 4, ["~bike"]).path
72
+ expect(path.size).to eq(8)
73
+ expect(path[0]).to eq(departure)
74
+ expect(path[1].class).to eq(ActiveRoad::AccessLink)
75
+ expect(path[2].physical_road.objectid).to eq("ab")
76
+ expect(path[3].physical_road.objectid).to eq("ac")
77
+ expect(path[4].physical_road.objectid).to eq("cd")
78
+ expect(path[5].physical_road.objectid).to eq("df")
79
+ expect(path[6].class).to eq(ActiveRoad::AccessLink)
80
+ expect(path[7]).to eq(arrival)
81
+ end
77
82
 
78
- # end
83
+ it "should return something when no solution" do
84
+ departure = point(-0.01, 0.01)
85
+ path = ActiveRoad::ShortestPath::Finder.new(departure, arrival, 4).path
86
+ expect(path).to eq([])
87
+ end
79
88
 
89
+ it "should return something when departure or arrival are 'outside the graph'" do
90
+ departure = point(-0.0005, -0.0005)
91
+ path = ActiveRoad::ShortestPath::Finder.new(departure, arrival, 4).path
92
+ expect(path.size).to eq(8)
93
+ expect(path[0]).to eq(departure)
94
+ expect(path[1].class).to eq(ActiveRoad::AccessLink)
95
+ expect(path[2].physical_road.objectid).to eq("ab")
96
+ expect(path[3].physical_road.objectid).to eq("ac")
97
+ expect(path[4].physical_road.objectid).to eq("cf")
98
+ expect(path[6].class).to eq(ActiveRoad::AccessLink)
99
+ expect(path[7]).to eq(arrival)
100
+ end
101
+
102
+ end
80
103
 
81
104
  describe "#path_weights" do
82
105
 
83
- let(:subject) { ActiveRoad::ShortestPath::Finder.new departure, arrival, 4 }
106
+ let(:subject) { ActiveRoad::ShortestPath::Finder.new departure, arrival, 4, ["test"] }
84
107
 
85
108
  it "should return 0 if no physical road" do
86
109
  path = departure
87
- subject.path_weights(path).should == 0
110
+ expect(subject.path_weights(path)).to eq(0)
88
111
  end
89
112
 
90
- it "should return path weights" do
113
+ it "should return path weight if physical road" do
91
114
  path = ActiveRoad::Path.new(:departure => create(:junction), :physical_road => create(:physical_road) )
92
- path.stub :length_in_meter => 2
93
- subject.path_weights(path).should == 2 / (4 * 1000/3600)
115
+ allow(path).to receive_messages :length_in_meter => 2
116
+ expect(subject.path_weights(path)).to eq(2 / (4 * 1000/3600))
94
117
  end
95
118
 
96
- it "should return path weights and node weight" do
119
+ it "should return path weights and node weight if nodes have weight" do
97
120
  path = ActiveRoad::Path.new(:departure => create(:junction, :waiting_constraint => 2.5), :physical_road => create(:physical_road) )
98
- path.stub :length_in_meter => 2
99
- subject.path_weights(path).should == 2 / (4 * 1000/3600) + 2.5
121
+ allow(path).to receive_messages :length_in_meter => 2
122
+ expect(subject.path_weights(path)).to eq(2 / (4 * 1000/3600) + 2.5)
123
+ end
124
+
125
+ it "should return path weights and physical roads weight if physical roads have weight" do
126
+ physical_road = create(:physical_road)
127
+ physical_road_conditionnal_cost = create(:physical_road_conditionnal_cost, :physical_road => physical_road, :tags => "test", :cost => 0.2)
128
+ path = ActiveRoad::Path.new(:departure => create(:junction), :physical_road => physical_road )
129
+ allow(path).to receive_messages :length_in_meter => 2
130
+ expect(subject.path_weights(path)).to eq(2 / (4 * 1000/3600) + (2 / (4 * 1000/3600)) * 0.2)
131
+ end
132
+
133
+ it "should return path weights == Infinity and physical roads weight if physical roads have weight" do
134
+ physical_road = create(:physical_road)
135
+ physical_road_conditionnal_cost = create(:physical_road_conditionnal_cost, :physical_road => physical_road, :tags => "test", :cost => Float::MAX)
136
+ path = ActiveRoad::Path.new(:departure => create(:junction), :physical_road => physical_road )
137
+ allow(path).to receive_messages :length_in_meter => 2
138
+ expect(subject.path_weights(path)).to eq(Float::INFINITY)
100
139
  end
101
140
 
102
141
  end
@@ -107,51 +146,65 @@ describe ActiveRoad::ShortestPath::Finder do
107
146
  it "should increase uphill if path has got a departure with an uphill value" do
108
147
  node = ActiveRoad::Path.new( :physical_road => create(:physical_road, :uphill => 3.0), :departure => create(:junction))
109
148
  context = {:uphill => 3}
110
- subject.refresh_context(node, context).should == { :uphill => 6.0, :downhill => 0, :height => 0}
149
+ expect(subject.refresh_context(node, context)).to eq({ :uphill => 6.0, :downhill => 0, :height => 0})
111
150
  end
112
151
 
113
152
  it "should not increase uphill if path hasn't' got a departure with an uphill value" do
114
153
  node = ActiveRoad::Path.new( :physical_road => create(:physical_road), :departure => create(:junction))
115
154
  context = {:uphill => 3}
116
- subject.refresh_context(node, context).should == { :uphill => 3.0, :downhill => 0, :height => 0}
155
+ expect(subject.refresh_context(node, context)).to eq({ :uphill => 3.0, :downhill => 0, :height => 0})
117
156
  end
118
157
 
119
158
  it "should set context uphill to 0 if path hasn't' got a departure with an uphill value and no previous context" do
120
159
  node = ActiveRoad::Path.new( :physical_road => create(:physical_road), :departure => create(:junction))
121
160
  context = {}
122
- subject.refresh_context(node, context).should == { :uphill => 0, :downhill => 0, :height => 0}
161
+ expect(subject.refresh_context(node, context)).to eq({ :uphill => 0, :downhill => 0, :height => 0})
123
162
  end
124
163
 
125
164
  it "should return {} if node is not a ActiveRoad::Path" do
126
165
  node = GeoRuby::SimpleFeatures::Point.from_x_y(0, 0)
127
166
  context = {}
128
- subject.refresh_context(node, context).should == {:uphill=>0, :downhill=>0, :height=>0}
167
+ expect(subject.refresh_context(node, context)).to eq({:uphill=>0, :downhill=>0, :height=>0})
129
168
  end
130
169
  end
131
170
 
132
171
  describe "#follow_way" do
133
172
 
134
- let(:node) { mock(:node) }
135
- let(:destination) { mock(:destination) }
136
- let(:weight) { 2 }
173
+ let(:node) { double(:node) }
174
+ let(:destination) { double(:destination) }
137
175
  let(:context) { {:uphill => 2} }
138
- let(:subject) { ActiveRoad::ShortestPath::Finder.new departure, arrival, 4 }
176
+ let(:subject) { ActiveRoad::ShortestPath::Finder.new departure, arrival, 4, [], {:uphill => 2} }
139
177
 
140
178
  before(:each) do
141
- subject.stub :search_heuristic => 1
142
- subject.stub :time_heuristic => 2
179
+ allow(subject).to receive_messages :search_heuristic => 1
180
+ allow(subject).to receive_messages :time_heuristic => 2
143
181
  end
144
182
 
183
+ it "should not follow way if weight == Infinity" do
184
+ expect(subject.follow_way?(node, destination, Float::INFINITY)).to be_falsey
185
+ end
186
+
145
187
  it "should not follow way if uphill > uphill max" do
146
188
  subject.follow_way_filter = {:uphill => 1}
147
- subject.follow_way?(node, destination, weight, context).should be_false
189
+ expect(subject.follow_way?(node, destination, 2, context)).to be_falsey
148
190
  end
149
191
 
150
192
  it "should follow way if uphill < uphill max" do
151
193
  subject.follow_way_filter = {:uphill => 3}
152
- subject.follow_way?(node, destination, weight, context).should be_true
194
+ expect(subject.follow_way?(node, destination, 2, context)).to be_truthy
153
195
  end
154
196
 
155
197
  end
198
+
199
+ describe "#geometry" do
200
+ include_context "shared simple graph"
201
+
202
+ let(:shortest_path) { ActiveRoad::ShortestPath::Finder.new(departure, arrival, 4) }
203
+
204
+ it "should return geometry" do
205
+ expect(shortest_path.geometry).not_to eq(nil)
206
+ end
207
+ end
156
208
 
157
209
  end
210
+
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ #####################################
4
+ # More complex path schema #
5
+ #####################################
6
+ describe "performance finder test" do
7
+ let!(:from) { point(-0.0009, -0.0009) }
8
+ let!(:to) { point(0.3009, 0.3009) }
9
+ let(:subject) { ActiveRoad::ShortestPath::Finder.new from, to, 4, [] }
10
+ let(:graph_size) { 0.3 }
11
+ let(:increment_coordinates) { 0.01 }
12
+ let(:round_coordinates) { 2 }
13
+ let(:graph_size_by_unit) { graph_size / increment_coordinates}
14
+
15
+ before(:each) do
16
+ x = y = 0.0
17
+ while y <= graph_size
18
+ departure = create(:junction, :objectid => "#{x},#{y}", :geometry => point(x, y) )
19
+
20
+ if y > 0
21
+ previous_departure = ActiveRoad::Junction.find_by_objectid("#{x},#{(y - increment_coordinates).round(round_coordinates)}")
22
+ create(:physical_road, :objectid => "#{x},#{(y - increment_coordinates).round(round_coordinates)}-#{x},#{y}", :geometry => line_string( previous_departure.geometry, departure.geometry ), :junctions => [previous_departure, departure] )
23
+ end
24
+
25
+ while x < graph_size
26
+ x = (x + increment_coordinates).round(round_coordinates)
27
+ arrival = create(:junction, :objectid => "#{x},#{y}", :geometry => point(x, y) )
28
+ create(:physical_road, :objectid => "#{(x - increment_coordinates).round(round_coordinates)},#{y}-#{x},#{y}", :geometry => line_string( departure.geometry, arrival.geometry ), :junctions => [departure, arrival] )
29
+
30
+ # Link to previous junctions
31
+ if y > 0
32
+ previous_arrival = ActiveRoad::Junction.find_by_objectid("#{x},#{(y - increment_coordinates).round(round_coordinates)}")
33
+ create(:physical_road, :objectid => "#{x},#{(y - increment_coordinates).round(round_coordinates)}-#{x},#{y}", :geometry => line_string( previous_arrival.geometry, arrival.geometry ), :junctions => [departure, arrival] )
34
+ end
35
+
36
+ # Change the departure in arrival
37
+ departure = arrival
38
+ end
39
+
40
+ x = 0.0
41
+ y = (y + increment_coordinates).round(round_coordinates)
42
+ end
43
+ end
44
+
45
+ # it "should create correct number of objects", :profile => true do
46
+ # ActiveRoad::Junction.all.size.should == (graph_size_by_unit + 1 ) * (graph_size_by_unit + 1)
47
+ # ActiveRoad::PhysicalRoad.all.size.should == graph_size_by_unit * ( 2 * graph_size_by_unit + 2)
48
+ # end
49
+
50
+ # Test to read nodes in picardie.osm.pbf data in less 34.910999522 seconds
51
+ # Test to read nodes and create objects in picardie.osm.pbf data in less 190.617743468 seconds
52
+ # Test to write nodes in picardie.osm.pbf data in less seconds
53
+
54
+ it "should evaluate path and profile it", :profile => true do
55
+ puts subject.path.inspect
56
+ #subject.path.count.should == graph_size_by_unit * 2 + 4
57
+ end
58
+
59
+ end
@@ -1,20 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ActiveRoad::AccessPoint do
4
- let!(:ab) { create(:physical_road, :geometry => line_string( "0 0,1 0" ), :minimum_width => :wide ) }
5
-
6
- subject { ActiveRoad::Accesspoint.new( :location => point(0, 0), :physical_road => ab ) }
3
+ describe ActiveRoad::AccessPoint, :type => :model do
4
+ let!(:origin) { point(0, 0) }
5
+ let!(:pr1) { create(:physical_road, :geometry => line_string( "0 0,1 1" )) }
6
+ let!(:pr2) { create(:physical_road, :geometry => line_string( "0.002 0.002,1 1" )) }
7
+ let!(:pr3) { create(:physical_road, :geometry => line_string( "2 2,3 3" )) }
8
+
9
+ #subject { ActiveRoad::Accesspoint.new( :location => point(0, 0), :physical_road => ab ) }
7
10
 
8
11
  describe ".from" do
9
12
 
10
13
  it "should return all access point with tags from the location" do
11
- access_points = ActiveRoad::AccessPoint.from( point(0, 0), { :minimum_width => :wide } )
12
- access_points.size.should == 1
13
- end
14
-
15
- it "should return all access point from the location with tags not in physical roads" do
16
- access_points = ActiveRoad::AccessPoint.from( point(0, 0), { :minimum_width => :narrow } )
17
- access_points.size.should == 0
14
+ expect( ActiveRoad::AccessPoint.from( origin ).size ).to eq(1)
18
15
  end
19
16
 
20
17
  end
@@ -22,13 +19,7 @@ describe ActiveRoad::AccessPoint do
22
19
  describe ".to" do
23
20
 
24
21
  it "should return all access point with tags from the location" do
25
- access_points = ActiveRoad::AccessPoint.to( point(0, 0), { :minimum_width => :wide } )
26
- access_points.size.should == 1
27
- end
28
-
29
- it "should return all access point from the location with tags not in physical roads" do
30
- access_points = ActiveRoad::AccessPoint.to( point(0, 0), { :minimum_width => :narrow } )
31
- access_points.size.should == 0
22
+ expect( ActiveRoad::AccessPoint.from( origin ).size ).to eq(1)
32
23
  end
33
24
 
34
25
  end
@@ -1,19 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ActiveRoad::JunctionConditionnalCost do
3
+ describe ActiveRoad::JunctionConditionnalCost, :type => :model do
4
4
 
5
5
  subject { create(:junction_conditionnal_cost) }
6
6
 
7
7
  it "should have tags" do
8
- subject.should respond_to(:tags)
8
+ expect(subject).to respond_to(:tags)
9
9
  end
10
10
 
11
11
  it "should have a cost" do
12
- subject.should respond_to(:cost)
12
+ expect(subject).to respond_to(:cost)
13
13
  end
14
14
 
15
15
  it "should have a junction" do
16
- subject.should respond_to(:junction_id)
16
+ expect(subject).to respond_to(:junction_id)
17
17
  end
18
18
 
19
19
  describe "#start_physical_road" do
@@ -1,25 +1,48 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ActiveRoad::Junction do
4
-
5
- subject { create(:junction) }
3
+ describe ActiveRoad::Junction, :type => :model do
6
4
 
5
+ subject { create(:junction_with_physical_roads) }
6
+
7
7
  it "should validate objectid uniqueness" do
8
8
  other = build :junction, :objectid => subject.objectid
9
- other.should_not be_valid
9
+ expect(other).not_to be_valid
10
10
  end
11
11
 
12
- context "junction connected to physical roads" do
13
- subject { create(:junction) }
12
+ describe "#location_on_road" do
13
+ it "should" do
14
+ # TODO Understand the result
15
+ expect(subject.location_on_road(subject.physical_roads.first)).to eq(25.577598616424485)
16
+ end
17
+ end
14
18
 
15
- describe "#physical_roads" do
16
- let(:new_road) { create(:physical_road) }
17
- it "should be addable" do
18
- subject.physical_roads << new_road
19
- subject.save!
19
+ describe "#paths" do
20
+ it "should return paths from junction" do
21
+ subject.physical_roads.each do |physical_road|
22
+ physical_road.junctions << create(:junction)
20
23
  end
24
+ expect(subject.paths.size).to eq(2)
25
+ expect(subject.paths.collect(&:physical_road).flatten).to match_array(subject.physical_roads)
26
+ end
27
+ end
28
+
29
+ describe "#access_on_road" do
30
+ it "should return if junction access to road or not" do
31
+ expect(subject.access_to_road?(subject.physical_roads.first)).to be_truthy
32
+ expect(subject.access_to_road?(create(:physical_road))).to be_falsey
21
33
  end
22
34
  end
23
35
 
36
+ describe "#to_s" do
37
+ it "should return junction description" do
38
+ expect(subject.to_s).to eq("Junction @#{subject.geometry.lng},#{subject.geometry.lat}")
39
+ end
40
+ end
41
+
42
+ describe "#name" do
43
+ it "should return junction name" do
44
+ expect(subject.name).to eq(subject.physical_roads.join(" - "))
45
+ end
46
+ end
24
47
 
25
48
  end