Skip to content

Commit ccf97e7

Browse files
committed
added prior to C++11 compatibility
1 parent 2743802 commit ccf97e7

1 file changed

Lines changed: 82 additions & 45 deletions

File tree

test/r_c_shortest_paths_to_all_test.cpp

Lines changed: 82 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,21 @@ std::string buildString(std::vector<std::string> const &path_p, size_t moveReq_p
323323
return ss_l.str();
324324
}
325325

326+
/// @brief manual path build using % operator
327+
struct manual_path
328+
{
329+
manual_path &operator%(std::string const &vertex_p)
330+
{
331+
internal_path.push_back(vertex_p);
332+
return *this;
333+
}
334+
std::vector<std::string> internal_path;
335+
};
336+
326337
/// @brief test that the given path exists in the solution
327-
bool testPathExistence(std::vector<Path> const &paths_p, std::vector<std::string> const &path_p, size_t moveReq_p, double expo_p)
338+
bool testPathExistence(std::vector<Path> const &paths_p, manual_path const &manual_path_p, size_t moveReq_p, double expo_p)
328339
{
329-
std::string refStringOneWay_l = buildString(path_p, moveReq_p, expo_p, false);
340+
std::string refStringOneWay_l = buildString(manual_path_p.internal_path, moveReq_p, expo_p, false);
330341
for(Path const &path_l : paths_p)
331342
{
332343
if(boost::lexical_cast<std::string, Path>(path_l) == refStringOneWay_l)
@@ -338,8 +349,37 @@ bool testPathExistence(std::vector<Path> const &paths_p, std::vector<std::string
338349
return false;
339350
}
340351

352+
/// @brief helpers struct to construct a row of position
353+
struct manual_row
354+
{
355+
manual_row &operator%(size_t moveReq_p)
356+
{
357+
row.push_back(moveReq_p);
358+
return *this;
359+
}
360+
361+
std::vector<size_t> row;
362+
};
363+
364+
/// @brief helpers struct to construct a map of position
365+
struct manual_map
366+
{
367+
368+
manual_map &operator%(manual_row const &row_p)
369+
{
370+
map.push_back(row_p.row);
371+
return *this;
372+
}
373+
374+
std::vector<std::vector<size_t> > map;
375+
};
376+
341377
}
342378

379+
///
380+
/// All tests are based on a map giving the number of required moves to access each position
381+
///
382+
343383
void test_shortest_paths_to_all_no_move_allowed()
344384
{
345385
// 0 1 2 3 4
@@ -353,27 +393,26 @@ void test_shortest_paths_to_all_no_move_allowed()
353393
// we read vertical index first
354394
// 2,0 is line 2 and colum 0
355395
//
356-
std::vector<std::vector<size_t> > pos_l = {
357-
{1, 1, 1, 1, 1},
358-
{1, 0, 1, 0, 1},
359-
{0, 0, 0, 0, 0},
360-
{1, 0, 1, 0, 1},
361-
{1, 1, 1, 0, 1}
362-
};
396+
manual_map map_l;
397+
map_l % (manual_row() % 1 % 1 % 1 % 1 % 1);
398+
map_l % (manual_row() % 1 % 0 % 1 % 0 % 1);
399+
map_l % (manual_row() % 0 % 0 % 0 % 0 % 0);
400+
map_l % (manual_row() % 1 % 0 % 1 % 0 % 1);
401+
map_l % (manual_row() % 1 % 1 % 1 % 0 % 1);
363402

364-
std::vector<Path> vectPath_l = getAllPathsToN(pos_l, {2,0}, 0);
403+
std::vector<Path> vectPath_l = getAllPathsToN(map_l.map, {2,0}, 0);
365404

366405
// Check all paths to all accessible tiles (no move are allowed meaning that all tile with 1 value are forbidden)
367-
BOOST_TEST(testPathExistence(vectPath_l, {"1,1", "2,1", "2,0"}, 0, 2));
368-
BOOST_TEST(testPathExistence(vectPath_l, {"1,3", "2,3", "2,2", "2,1", "2,0"}, 0, 4));
369-
BOOST_TEST(testPathExistence(vectPath_l, {"2,0"}, 0, 0));
370-
BOOST_TEST(testPathExistence(vectPath_l, {"2,1", "2,0"}, 0, 1));
371-
BOOST_TEST(testPathExistence(vectPath_l, {"2,2", "2,1", "2,0"}, 0, 2));
372-
BOOST_TEST(testPathExistence(vectPath_l, {"2,3", "2,2", "2,1", "2,0"}, 0, 3));
373-
BOOST_TEST(testPathExistence(vectPath_l, {"2,4", "2,3", "2,2", "2,1", "2,0"}, 0, 4));
374-
BOOST_TEST(testPathExistence(vectPath_l, {"3,1", "2,1", "2,0"}, 0, 2));
375-
BOOST_TEST(testPathExistence(vectPath_l, {"3,3", "2,3", "2,2", "2,1", "2,0"}, 0, 4));
376-
BOOST_TEST(testPathExistence(vectPath_l, {"4,3", "3,3", "2,3", "2,2", "2,1", "2,0"}, 0, 5));
406+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "1,1" % "2,1" % "2,0", 0, 2));
407+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "1,3" % "2,3" % "2,2" % "2,1" % "2,0", 0, 4));
408+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "2,0", 0, 0));
409+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "2,1" % "2,0", 0, 1));
410+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "2,2" % "2,1" % "2,0", 0, 2));
411+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "2,3" % "2,2" % "2,1" % "2,0", 0, 3));
412+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "2,4" % "2,3" % "2,2" % "2,1" % "2,0", 0, 4));
413+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "3,1" % "2,1" % "2,0", 0, 2));
414+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "3,3" % "2,3" % "2,2" % "2,1" % "2,0", 0, 4));
415+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "4,3" % "3,3" % "2,3" % "2,2" % "2,1" % "2,0", 0, 5));
377416

