Skip to content

v0.2.49..v0.2.50 changeset OsmMapTest.cpp

Garret Voltz edited this page Nov 6, 2019 · 1 revision
diff --git a/hoot-core-test/src/test/cpp/hoot/core/elements/OsmMapTest.cpp b/hoot-core-test/src/test/cpp/hoot/core/elements/OsmMapTest.cpp
index 1bbe6c0..78991f7 100644
--- a/hoot-core-test/src/test/cpp/hoot/core/elements/OsmMapTest.cpp
+++ b/hoot-core-test/src/test/cpp/hoot/core/elements/OsmMapTest.cpp
@@ -466,7 +466,7 @@ public:
     OsmMapPtr mapA(new OsmMap());
     reader.read("test-files/ToyTestA.osm", mapA);
 
-    const char* exceptionMsg = "<wrong>";
+    QString exceptionMsg = "<wrong>";
     try
     {
       mapA->append(mapA);
@@ -744,28 +744,35 @@ public:
     // Sample data does not have any relations, have to add some with nodes in them
     RelationPtr relations[5] =
     {
-      RelationPtr( new Relation(Status::Unknown1, 100, 3.0, "relationtype0") ),
-      RelationPtr( new Relation(Status::Unknown1, 101, 4.1, "relationtype1") ),
-      RelationPtr( new Relation(Status::Unknown1, 102, 5.2, "relationtype2") ),
-      RelationPtr( new Relation(Status::Unknown1, 103, 6.3, "relationtype3") ),
-      RelationPtr( new Relation(Status::Unknown1, 104, 7.4, "relationtype4") ),
+      RelationPtr(new Relation(Status::Unknown1, 100, 3.0, "relationtype0")),
+      RelationPtr(new Relation(Status::Unknown1, 101, 4.1, "relationtype1")),
+      RelationPtr(new Relation(Status::Unknown1, 102, 5.2, "relationtype2")),
+      RelationPtr(new Relation(Status::Unknown1, 103, 6.3, "relationtype3")),
+      RelationPtr(new Relation(Status::Unknown1, 104, 7.4, "relationtype4")),
     };
 
     // Add relations to the map
-    for ( int i = 0; i < 5; i++ )
+    for (int i = 0; i < 5; i++)
     {
       relations[i]->addElement("correlated_streetlight", ElementId::node(-10 - i));
       relations[i]->addElement("correlated_streetlight", ElementId::node(-11 - i));
-
-      // LOG_DEBUG(relations[i]->toString());
-
+      LOG_TRACE(relations[i]->toString());
       map->addRelation(relations[i]);
     }
 
+    WayMap waysBeforeReplacement = map->getWays();
+    LOG_TRACE("Ways before replacement:");
+    for (WayMap::const_iterator iterator = waysBeforeReplacement.begin();
+         iterator != waysBeforeReplacement.end(); ++iterator)
+    {
+      LOG_VART(iterator->second->getNodeIds());
+    }
+
     // Replace selected nodes
-    for ( int i = -2; i > -22; i -= 2 )
+    for (int i = -2; i > -22; i -= 2)
     {
-      map->replaceNode( i, -10 + i);
+      LOG_TRACE("Replacing node: " << i << " with: " << (-10 + i) << "...");
+      map->replaceNode(i, -10 + i);
     }
 
     // Original data had nodes -1 through -36.  Make sure that even-numbered nodes -2 through
@@ -773,33 +780,32 @@ public:
 
     const NodeMap nodes = map->getNodes();
     CPPUNIT_ASSERT_EQUAL(26, (int)nodes.size());
-    for ( NodeMap::const_iterator nodeIter = nodes.begin();
-          nodeIter != nodes.end(); ++nodeIter )
+    for (NodeMap::const_iterator nodeIter = nodes.begin(); nodeIter != nodes.end(); ++nodeIter)
     {
       const ConstNodePtr n = nodeIter->second;
-      //LOG_DEBUG("Node: " << n->getId());
-      CPPUNIT_ASSERT( (n->getId() >= -36) && (n->getId() <= -1) );
+      LOG_TRACE("Node: " << n->getId());
+      CPPUNIT_ASSERT((n->getId() >= -36) && (n->getId() <= -1));
 
       // If it's in the range where nodes were replaced, make sure only ones left are odd IDs
-      if ( n->getId() >= -21 )
+      if (n->getId() >= -21)
       {
-        //LOG_DEBUG("Even test on negative number: " << (n->getId() % 2) );
-        CPPUNIT_ASSERT( (n->getId() % 2) == -1 );
+        LOG_TRACE("Even test on negative number: " << (n->getId() % 2) );
+        CPPUNIT_ASSERT((n->getId() % 2) == -1);
       }
     }
 
     // Make sure replacement did correct thing with ways
     WayMap ways = map->getWays();
-    CPPUNIT_ASSERT( 4 == ways.size() );
+    CPPUNIT_ASSERT(4 == ways.size());
 
     int i = 1;
-    for ( WayMap::const_iterator iterator = ways.begin(); iterator != ways.end(); ++iterator )
+    for (WayMap::const_iterator iterator = ways.begin(); iterator != ways.end(); ++iterator)
     {
       WayPtr way = iterator->second;
-      //LOG_DEBUG(way->toString());
+      LOG_TRACE(way->toString());
       std::vector<long> nodeIds = way->getNodeIds();
-      CPPUNIT_ASSERT( (-5 + i) == way->getId() );
-      if ( i == 1 )
+      CPPUNIT_ASSERT((-5 + i) == way->getId());
+      if (i == 1)
       {
         const size_t correctSize = 4;
         CPPUNIT_ASSERT(nodeIds.size() == correctSize);
@@ -807,28 +813,30 @@ public:
         std::vector<long> correctIdVector(correctIds, correctIds + sizeof(correctIds) / sizeof(long));
         CPPUNIT_ASSERT(correctIdVector == nodeIds);
       }
-      else if ( i == 2 )
+      else if (i == 2)
       {
         const size_t correctSize = 30;
         CPPUNIT_ASSERT( nodeIds.size() == correctSize );
+        // really there shouldn't be duplicated way nodes in the way; see comments in
+        // Way::replaceNode
         long correctIds[correctSize] = { -3, -24, -5, -26, -7, -32, -31, -30, -36, -29, -28, -27, -26,
-                                -25, -24, -23, -22, -21, -30, -19, -28, -17, -26, -15, -24,
-                                -13, -22, -11, -30, -9 };
+                                         -25, -24, -23, -22, -21, -30, -19, -28, -17, -26, -15, -24,
+                                         -13, -22, -11, -30, -9 };
         std::vector<long> correctIdVector(correctIds, correctIds + sizeof(correctIds) / sizeof(long));
         CPPUNIT_ASSERT(correctIdVector == nodeIds);
       }
-      else if ( i == 3 )
+      else if (i == 3)
       {
         const size_t correctSize = 3;
-        CPPUNIT_ASSERT( nodeIds.size() == correctSize );
+        CPPUNIT_ASSERT(nodeIds.size() == correctSize);
         long correctIds[correctSize] = { -33, -28, -7 };
         std::vector<long> correctIdVector(correctIds, correctIds + sizeof(correctIds) / sizeof(long));
         CPPUNIT_ASSERT(correctIdVector == nodeIds);
       }
-      else if (i == 4 )
+      else if (i == 4)
       {
         const size_t correctSize = 3;
-        CPPUNIT_ASSERT( nodeIds.size() == correctSize );
+        CPPUNIT_ASSERT(nodeIds.size() == correctSize);
         long correctIds[correctSize] = { -32, -22, -1 };
         std::vector<long> correctIdVector(correctIds, correctIds + sizeof(correctIds) / sizeof(long));
         CPPUNIT_ASSERT(correctIdVector == nodeIds);
@@ -881,7 +889,6 @@ public:
         CPPUNIT_ASSERT(entries[0].getElementId() == ElementId::node(-24));
         CPPUNIT_ASSERT(entries[1].getElementId() == ElementId::node(-15));
         break;
-
       }
 
       i++;
Clone this wiki locally