From 093b6c0217e593943df2598c1e5f0afd8ef116c0 Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Tue, 27 Dec 2011 12:54:52 +0100 Subject: [PATCH] adding test for turn restrictions --- features/bicycle.feature | 22 +++++++++++++ features/restrictions.feature | 49 ++++++++++++++++++++++++++++ features/routing.feature | 18 +--------- features/step_definitions/routing.rb | 49 +++++++++++++++++++++++----- test/speedprofiles/bicycle.ini | 2 +- 5 files changed, 113 insertions(+), 27 deletions(-) create mode 100644 features/bicycle.feature create mode 100644 features/restrictions.feature diff --git a/features/bicycle.feature b/features/bicycle.feature new file mode 100644 index 000000000..4dd4b2c3a --- /dev/null +++ b/features/bicycle.feature @@ -0,0 +1,22 @@ +@routing @bicycle +Feature: Bicycle Routing from A to B + To enable bicycle routing + OSRM should handle all relevant bicycle tags + + Scenario: Respect oneway without additional tags + + Scenario: oneway:bicycle + When I request a route from 55.673168935147,12.563557740441 to 55.67380116846,12.563107129324& + Then I should get a route + And the route should follow "Banegårdspladsen" + And there should not be any turns + And the distance should be close to 70m + + Scenario: cycleway=opposite_lane + When I request a route from 55.689236488,12.55317804955 to 55.688510764046,12.552909828648 + Then I should get a route + And the route should follow "Kapelvej" + And there should not be any turns + And the distance should be close to 80m + + diff --git a/features/restrictions.feature b/features/restrictions.feature new file mode 100644 index 000000000..b0e4742a6 --- /dev/null +++ b/features/restrictions.feature @@ -0,0 +1,49 @@ +@routing @restrictions +Feature: Turn restrictions + OSRM should handle turn restrictions + +Scenario: No left turn when crossing a oneway street + When I request a route from 55.689741159238,12.574720202639 to 55.689741159232,12.57455927015 + Then I should get a route + And the route should start at "Sølvgade" + And the route should end at "Øster Farimagsgade" + And the route should not include "Sølvgade, Øster Farimagsgade" + And no error should be reported in terminal + +Scenario: No left turn at T-junction: Don't turn left from side road into main road + When I request a route from 55.66442995717,12.549384056343 to 55.664060815164,12.548944174065 + Then I should get a route + And the route should start at "Sigerstedgade" + And the route should end at "Ingerslevsgade" + And there should be more than 1 turn + And the route should not include "Sigerstedgade, Ingerslevsgade" + +Scenario: No left turn at T-junction: OK to turn right from side road into main road + When I request a route from 55.66442995717,12.549384056343 to 55.664218154805,12.5502638209 + Then I should get a route + And the route should start at "Sigerstedgade" + And the route should end at "Ingerslevsgade" + And there should be 1 turn + And the route should include "Sigerstedgade, Ingerslevsgade" + +Scenario: No left turn at T-junction: OK to go straight on main road + When I request a route from 55.66419092299,12.550333558335 to 55.664060815164,12.548944174065 + Then I should get a route + And the route should stay on "Ingerslevsgade" + +Scenario: No left turn at T-junction: OK to turn right from main road into side road + When I request a route from 55.664060815164,12.548944174065 to 55.66442995717,12.549384056343 + Then I should get a route + And the route should start at "Ingerslevsgade" + And the route should end at "Sigerstedgade" + And there should be 1 turn + And the route should include "Ingerslevsgade, Sigerstedgade" + +Scenario: No left turn at T-junction: OK to turn left from main road into side road + When I request a route from 55.664218154805,12.5502638209 to 55.66442995717,12.549384056343 + Then I should get a route + And the route should start at "Ingerslevsgade" + And the route should end at "Sigerstedgade" + And there should be 1 turn + And the route should include "Ingerslevsgade, Sigerstedgade" + diff --git a/features/routing.feature b/features/routing.feature index c9fdc1857..0179bc7dd 100644 --- a/features/routing.feature +++ b/features/routing.feature @@ -15,27 +15,11 @@ Feature: Routing from A to B And the route should stay on "Islands Brygge" And the distance should be close to 200m - Scenario: Crossing round-about at Amalienborg + Scenario: Crossing roundabout at Amalienborg When I request a route from 55.683797649183,12.593940686704 to 55.6842149924,12.592476200581 Then I should get a route And the distance should be close to 150m - @bicycle - Scenario: Handle cycleway=opposite_lane - When I request a route from 55.689236488,12.55317804955 to 55.688510764046,12.552909828648 - Then I should get a route - And the route should follow "Kapelvej" - And there should not be any turns - And the distance should be close to 80m - - @bicycle - Scenario: Handle oneway:bicycle - When I request a route from 55.673168935147,12.563557740441 to 55.67380116846,12.563107129324& - Then I should get a route - And the route should follow "Banegårdspladsen" - And there should not be any turns - And the distance should be close to 70m - Scenario: Requesting invalid routes When I request a route from 0,0 to 0,0 Then I should not get a route diff --git a/features/step_definitions/routing.rb b/features/step_definitions/routing.rb index 16e832a20..4cf22c07c 100644 --- a/features/step_definitions/routing.rb +++ b/features/step_definitions/routing.rb @@ -67,11 +67,11 @@ Then /^I should not get a route$/ do step "no route should be found" end -Then /^starting point should be "([^']*)"$/ do |name| +Then /^the route should start at "([^']*)"$/ do |name| @json['route_summary']['start_point'].should == name end -Then /^end point should be "([^']*)"$/ do |name| +Then /^the route should end at "([^']*)"$/ do |name| @json['route_summary']['end_point'].should == name end @@ -89,19 +89,50 @@ Then /^number of instructions should be (\d+)$/ do |n| @json['route_instructions'].size.should == n end +Then /^there should be 1 turn$/ do + step 'there should be 1 turns' +end + +Then /^there should be (\d+) turns$/ do |n| + @json['route_instructions'].map {|t| t.first}.select {|t| t =~ /^Turn/ }.size.should == n.to_i +end + +Then /^there should be more than (\d+) turn$/ do |n| + @json['route_instructions'].map {|t| t.first}.select {|t| t =~ /^Turn/ }.size.should > n.to_i +end + Then /^there should not be any turns$/ do (@json['route_instructions'].size-1).should == 0 end +def sanitize_route route + route.split(',').map{|w| w.strip}.reject(&:empty?).join(', ') +end + +def computed_route + @json['route_instructions'].map { |r| r[1] }.reject(&:empty?).join(', ') +end + Then /^the route should follow "([^"]*)"$/ do |route| - route = route.split(',').map{|w| w.strip}.reject(&:empty?).join(', ') - @json['route_instructions'].map { |r| r[1].strip }.reject(&:empty?).join(', ').should == route + sanitize_route(route).should == computed_route end -Then /^the route should stay on "([^"]*)"$/ do |route| - step 'starting point should be "Islands Brygge"' - step 'end point should be "Islands Brygge"' - step 'the route should follow "Islands Brygge"' - step 'there should not be any turns' +Then /^the route should not follow "([^"]*)"$/ do |route| + sanitize_route(route).should_not == computed_route +end + +Then /^the route should include "([^"]*)"$/ do |route| + sanitize_route(route).should =~ /#{computed_route}/ +end + +Then /^the route should not include "([^"]*)"$/ do |route| + sanitize_route(route).should_not =~ /#{computed_route}/ +end + +Then /^the route should stay on "([^"]*)"$/ do |way| + step "the route should start at \"#{way}\"" + step "the route should end at \"#{way}\"" + step "the route should follow \"#{way}\"" + step "there should not be any turns" end diff --git a/test/speedprofiles/bicycle.ini b/test/speedprofiles/bicycle.ini index bd570c051..adbadfecb 100644 --- a/test/speedprofiles/bicycle.ini +++ b/test/speedprofiles/bicycle.ini @@ -17,7 +17,7 @@ pier = 5 steps = 3 obeyOneways = yes - useRestrictions = no + useRestrictions = yes accessTag = bicycle excludeFromGrid = ferry defaultSpeed = 15