allow setting the grid space in tests

This commit is contained in:
Emil Tin 2012-02-18 15:19:11 +01:00
parent 091cd57f68
commit 887092bacd
3 changed files with 15 additions and 7 deletions

View File

@ -8,6 +8,10 @@ Given /^the speedprofile settings$/ do |table|
end end
end end
Given /^a grid size of (\d+) meters$/ do |meters|
set_grid_size meters
end
Given /^the nodes$/ do |table| Given /^the nodes$/ do |table|
table.raw.each_with_index do |row,ri| table.raw.each_with_index do |row,ri|
row.each_with_index do |name,ci| row.each_with_index do |name,ci|
@ -15,7 +19,7 @@ Given /^the nodes$/ do |table|
raise "*** node invalid name '#{name}', must be single characters" unless name.size == 1 raise "*** node invalid name '#{name}', must be single characters" unless name.size == 1
raise "*** invalid node name '#{name}', must me alphanumeric" unless name.match /[a-z0-9]/ raise "*** invalid node name '#{name}', must me alphanumeric" unless name.match /[a-z0-9]/
raise "*** duplicate node '#{name}'" if name_node_hash[name] raise "*** duplicate node '#{name}'" if name_node_hash[name]
node = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+ci*ZOOM, ORIGIN[1]-ri*ZOOM node = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+ci*@zoom, ORIGIN[1]-ri*@zoom
node << { :name => name } node << { :name => name }
node.uid = OSM_UID node.uid = OSM_UID
osm_db << node osm_db << node

View File

@ -12,10 +12,13 @@ LOG_FILE = 'fail.log'
OSM_TIMESTAMP = '2000-00-00T00:00:00Z' OSM_TIMESTAMP = '2000-00-00T00:00:00Z'
DEFAULT_SPEEDPROFILE = 'bicycle' DEFAULT_SPEEDPROFILE = 'bicycle'
WAY_SPACING = 10 WAY_SPACING = 10
DEFAULT_GRID_SIZE = 100 #meters
ORIGIN = [1,1] ORIGIN = [1,1]
NODE_SPACING = 100 #meters
ZOOM = 0.001*(NODE_SPACING.to_f/111.0) def set_grid_size meters
@zoom = 0.001*(meters.to_f/111.21)
end
def build_ways_from_table table def build_ways_from_table table
#add one unconnected way for each row #add one unconnected way for each row
@ -28,10 +31,10 @@ def build_ways_from_table table
#instead we place all lines as a string on the same y coordinate. this prevents using neightboring ways. #instead we place all lines as a string on the same y coordinate. this prevents using neightboring ways.
#a few nodes... #a few nodes...
node1 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(0+WAY_SPACING*ri)*ZOOM, ORIGIN[1] node1 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(0+WAY_SPACING*ri)*@zoom, ORIGIN[1]
node2 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(1+WAY_SPACING*ri)*ZOOM, ORIGIN[1] node2 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(1+WAY_SPACING*ri)*@zoom, ORIGIN[1]
node3 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(2+WAY_SPACING*ri)*ZOOM, ORIGIN[1] node3 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(2+WAY_SPACING*ri)*@zoom, ORIGIN[1]
node4 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(3+WAY_SPACING*ri)*ZOOM, ORIGIN[1] node4 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(3+WAY_SPACING*ri)*@zoom, ORIGIN[1]
node1.uid = OSM_UID node1.uid = OSM_UID
node2.uid = OSM_UID node2.uid = OSM_UID
node3.uid = OSM_UID node3.uid = OSM_UID

View File

@ -4,6 +4,7 @@ Before do |scenario|
reset_data reset_data
@has_logged_preprocess_info = false @has_logged_preprocess_info = false
@has_logged_scenario_info = false @has_logged_scenario_info = false
set_grid_size DEFAULT_GRID_SIZE
end end
Around('@routing') do |scenario, block| Around('@routing') do |scenario, block|