diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-07 18:02:56 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-07 18:02:56 +0000 |
commit | 509c955aac687a6e8daa80906d593cb24f83c64d (patch) | |
tree | 0b551c1a26a2c08973e9dcf298f9da286687fc20 /test | |
parent | Merge branch 'template-types' (diff) | |
parent | Simplify find_arcs_radius (diff) | |
download | ilt-509c955aac687a6e8daa80906d593cb24f83c64d.tar.bz2 ilt-509c955aac687a6e8daa80906d593cb24f83c64d.tar.xz ilt-509c955aac687a6e8daa80906d593cb24f83c64d.zip |
Merge branch 'global-network'
Diffstat (limited to 'test')
-rw-r--r-- | test/test-maths.cpp | 18 | ||||
-rw-r--r-- | test/test-network.cpp | 23 | ||||
-rw-r--r-- | test/testStructures.h | 4 |
3 files changed, 24 insertions, 21 deletions
diff --git a/test/test-maths.cpp b/test/test-maths.cpp index 8680409..ccfb113 100644 --- a/test/test-maths.cpp +++ b/test/test-maths.cpp @@ -177,7 +177,7 @@ BOOST_AUTO_TEST_CASE(test_find_arcs_radius) struct TestLinkStraight : public LinkStraight { explicit TestLinkStraight(glm::vec3 v) : - Link {{std::make_shared<Node>(Position3D {}), vector_yaw(v)}, {std::make_shared<Node>(v), vector_yaw(-v)}, + Link {{std::make_shared<Node>(GlobalPosition3D {}), vector_yaw(v)}, {std::make_shared<Node>(v), vector_yaw(-v)}, glm::length(v)} { } @@ -216,7 +216,7 @@ struct TestLinkCurve : public LinkCurve { } }; -using CurvesData = std::tuple<glm::vec3 /*e1*/, glm::vec3 /*ctr*/, float /*angFor*/, float /* angBack*/>; +using CurvesData = std::tuple<GlobalPosition3D /*e1*/, GlobalPosition3D /*ctr*/, Angle /*angFor*/, Angle /* angBack*/>; BOOST_DATA_TEST_CASE(curve1, boost::unit_test::data::make<CurvesData>({ @@ -232,13 +232,13 @@ BOOST_DATA_TEST_CASE(curve1, BOOST_CHECK_EQUAL(l.radius, 1.F); { const auto p = l.positionAt(0, 0); - BOOST_CHECK_CLOSE_VEC(RelativePosition3D {p.pos}, RelativePosition3D {}); + BOOST_CHECK_CLOSE_VECI(p.pos, GlobalPosition3D {}); BOOST_CHECK_CLOSE_VEC(p.rot, glm::vec3(0, angFor, 0)); } { const auto p = l.positionAt(0, 1); - BOOST_CHECK_CLOSE_VECI(RelativePosition3D {p.pos}, e1); - BOOST_CHECK_CLOSE_VECI(p.rot, glm::vec3(0, angBack, 0)); + BOOST_CHECK_CLOSE_VECI(p.pos, e1); + BOOST_CHECK_CLOSE_VEC(p.rot, glm::vec3(0, angBack, 0)); } } @@ -248,13 +248,13 @@ BOOST_DATA_TEST_CASE(curve1, { const auto p = l.positionAt(0, 0); const auto angForReversed = normalize(vector_yaw(-e1) * 2 - angFor); - BOOST_CHECK_CLOSE_VECI(RelativePosition3D {p.pos}, e1); - BOOST_CHECK_CLOSE_VECI(p.rot, glm::vec3(0, angForReversed, 0)); + BOOST_CHECK_CLOSE_VECI(p.pos, e1); + BOOST_CHECK_CLOSE_VEC(p.rot, glm::vec3(0, angForReversed, 0)); } { const auto p = l.positionAt(0, 1); const auto angBackReversed = normalize(vector_yaw(e1) * 2 - angBack); - BOOST_CHECK_CLOSE_VEC(RelativePosition3D {p.pos}, Position3D {}); + BOOST_CHECK_CLOSE_VECI(p.pos, GlobalPosition3D {}); BOOST_CHECK_CLOSE_VEC(p.rot, glm::vec3(0, angBackReversed, 0)); } } @@ -330,6 +330,6 @@ BOOST_DATA_TEST_CASE(rayLineDistance, for (float along = 0.2F; along <= 0.8F; along += 0.1F) { const auto target = n1 + (along * nstep); const auto direction = glm::normalize(target - c); - BOOST_CHECK_LE(Ray(c, direction).distanceToLine(n1, n2), 0.01F); + BOOST_CHECK_LE(Ray<RelativePosition3D>(c, direction).distanceToLine(n1, n2), 0.01F); } } diff --git a/test/test-network.cpp b/test/test-network.cpp index ab0818a..0274b00 100644 --- a/test/test-network.cpp +++ b/test/test-network.cpp @@ -26,7 +26,10 @@ BOOST_GLOBAL_FIXTURE(TestMainWindow); struct TestLink : public LinkStraight { TestLink(const Node::Ptr & a, const Node::Ptr & b) : TestLink {a, b, (a->pos - b->pos)} { } - TestLink(Node::Ptr a, Node::Ptr b, glm::vec2 l) : Link {{std::move(a), 0}, {std::move(b), pi}, glm::length(l)} { } + TestLink(Node::Ptr a, Node::Ptr b, RelativePosition2D l) : + Link {{std::move(a), 0}, {std::move(b), pi}, glm::length(l)} + { + } TestLink(Node::Ptr a, Node::Ptr b, float l) : Link {{std::move(a), 0}, {std::move(b), pi}, l} { } @@ -34,8 +37,8 @@ struct TestLink : public LinkStraight { using CurveLink = TestLink; }; -constexpr glm::vec3 p000 {0, 0, 0}, p100 {1, 0, 0}, p200 {2, 0, 0}, p300 {3, 0, 0}; -constexpr glm::vec3 p110 {1, 1, 0}; +constexpr GlobalPosition3D p000 {0, 0, 0}, p100 {10000, 0, 0}, p200 {20000, 0, 0}, p300 {30000, 0, 0}; +constexpr GlobalPosition3D p110 {10000, 10000, 0}; struct TestNetwork : public NetworkOf<TestLink> { TestNetwork() : NetworkOf<TestLink> {RESDIR "rails.jpg"} @@ -55,13 +58,13 @@ struct TestNetwork : public NetworkOf<TestLink> { } }; -const auto VALID_NODES = boost::unit_test::data::make<glm::vec3>({ +const auto VALID_NODES = boost::unit_test::data::make<GlobalPosition3D>({ p000, p100, p200, p300, }); -const auto INVALID_NODES = boost::unit_test::data::make<glm::vec3>({ +const auto INVALID_NODES = boost::unit_test::data::make<GlobalPosition3D>({ {1000, 0, 0}, {0, 1000, 0}, {0, 0, 1000}, @@ -201,7 +204,7 @@ BOOST_FIXTURE_TEST_CASE(test_rail_network, RailLinks) // -------- auto l0 = addLinksBetween(p000, p100); BOOST_CHECK(dynamic_cast<RailLinkStraight *>(l0.get())); - BOOST_CHECK_EQUAL(l0->length, 1.F); + BOOST_CHECK_EQUAL(l0->length, 10000); BOOST_CHECK_CLOSE(l0->ends[0].dir, half_pi, 0.1F); BOOST_CHECK_CLOSE(l0->ends[1].dir, -half_pi, 0.1F); BOOST_CHECK(l0->ends[0].nexts.empty()); @@ -209,7 +212,7 @@ BOOST_FIXTURE_TEST_CASE(test_rail_network, RailLinks) auto l1 = addLinksBetween(p200, p100); BOOST_CHECK(dynamic_cast<RailLinkStraight *>(l1.get())); - BOOST_CHECK_EQUAL(l1->length, 1.F); + BOOST_CHECK_EQUAL(l1->length, 10000); BOOST_CHECK_CLOSE(l1->ends[0].dir, half_pi, 0.1F); BOOST_CHECK_CLOSE(l1->ends[1].dir, -half_pi, 0.1F); BOOST_CHECK(l0->ends[0].nexts.empty()); @@ -221,7 +224,7 @@ BOOST_FIXTURE_TEST_CASE(test_rail_network, RailLinks) auto l2 = addLinksBetween(p200, p300); BOOST_CHECK(dynamic_cast<RailLinkStraight *>(l2.get())); - BOOST_CHECK_EQUAL(l2->length, 1.F); + BOOST_CHECK_EQUAL(l2->length, 10000); BOOST_CHECK_CLOSE(l2->ends[0].dir, half_pi, 0.1F); BOOST_CHECK_CLOSE(l2->ends[1].dir, -half_pi, 0.1F); BOOST_CHECK(l0->ends[0].nexts.empty()); @@ -233,7 +236,7 @@ BOOST_FIXTURE_TEST_CASE(test_rail_network, RailLinks) auto l3 = addLinksBetween(p000, p110); BOOST_CHECK(dynamic_cast<RailLinkCurve *>(l3.get())); - BOOST_CHECK_CLOSE(l3->length, pi + half_pi, 0.1F); + BOOST_CHECK_CLOSE(l3->length, (pi + half_pi) * 10000.F, 0.1F); BOOST_CHECK_CLOSE(l3->ends[0].dir, -half_pi, 0.1F); BOOST_CHECK_CLOSE(l3->ends[1].dir, 0, 0.1F); BOOST_CHECK_EQUAL(l0->ends[0].nexts.at(0).first.lock(), l3); @@ -243,7 +246,7 @@ BOOST_FIXTURE_TEST_CASE(test_rail_network, RailLinks) BOOST_CHECK(l3->ends[1].nexts.empty()); auto l4 = addLinksBetween(p110, p300); - BOOST_CHECK_CLOSE(l4->length, 3.04F, 0.1F); + BOOST_CHECK_CLOSE(l4->length, 30400.F, 0.1F); BOOST_CHECK_BETWEEN(l4->ends[0].dir, .23F, .24F); BOOST_CHECK_CLOSE(l4->ends[1].dir, half_pi, 0.1F); } diff --git a/test/testStructures.h b/test/testStructures.h index aaaf940..064c00c 100644 --- a/test/testStructures.h +++ b/test/testStructures.h @@ -32,9 +32,9 @@ struct TestObject : public Persistence::Persistable { float flt {}; std::string str {}; bool bl {}; - Position3D pos {}; + RelativePosition3D pos {}; std::vector<float> flts; - std::vector<Position3D> poss; + std::vector<RelativePosition3D> poss; std::vector<std::vector<std::vector<std::string>>> nest; std::unique_ptr<TestObject> ptr; std::unique_ptr<AbsObject> aptr; |