378417
}
379418

@@ -382,28 +421,27 @@ void test_shortest_paths_to_all_one_move_allowed()
382421
// 0 1 2 3 4
383422
// --------------
384423
//0 | 1, 1, 1, 1, 1
385-
//1 | 1, 1, 1, 1, 1
424+
//1 | 1, 1, 1, 0, 1
386425
//2 | 0, 0, 1, 0, 1
387426
//
388427
// we read vertical index first
389428
// 2,0 is line 2 and colum 0
390429
//
391-
std::vector<std::vector<size_t> > pos_l = {
392-
{1, 1, 1, 1, 1},
393-
{1, 1, 1, 0, 1},
394-
{0, 0, 1, 0, 1}
395-
};
430+
manual_map map_l;
431+
map_l % (manual_row() % 1 % 1 % 1 % 1 % 1);
432+
map_l % (manual_row() % 1 % 1 % 1 % 0 % 1);
433+
map_l % (manual_row() % 0 % 0 % 1 % 0 % 1);
396434

397-
std::vector<Path> vectPath_l = getAllPathsToN(pos_l, {2,0}, 1);
435+
std::vector<Path> vectPath_l = getAllPathsToN(map_l.map, {2,0}, 1);
398436

399437
// Check all paths to all accessible tiles (no move are allowed meaning that all tile with 1 value are forbidden)
400-
BOOST_TEST(testPathExistence(vectPath_l, {"1,0", "2,0"}, 1, 1));
401-
BOOST_TEST(testPathExistence(vectPath_l, {"1,1", "2,1", "2,0"}, 1, 2));
402-
BOOST_TEST(testPathExistence(vectPath_l, {"1,3", "2,3", "2,2", "2,1", "2,0"}, 1, 4));
403-
BOOST_TEST(testPathExistence(vectPath_l, {"2,0"}, 0, 0));
404-
BOOST_TEST(testPathExistence(vectPath_l, {"2,1", "2,0"}, 0, 1));
405-
BOOST_TEST(testPathExistence(vectPath_l, {"2,2", "2,1", "2,0"}, 1, 2));
406-
BOOST_TEST(testPathExistence(vectPath_l, {"2,3", "2,2", "2,1", "2,0"}, 1, 3));
438+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "1,0" % "2,0", 1, 1));
439+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "1,1" % "2,1" % "2,0", 1, 2));
440+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "1,3" % "2,3" % "2,2" % "2,1" % "2,0", 1, 4));
441+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "2,0", 0, 0));
442+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "2,1" % "2,0", 0, 1));
443+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "2,2" % "2,1" % "2,0", 1, 2));
444+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "2,3" % "2,2" % "2,1" % "2,0", 1, 3));
407445
}
408446

409447
void test_shortest_paths_to_all_multiple_paths()
@@ -417,20 +455,19 @@ void test_shortest_paths_to_all_multiple_paths()
417455
// we read vertical index first
418456
// 2,0 is line 2 and colum 0
419457
//
420-
std::vector<std::vector<size_t> > pos_l = {
421-
{1, 1, 1, 1, 1},
422-
{0, 0, 1, 0, 1},
423-
{0, 0, 1, 0, 1}
424-
};
458+
manual_map map_l;
459+
map_l % (manual_row() % 1 % 1 % 1 % 1 % 1);
460+
map_l % (manual_row() % 0 % 0 % 1 % 0 % 1);
461+
map_l % (manual_row() % 0 % 0 % 1 % 0 % 0);
425462

426-
std::vector<Path> vectPath_l = getAllPathsToN(pos_l, {2,0}, 0);
463+
std::vector<Path> vectPath_l = getAllPathsToN(map_l.map, {2,0}, 0);
427464

428465
// Check all paths to all accessible tiles (no move are allowed meaning that all tile with 1 value are forbidden)
429-
BOOST_TEST(testPathExistence(vectPath_l, {"1,0", "2,0"}, 0, 1));
430-
BOOST_TEST(testPathExistence(vectPath_l, {"1,1", "1,0", "2,0"}, 0, 2));
431-
BOOST_TEST(testPathExistence(vectPath_l, {"1,1", "2,1", "2,0"}, 0, 2));
432-
BOOST_TEST(testPathExistence(vectPath_l, {"2,0"}, 0, 0));
433-
BOOST_TEST(testPathExistence(vectPath_l, {"2,1", "2,0"}, 0, 1));
466+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "1,0" % "2,0", 0, 1));
467+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "1,1" % "1,0" % "2,0", 0, 2));
468+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "1,1" % "2,1" % "2,0", 0, 2));
469+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "2,0", 0, 0));
470+
BOOST_TEST(testPathExistence(vectPath_l, manual_path() % "2,1" % "2,0", 0, 1));
434471
}
435472

436473
int main(int, char*[])

0 commit comments

Comments
 (0)