diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-03-13 15:20:05 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-03-13 15:20:05 +0000 |
commit | de856d5517df4e5288f8ca27378c4731c7ae764e (patch) | |
tree | b35209b1781538735f5717bdf187dd6ed9abb844 | |
parent | Initial commit of the route finder (diff) | |
download | ilt-de856d5517df4e5288f8ca27378c4731c7ae764e.tar.bz2 ilt-de856d5517df4e5288f8ca27378c4731c7ae764e.tar.xz ilt-de856d5517df4e5288f8ca27378c4731c7ae764e.zip |
More complete tests for route finding
-rw-r--r-- | test/test-network.cpp | 60 |
1 files changed, 45 insertions, 15 deletions
diff --git a/test/test-network.cpp b/test/test-network.cpp index 80ff1ef..1228e81 100644 --- a/test/test-network.cpp +++ b/test/test-network.cpp @@ -27,15 +27,23 @@ struct TestLink : public Link { }; constexpr glm::vec3 p000 {0, 0, 0}, p100 {1, 0, 0}, p200 {2, 0, 0}, p300 {3, 0, 0}; +constexpr glm::vec3 p101 {1, 0, 1}; struct TestNetwork : public NetworkOf<TestLink> { TestNetwork() : NetworkOf<TestLink> {RESDIR "rails.jpg"} { // 0 1 2 // p000 <-> p100 <-> p200 <-> p300 + // \ | / + // \ 5 / + // 3 | 4 + // \-> p101 <-/ addLink<TestLink>(p000, p100, 0.F, pi, 1.F); addLink<TestLink>(p100, p200, 0.F, pi, 1.F); addLink<TestLink>(p200, p300, 0.F, pi, 1.F); + addLink<TestLink>(p000, p101, 0.F, pi, 2.F); + addLink<TestLink>(p200, p101, 0.F, pi, 2.F); + addLink<TestLink>(p100, p101, 0.F, pi, 1.F); } }; @@ -91,22 +99,25 @@ BOOST_DATA_TEST_CASE(newNodeAt_new, INVALID_NODES, p) BOOST_AUTO_TEST_CASE(network_joins) { // Ends - BOOST_CHECK(links.objects[0]->ends[0].nexts.empty()); BOOST_CHECK(links.objects[2]->ends[1].nexts.empty()); // Join 0 <-> 1 - BOOST_REQUIRE_EQUAL(links.objects[0]->ends[1].nexts.size(), 1); - BOOST_CHECK_EQUAL(links.objects[0]->ends[1].nexts.front().first.lock().get(), links.objects[1].get()); - BOOST_CHECK_EQUAL(links.objects[0]->ends[1].nexts.front().second, 0); - BOOST_REQUIRE_EQUAL(links.objects[1]->ends[0].nexts.size(), 1); - BOOST_CHECK_EQUAL(links.objects[1]->ends[0].nexts.front().first.lock().get(), links.objects[0].get()); - BOOST_CHECK_EQUAL(links.objects[1]->ends[0].nexts.front().second, 1); + BOOST_REQUIRE_EQUAL(links.objects[0]->ends[1].nexts.size(), 2); + BOOST_CHECK_EQUAL(links.objects[0]->ends[1].nexts[0].first.lock().get(), links.objects[1].get()); + BOOST_CHECK_EQUAL(links.objects[0]->ends[1].nexts[0].second, 0); + BOOST_CHECK_EQUAL(links.objects[0]->ends[1].nexts[1].first.lock().get(), links.objects[5].get()); + BOOST_CHECK_EQUAL(links.objects[0]->ends[1].nexts[1].second, 0); + BOOST_REQUIRE_EQUAL(links.objects[1]->ends[0].nexts.size(), 2); + BOOST_CHECK_EQUAL(links.objects[1]->ends[0].nexts[0].first.lock().get(), links.objects[0].get()); + BOOST_CHECK_EQUAL(links.objects[1]->ends[0].nexts[0].second, 1); + BOOST_CHECK_EQUAL(links.objects[1]->ends[0].nexts[1].first.lock().get(), links.objects[5].get()); + BOOST_CHECK_EQUAL(links.objects[1]->ends[0].nexts[1].second, 0); // Join 1 <-> 2 - BOOST_REQUIRE_EQUAL(links.objects[1]->ends[1].nexts.size(), 1); - BOOST_CHECK_EQUAL(links.objects[1]->ends[1].nexts.front().first.lock().get(), links.objects[2].get()); - BOOST_CHECK_EQUAL(links.objects[1]->ends[1].nexts.front().second, 0); - BOOST_REQUIRE_EQUAL(links.objects[2]->ends[0].nexts.size(), 1); - BOOST_CHECK_EQUAL(links.objects[2]->ends[0].nexts.front().first.lock().get(), links.objects[1].get()); - BOOST_CHECK_EQUAL(links.objects[2]->ends[0].nexts.front().second, 1); + BOOST_REQUIRE_EQUAL(links.objects[1]->ends[1].nexts.size(), 2); + BOOST_CHECK_EQUAL(links.objects[1]->ends[1].nexts[0].first.lock().get(), links.objects[2].get()); + BOOST_CHECK_EQUAL(links.objects[1]->ends[1].nexts[0].second, 0); + BOOST_REQUIRE_EQUAL(links.objects[2]->ends[0].nexts.size(), 2); + BOOST_CHECK_EQUAL(links.objects[2]->ends[0].nexts[0].first.lock().get(), links.objects[1].get()); + BOOST_CHECK_EQUAL(links.objects[2]->ends[0].nexts[0].second, 1); } BOOST_DATA_TEST_CASE(routeTo_nodeNotInNetwork, INVALID_NODES, dest) @@ -132,7 +143,7 @@ BOOST_AUTO_TEST_CASE(routeTo_upStream_to2) BOOST_AUTO_TEST_CASE(routeTo_upStream_to3) { - const auto & start = links.objects.front()->ends[1]; + const auto & start = links.objects[0]->ends[1]; auto r = this->routeFromTo(start, p300); BOOST_REQUIRE_EQUAL(r.size(), 2); BOOST_CHECK_EQUAL(r[0].lock().get(), links.objects[1].get()); @@ -141,11 +152,30 @@ BOOST_AUTO_TEST_CASE(routeTo_upStream_to3) BOOST_AUTO_TEST_CASE(routeTo_downStream_to0) { - const auto & start = links.objects.back()->ends[0]; + const auto & start = links.objects[2]->ends[0]; auto r = this->routeFromTo(start, p000); BOOST_REQUIRE_EQUAL(r.size(), 2); BOOST_CHECK_EQUAL(r[0].lock().get(), links.objects[1].get()); BOOST_CHECK_EQUAL(r[1].lock().get(), links.objects[0].get()); } +BOOST_AUTO_TEST_CASE(routeTo_upStream_3to300) +{ + const auto & start = links.objects[3]->ends[1]; + auto r = this->routeFromTo(start, p300); + BOOST_REQUIRE_EQUAL(r.size(), 2); + BOOST_CHECK_EQUAL(r[0].lock().get(), links.objects[4].get()); + BOOST_CHECK_EQUAL(r[1].lock().get(), links.objects[2].get()); +} + +BOOST_AUTO_TEST_CASE(routeTo_downStream_3to300) +{ + const auto & start = links.objects[3]->ends[0]; + auto r = this->routeFromTo(start, p300); + BOOST_REQUIRE_EQUAL(r.size(), 3); + BOOST_CHECK_EQUAL(r[0].lock().get(), links.objects[0].get()); + BOOST_CHECK_EQUAL(r[1].lock().get(), links.objects[1].get()); + BOOST_CHECK_EQUAL(r[2].lock().get(), links.objects[2].get()); +} + BOOST_AUTO_TEST_SUITE_END() |