-
Notifications
You must be signed in to change notification settings - Fork 74
v0.2.49..v0.2.50 changeset WayTest.cpp
Garret Voltz edited this page Nov 6, 2019
·
1 revision
diff --git a/hoot-core-test/src/test/cpp/hoot/core/elements/WayTest.cpp b/hoot-core-test/src/test/cpp/hoot/core/elements/WayTest.cpp
index f34f435..4566689 100644
--- a/hoot-core-test/src/test/cpp/hoot/core/elements/WayTest.cpp
+++ b/hoot-core-test/src/test/cpp/hoot/core/elements/WayTest.cpp
@@ -22,7 +22,7 @@
* This will properly maintain the copyright information. DigitalGlobe
* copyrights will be updated automatically.
*
- * @copyright Copyright (C) 2013, 2014, 2015, 2018 DigitalGlobe (http://www.digitalglobe.com/)
+ * @copyright Copyright (C) 2013, 2014, 2015, 2018, 2019 DigitalGlobe (http://www.digitalglobe.com/)
*/
// Hoot
@@ -37,6 +37,7 @@ class WayTest : public HootTestFixture
{
CPPUNIT_TEST_SUITE(WayTest);
CPPUNIT_TEST(runRemoveTest);
+ CPPUNIT_TEST(runReplaceTest);
CPPUNIT_TEST_SUITE_END();
public:
@@ -58,6 +59,76 @@ public:
w.removeNode(2);
HOOT_STR_EQUALS("[3]{1, 3, 5}", w.getNodeIds());
}
+
+ void runReplaceTest()
+ {
+ Way w(Status::Unknown1, -1, 10);
+
+ w.clear();
+ w.addNode(1);
+ w.addNode(2);
+ w.addNode(5);
+ w.replaceNode(2, 4);
+ HOOT_STR_EQUALS("[3]{1, 4, 5}", w.getNodeIds());
+
+ // closed ways
+ w.clear();
+ w.addNode(1);
+ w.addNode(2);
+ w.addNode(1);
+ w.replaceNode(2, 4);
+ HOOT_STR_EQUALS("[3]{1, 4, 1}", w.getNodeIds());
+
+ // replacement node already exists - Note that Way::replaceNode does allow duplicated way nodes
+ // to be introduced. Its currently the responsibility of the caller to clean up after the
+ // replacement. See notes in Way::replaceNode. If we decide we want to change that behavior,
+ // the the correct output here becomes: [4]{1, 4, 3, 1}
+ w.clear();
+ w.addNode(1);
+ w.addNode(2);
+ w.addNode(3);
+ w.addNode(4);
+ w.addNode(1);
+ w.replaceNode(2, 4);
+ HOOT_STR_EQUALS("[5]{1, 4, 3, 4, 1}", w.getNodeIds());
+
+ // start/end node replaced
+ w.clear();
+ w.addNode(1);
+ w.addNode(2);
+ w.addNode(1);
+ w.replaceNode(1, 3);
+ HOOT_STR_EQUALS("[3]{3, 2, 3}", w.getNodeIds());
+
+ // This is non-sensical, and mostly here for documentation purposes. If we didn't allow dupe
+ // nodes in Way::replaceNode, we would end up with two nodes instead of three. No way should
+ // ever have duplicate nodes, but we don't check that at runtime outside of debugging due to
+ // the performance hit.
+ w.clear();
+ w.addNode(1);
+ w.addNode(2);
+ w.addNode(1);
+ w.replaceNode(1, 2);
+ HOOT_STR_EQUALS("[3]{2, 2, 2}", w.getNodeIds());
+
+ // Replace a middle node with an end node that matches with the ID of what we're replacing with
+ // We end up with two consecutive nodes with the same ID due to dupes being allowed.
+ w.clear();
+ w.addNode(1);
+ w.addNode(2);
+ w.addNode(3);
+ w.replaceNode(2, 3);
+ HOOT_STR_EQUALS("[3]{1, 3, 3}", w.getNodeIds());
+
+ // Replace an end node with the ID from the end node on the other side. We should end up with
+ // the way having identical end nodes that both have the replacement ID.
+ w.clear();
+ w.addNode(1);
+ w.addNode(2);
+ w.addNode(3);
+ w.replaceNode(1, 3);
+ HOOT_STR_EQUALS("[3]{3, 2, 3}", w.getNodeIds());
+ }
};
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(WayTest, "quick");