Skip to content

Commit

Permalink
cuke: test travel time of individual instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
emiltin committed Apr 2, 2014
1 parent 165c252 commit df83dfd
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 55 deletions.
8 changes: 8 additions & 0 deletions features/step_definitions/routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
compasses = compass_list json['route_instructions']
turns = turn_list json['route_instructions']
modes = mode_list json['route_instructions']
times = time_list json['route_instructions']
distances = distance_list json['route_instructions']
end
end

Expand Down Expand Up @@ -90,6 +92,12 @@
if table.headers.include? 'modes'
got['modes'] = modes
end
if table.headers.include? 'times'
got['times'] = times
end
if table.headers.include? 'distances'
got['distances'] = distances
end
if table.headers.include? '#' # comment column
got['#'] = row['#'] # copy value so it always match
end
Expand Down
35 changes: 19 additions & 16 deletions features/support/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,23 @@ def route_status response
end
end

def way_list instructions
def extract_instruction_list instructions, index, postfix=nil
instructions.reject { |r| r[0].to_s=="#{DESTINATION_REACHED}" }.
map { |r| r[1] }.
map { |r| r=="" ? '""' : r }.
map { |r| r[index] }.
map { |r| (r=="" || r==nil) ? '""' : "#{r}#{postfix}" }.
join(',')
end

def way_list instructions
extract_instruction_list instructions, 1
end

def compass_list instructions
instructions.reject { |r| r[0].to_s=="#{DESTINATION_REACHED}" }.
map { |r| r[6] }.
map { |r| r=="" ? '""' : r }.
join(',')
extract_instruction_list instructions, 6
end

def bearing_list instructions
instructions.reject { |r| r[0].to_s=="#{DESTINATION_REACHED}" }.
map { |r| r[7] }.
map { |r| r=="" ? '""' : r }.
join(',')
extract_instruction_list instructions, 7
end

def turn_list instructions
Expand All @@ -125,15 +123,20 @@ def turn_list instructions
# replace instructions codes with strings
# "11-3" (enter roundabout and leave a 3rd exit) gets converted to "enter_roundabout-3"
instructions.map do |r|
r[0].to_s.gsub!(/^\d*/) do |match|
r[0].to_s.gsub(/^\d*/) do |match|
types[match.to_i].to_s
end
end.join(',')
end

def mode_list instructions
instructions.reject { |r| r[0].to_s=="#{DESTINATION_REACHED}" }.
map { |r| r[8] }.
map { |r| (r=="" || r==nil) ? '""' : r }.
join(',')
extract_instruction_list instructions, 8
end

def time_list instructions
extract_instruction_list instructions, 4, "s"
end

def distance_list instructions
extract_instruction_list instructions, 2, "m"
end
101 changes: 62 additions & 39 deletions features/testbot/time.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ Feature: Estimation of travel time
| f | e | d |

And the ways
| nodes | highway |
| xa | primary |
| xb | primary |
| xc | primary |
| xd | primary |
| xe | primary |
| xf | primary |
| xg | primary |
| xh | primary |
| nodes | highway |
| xa | primary |
| xb | primary |
| xc | primary |
| xd | primary |
| xe | primary |
| xf | primary |
| xg | primary |
| xh | primary |

When I route I should get
| from | to | route | time |
Expand All @@ -45,15 +45,15 @@ Feature: Estimation of travel time
| f | e | d |

And the ways
| nodes | highway |
| xa | primary |
| xb | primary |
| xc | primary |
| xd | primary |
| xe | primary |
| xf | primary |
| xg | primary |
| xh | primary |
| nodes | highway |
| xa | primary |
| xb | primary |
| xc | primary |
| xd | primary |
| xe | primary |
| xf | primary |
| xg | primary |
| xh | primary |

When I route I should get
| from | to | route | time |
Expand All @@ -74,15 +74,15 @@ Feature: Estimation of travel time
| f | e | d |

And the ways
| nodes | highway |
| xa | primary |
| xb | primary |
| xc | primary |
| xd | primary |
| xe | primary |
| xf | primary |
| xg | primary |
| xh | primary |
| nodes | highway |
| xa | primary |
| xb | primary |
| xc | primary |
| xd | primary |
| xe | primary |
| xf | primary |
| xg | primary |
| xh | primary |

When I route I should get
| from | to | route | time |
Expand All @@ -103,15 +103,15 @@ Feature: Estimation of travel time
| f | e | d |

And the ways
| nodes | highway |
| xa | primary |
| xb | primary |
| xc | primary |
| xd | primary |
| xe | primary |
| xf | primary |
| xg | primary |
| xh | primary |
| nodes | highway |
| xa | primary |
| xb | primary |
| xc | primary |
| xd | primary |
| xe | primary |
| xf | primary |
| xg | primary |
| xh | primary |

When I route I should get
| from | to | route | time |
Expand Down Expand Up @@ -183,9 +183,9 @@ Feature: Estimation of travel time
| | | e |

And the ways
| nodes | highway |
| abc | primary |
| cde | tertiary |
| nodes | highway |
| abc | primary |
| cde | tertiary |

When I route I should get
| from | to | route | time |
Expand Down Expand Up @@ -213,3 +213,26 @@ Feature: Estimation of travel time
| 4 | 3 | ab | 10s +-1 |
| 4 | 2 | ab | 20s +-1 |
| 4 | 1 | ab | 30s +-1 |

@bug
Scenario: Total travel time should match sum of times of individual ways
Given a grid size of 1000 meters
And the node map
| a | b | | | |
| | | | | |
| | c | | | d |

And the ways
| nodes | highway |
| ab | primary |
| bc | primary |
| cd | primary |

When I route I should get
| from | to | route | distances | distance | times | time |
| a | b | ab | 1000m +-1 | 1000m +-1 | 100s +-1 | 100s +-1 |
| b | c | bc | 2000m +-1 | 2000m +-1 | 200s +-1 | 200s +-1 |
| c | d | cd | 3000m +-1 | 3000m +-1 | 300s +-1 | 300s +-1 |
| a | c | ab,bc | 1000m,2000m +-1 | 3000m +-1 | 100s,200s +-1 | 300s +-1 |
| b | d | bc,cd | 2000m,3000m +-1 | 5000m +-1 | 200s,300s +-1 | 500s +-1 |
| a | d | ab,bc,cd | 1000m,2000m,3000m +-1 | 6000m +-1 | 100s,200s,300s +-1 | 600s +-1 |

0 comments on commit df83dfd

Please sign in to comment.