Skip to content

Commit 3e35441

Browse files
Kajarighoshkaj
authored andcommitted
failing unit tests
1 parent b91597c commit 3e35441

6 files changed

Lines changed: 77 additions & 7 deletions

File tree

features/step_definitions/trip.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ module.exports = function () {
3434
json = JSON.parse(res.body);
3535
}
3636

37+
console.log(json);
38+
3739
if (headers.has('status')) {
3840
got.status = json.status.toString();
3941
}
@@ -52,6 +54,15 @@ module.exports = function () {
5254
}
5355
}
5456

57+
if (headers.has('source') && headers.has('destination')) {
58+
if (this.queryParams['source']) {
59+
got.source = json.trips[0].source;
60+
}
61+
if (this.queryParams['destination']) {
62+
got.source = json.trips[0].destination;
63+
}
64+
}
65+
5566
if (headers.has('#')) {
5667
// comment column
5768
got['#'] = row['#'];

features/testbot/trip.feature

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Feature: Basic trip planning
2424
| a,b,c,d | abcda | 7.6 |
2525
| d,b,c,a | dbcad | 7.6 |
2626

27+
2728
Scenario: Testbot - Trip planning with more than 10 nodes
2829
Given the node map
2930
"""
@@ -48,14 +49,16 @@ Feature: Basic trip planning
4849
| kl |
4950
| la |
5051

51-
5252
When I plan a trip I should get
5353
| waypoints | trips |
5454
| a,b,c,d,e,f,g,h,i,j,k,l | cbalkjihgfedc |
5555

5656

5757
Scenario: Testbot - Trip planning with less than 10 nodes with fixed start and end
58-
Given the query parameters
58+
Given the query options
59+
| source | 1 |
60+
| destination | 4 |
61+
5962
Given the node map
6063
"""
6164
a b
@@ -71,11 +74,15 @@ Feature: Basic trip planning
7174

7275
When I plan a trip I should get
7376
| waypoints | trips | durations |
74-
| a,b,c,d | abcd | 7.6 |
75-
| d,b,c,a | dbca | 7.6 |
77+
| a,b,c,d | abcda | 7.6 |
78+
| d,b,c,a | dbcaa | 7.6 |
7679

7780

7881
Scenario: Testbot - Trip planning with more than 10 nodes with fixed start and end
82+
Given the query options
83+
| source | 1 |
84+
| destination | 12 |
85+
7986
Given the node map
8087
"""
8188
a b c d
@@ -101,8 +108,9 @@ Feature: Basic trip planning
101108

102109

103110
When I plan a trip I should get
104-
| waypoints | trips |
105-
| a,b,c,d,e,f,g,h,i,j,k,l | cbalkjihgfed |
111+
| waypoints | trips |
112+
| a,b,c,d,e,f,g,h,i,j,k,l | cbalkjihgfedc |
113+
106114

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

152+
144153
# Test single node in each component #1850
145154
Scenario: Testbot - Trip planning with less than 10 nodes
146155
Given the node map
@@ -196,6 +205,7 @@ Feature: Basic trip planning
196205
| 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 |
197206
| 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 |
198207

208+
199209
Scenario: Testbot - Trip with geometry details of polyline
200210
Given the query options
201211
| geometries | polyline |
@@ -218,6 +228,7 @@ Feature: Basic trip planning
218228
| 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 |
219229
| 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 |
220230

231+
221232
Scenario: Testbot - Trip with geometry details of polyline6
222233
Given the query options
223234
| geometries | polyline6 |

include/engine/api/trip_parameters.hpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030

3131
#include "engine/api/route_parameters.hpp"
3232

33+
#include <boost/optional/optional_io.hpp>
3334
#include <vector>
3435

3536
namespace osrm
@@ -47,7 +48,30 @@ namespace api
4748
*/
4849
struct TripParameters : public RouteParameters
4950
{
50-
// bool IsValid() const; Falls back to base class
51+
TripParameters()
52+
: RouteParameters(false,
53+
false,
54+
false,
55+
RouteParameters::GeometriesType::Polyline,
56+
RouteParameters::OverviewType::Simplified,
57+
0,
58+
0)
59+
{
60+
}
61+
62+
template <typename... Args>
63+
TripParameters(int source_, int destination_, Args... args_)
64+
: RouteParameters{std::forward<Args>(args_)...}, source{source_}, destination{destination_}
65+
{
66+
}
67+
68+
int source;
69+
int destination;
70+
71+
bool IsValid() const
72+
{
73+
return RouteParameters::IsValid() && source > 0 && destination > 0;
74+
}
5175
};
5276
}
5377
}

include/server/api/trip_parameter_grammar.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,20 @@ struct TripParametersGrammar final : public RouteParametersGrammar<Iterator, Sig
2626

2727
TripParametersGrammar() : BaseGrammar(root_rule)
2828
{
29+
30+
source_rule = (qi::lit("source=") >
31+
qi::uint_)[ph::bind(&engine::api::TripParameters::source, qi::_r1) = qi::_1];
32+
33+
destination_rule = (qi::lit("destination=") >
34+
qi::uint_)[ph::bind(&engine::api::TripParameters::destination, qi::_r1) = qi::_1];
35+
2936
root_rule = BaseGrammar::query_rule(qi::_r1) > -qi::lit(".json") >
3037
-('?' > (BaseGrammar::base_rule(qi::_r1)) % '&');
3138
}
3239

3340
private:
41+
qi::rule<Iterator, Signature> source_rule;
42+
qi::rule<Iterator, Signature> destination_rule;
3443
qi::rule<Iterator, Signature> root_rule;
3544
};
3645
}

src/engine/plugins/trip.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ Status TripPlugin::HandleRequest(const std::shared_ptr<const datafacade::BaseDat
148148
{
149149
BOOST_ASSERT(parameters.IsValid());
150150

151+
std::cout << "parameters " << std::endl;
152+
std::cout << "parameters.source: " << parameters.source << std::endl;
153+
std::cout << "parameters.destination: " << parameters.destination << std::endl;
151154
// enforce maximum number of locations for performance reasons
152155
if (max_locations_trip > 0 &&
153156
static_cast<int>(parameters.coordinates.size()) > max_locations_trip)

unit_tests/server/parameters_parser.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,18 @@ BOOST_AUTO_TEST_CASE(valid_trip_urls)
432432
CHECK_EQUAL_RANGE(reference_1.bearings, result_1->bearings);
433433
CHECK_EQUAL_RANGE(reference_1.radiuses, result_1->radiuses);
434434
CHECK_EQUAL_RANGE(reference_1.coordinates, result_1->coordinates);
435+
436+
TripParameters reference_2{};
437+
reference_2.coordinates = coords_1;
438+
reference_2.source = 1;
439+
reference_2.destination = 2;
440+
auto result_2 = parseParameters<TripParameters>("1,2;3,4?source=1&destination=2");
441+
BOOST_CHECK(result_2);
442+
BOOST_CHECK_EQUAL(reference_2.source, result_2->source);
443+
BOOST_CHECK_EQUAL(reference_2.destination, result_2->destination);
444+
CHECK_EQUAL_RANGE(reference_2.bearings, result_2->bearings);
445+
CHECK_EQUAL_RANGE(reference_2.radiuses, result_2->radiuses);
446+
CHECK_EQUAL_RANGE(reference_2.coordinates, result_2->coordinates);
435447
}
436448

437449
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)