allow setting origin in cuke tests

This commit is contained in:
Emil Tin 2013-08-31 23:35:26 +02:00
parent caa02bbca1
commit 3cf72e93e6
4 changed files with 20 additions and 11 deletions

View File

@ -6,6 +6,10 @@ Given /^a grid size of (\d+) meters$/ do |meters|
set_grid_size meters set_grid_size meters
end end
Given /^the origin lat\/lon (\d+),(\d+)$/ do |lat,lon|
set_origin [lon.to_f,lat.to_f]
end
Given /^the shortcuts$/ do |table| Given /^the shortcuts$/ do |table|
table.hashes.each do |row| table.hashes.each do |row|
shortcuts_hash[ row['key'] ] = row['value'] shortcuts_hash[ row['key'] ] = row['value']

View File

@ -12,12 +12,12 @@ Then /^routability should be$/ do |table|
['forw','backw','bothw'].each do |direction| ['forw','backw','bothw'].each do |direction|
if table.headers.include? direction if table.headers.include? direction
if direction == 'forw' || direction == 'bothw' if direction == 'forw' || direction == 'bothw'
a = Location.new ORIGIN[0]+(1+WAY_SPACING*i)*@zoom, ORIGIN[1] a = Location.new @origin[0]+(1+WAY_SPACING*i)*@zoom, @origin[1]
b = Location.new ORIGIN[0]+(3+WAY_SPACING*i)*@zoom, ORIGIN[1] b = Location.new @origin[0]+(3+WAY_SPACING*i)*@zoom, @origin[1]
response = request_route [a,b] response = request_route [a,b]
elsif direction == 'backw' || direction == 'bothw' elsif direction == 'backw' || direction == 'bothw'
a = Location.new ORIGIN[0]+(3+WAY_SPACING*i)*@zoom, ORIGIN[1] a = Location.new @origin[0]+(3+WAY_SPACING*i)*@zoom, @origin[1]
b = Location.new ORIGIN[0]+(1+WAY_SPACING*i)*@zoom, ORIGIN[1] b = Location.new @origin[0]+(1+WAY_SPACING*i)*@zoom, @origin[1]
response = request_route [a,b] response = request_route [a,b]
end end
want = shortcuts_hash[row[direction]] || row[direction] #expand shortcuts want = shortcuts_hash[row[direction]] || row[direction] #expand shortcuts

View File

@ -16,7 +16,7 @@ DEFAULT_GRID_SIZE = 100 #meters
PROFILES_PATH = '../profiles' PROFILES_PATH = '../profiles'
BIN_PATH = '../build' BIN_PATH = '../build'
ORIGIN = [1,1] DEFAULT_ORIGIN = [1,1]
class Location class Location
attr_accessor :lon,:lat attr_accessor :lon,:lat
@ -38,6 +38,10 @@ def set_grid_size meters
@zoom = meters.to_f*0.8990679362704610899694577444566908445396483347536032203503E-5 @zoom = meters.to_f*0.8990679362704610899694577444566908445396483347536032203503E-5
end end
def set_origin origin
@origin = origin
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
table.hashes.each_with_index do |row,ri| table.hashes.each_with_index do |row,ri|
@ -49,11 +53,11 @@ 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]
node5 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, ORIGIN[0]+(4+WAY_SPACING*ri)*@zoom, ORIGIN[1] node5 = OSM::Node.new make_osm_id, OSM_USER, OSM_TIMESTAMP, @origin[0]+(4+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
@ -121,7 +125,7 @@ def build_ways_from_table table
end end
def table_coord_to_lonlat ci,ri def table_coord_to_lonlat ci,ri
[ORIGIN[0]+ci*@zoom, ORIGIN[1]-ri*@zoom] [@origin[0]+ci*@zoom, @origin[1]-ri*@zoom]
end end
def add_osm_node name,lon,lat def add_osm_node name,lon,lat

View File

@ -8,6 +8,7 @@ Before do |scenario|
@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 set_grid_size DEFAULT_GRID_SIZE
set_origin DEFAULT_ORIGIN
end end
Around('@stress') do |scenario, block| Around('@stress') do |scenario, block|