Skip to content

Commit

Permalink
failing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kajari authored and ghoshkaj committed Jan 25, 2017
1 parent b91597c commit 3e35441
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 7 deletions.
11 changes: 11 additions & 0 deletions features/step_definitions/trip.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ module.exports = function () {
json = JSON.parse(res.body);
}

console.log(json);

if (headers.has('status')) {
got.status = json.status.toString();
}
Expand All @@ -52,6 +54,15 @@ module.exports = function () {
}
}

if (headers.has('source') && headers.has('destination')) {
if (this.queryParams['source']) {
got.source = json.trips[0].source;
}
if (this.queryParams['destination']) {
got.source = json.trips[0].destination;
}
}

if (headers.has('#')) {
// comment column
got['#'] = row['#'];
Expand Down
23 changes: 17 additions & 6 deletions features/testbot/trip.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Feature: Basic trip planning
| a,b,c,d | abcda | 7.6 |
| d,b,c,a | dbcad | 7.6 |


Scenario: Testbot - Trip planning with more than 10 nodes
Given the node map
"""
Expand All @@ -48,14 +49,16 @@ Feature: Basic trip planning
| kl |
| la |


When I plan a trip I should get
| waypoints | trips |
| a,b,c,d,e,f,g,h,i,j,k,l | cbalkjihgfedc |


Scenario: Testbot - Trip planning with less than 10 nodes with fixed start and end
Given the query parameters
Given the query options
| source | 1 |
| destination | 4 |

Given the node map
"""
a b
Expand All @@ -71,11 +74,15 @@ Feature: Basic trip planning

When I plan a trip I should get
| waypoints | trips | durations |
| a,b,c,d | abcd | 7.6 |
| d,b,c,a | dbca | 7.6 |
| a,b,c,d | abcda | 7.6 |
| d,b,c,a | dbcaa | 7.6 |


Scenario: Testbot - Trip planning with more than 10 nodes with fixed start and end
Given the query options
| source | 1 |
| destination | 12 |

Given the node map
"""
a b c d
Expand All @@ -101,8 +108,9 @@ Feature: Basic trip planning


When I plan a trip I should get
| waypoints | trips |
| a,b,c,d,e,f,g,h,i,j,k,l | cbalkjihgfed |
| waypoints | trips |
| a,b,c,d,e,f,g,h,i,j,k,l | cbalkjihgfedc |


Scenario: Testbot - Trip planning with multiple scc
Given the node map
Expand Down Expand Up @@ -141,6 +149,7 @@ Feature: Basic trip planning
| waypoints | trips |
| a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p | defghijklabcd,mnopm |


# Test single node in each component #1850
Scenario: Testbot - Trip planning with less than 10 nodes
Given the node map
Expand Down Expand Up @@ -196,6 +205,7 @@ Feature: Basic trip planning
| a,b,c,d | abcda | 7.6 | 1,1,1.00009,1,1,0.99991,1.00009,1,1,1,1.00009,0.99991,1,1 |
| d,b,c,a | dbcad | 7.6 | 1.00009,0.99991,1,1,1.00009,1,1,0.99991,1.00009,1,1,1,1.00009,0.99991 |


Scenario: Testbot - Trip with geometry details of polyline
Given the query options
| geometries | polyline |
Expand All @@ -218,6 +228,7 @@ Feature: Basic trip planning
| a,b,c,d | abcda | 7.6 | 1,1,1,1.00009,0.99991,1,1,1.00009,1,1,0.99991,1.00009,1,1 |
| d,b,c,a | dbcad | 7.6 | 0.99991,1.00009,1,1,1,1.00009,0.99991,1,1,1.00009,1,1,0.99991,1.00009 |


Scenario: Testbot - Trip with geometry details of polyline6
Given the query options
| geometries | polyline6 |
Expand Down
26 changes: 25 additions & 1 deletion include/engine/api/trip_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "engine/api/route_parameters.hpp"

#include <boost/optional/optional_io.hpp>
#include <vector>

namespace osrm
Expand All @@ -47,7 +48,30 @@ namespace api
*/
struct TripParameters : public RouteParameters
{
// bool IsValid() const; Falls back to base class
TripParameters()
: RouteParameters(false,
false,
false,
RouteParameters::GeometriesType::Polyline,
RouteParameters::OverviewType::Simplified,
0,
0)
{
}

template <typename... Args>
TripParameters(int source_, int destination_, Args... args_)
: RouteParameters{std::forward<Args>(args_)...}, source{source_}, destination{destination_}
{
}

int source;
int destination;

bool IsValid() const
{
return RouteParameters::IsValid() && source > 0 && destination > 0;
}
};
}
}
Expand Down
9 changes: 9 additions & 0 deletions include/server/api/trip_parameter_grammar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,20 @@ struct TripParametersGrammar final : public RouteParametersGrammar<Iterator, Sig

TripParametersGrammar() : BaseGrammar(root_rule)
{

source_rule = (qi::lit("source=") >
qi::uint_)[ph::bind(&engine::api::TripParameters::source, qi::_r1) = qi::_1];

destination_rule = (qi::lit("destination=") >
qi::uint_)[ph::bind(&engine::api::TripParameters::destination, qi::_r1) = qi::_1];

root_rule = BaseGrammar::query_rule(qi::_r1) > -qi::lit(".json") >
-('?' > (BaseGrammar::base_rule(qi::_r1)) % '&');
}

private:
qi::rule<Iterator, Signature> source_rule;
qi::rule<Iterator, Signature> destination_rule;
qi::rule<Iterator, Signature> root_rule;
};
}
Expand Down
3 changes: 3 additions & 0 deletions src/engine/plugins/trip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ Status TripPlugin::HandleRequest(const std::shared_ptr<const datafacade::BaseDat
{
BOOST_ASSERT(parameters.IsValid());

std::cout << "parameters " << std::endl;
std::cout << "parameters.source: " << parameters.source << std::endl;
std::cout << "parameters.destination: " << parameters.destination << std::endl;
// enforce maximum number of locations for performance reasons
if (max_locations_trip > 0 &&
static_cast<int>(parameters.coordinates.size()) > max_locations_trip)
Expand Down
12 changes: 12 additions & 0 deletions unit_tests/server/parameters_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,18 @@ BOOST_AUTO_TEST_CASE(valid_trip_urls)
CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings);
CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses);
CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates);

TripParameters reference_2{};
reference_2.coordinates = coords_1;
reference_2.source = 1;
reference_2.destination = 2;
auto result_2 = parseParameters<TripParameters>("1,2;3,4?source=1&destination=2");
BOOST_CHECK(result_2);
BOOST_CHECK_EQUAL(reference_2.source, result_2->source);
BOOST_CHECK_EQUAL(reference_2.destination, result_2->destination);
CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings);
CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses);
CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates);
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 3e35441

Please sign in to comment.