[Liblas-commits] libpc: add Faux read/write tests

liblas-commits at liblas.org liblas-commits at liblas.org
Wed Feb 23 21:00:09 EST 2011


details:   http://hg.liblas.orglibpc/rev/d796f3aee4ff
changeset: 83:d796f3aee4ff
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Wed Feb 23 18:00:03 2011 -0800
description:
add Faux read/write tests

diffstat:

 include/libpc/FauxReader.hpp |   3 +-
 include/libpc/FauxWriter.hpp |   6 +++
 src/FauxWriter.cpp           |  29 +++++++++++------
 test/unit/FauxReaderTest.cpp |  70 ++++++++++++++++++++++++++++++++++++++++++-
 test/unit/FauxWriterTest.cpp |  47 ++++++++++++++++++++++++++++-
 5 files changed, 141 insertions(+), 14 deletions(-)

diffs (240 lines):

diff -r 13177ebbdcd8 -r d796f3aee4ff include/libpc/FauxReader.hpp
--- a/include/libpc/FauxReader.hpp	Wed Feb 23 17:59:11 2011 -0800
+++ b/include/libpc/FauxReader.hpp	Wed Feb 23 18:00:03 2011 -0800
@@ -50,7 +50,8 @@
 //
 // It supports two modes: "random" generates points that are randomly
 // distributed within the given bounding box, and "constant" generates its
-// points to always be at the minimum of the bounding box.
+// points to always be at the minimum of the bounding box.  The Time field
+// is always set to the point number.
 //
 class LIBPC_DLL FauxReader : public Reader
 {
diff -r 13177ebbdcd8 -r d796f3aee4ff include/libpc/FauxWriter.hpp
--- a/include/libpc/FauxWriter.hpp	Wed Feb 23 17:59:11 2011 -0800
+++ b/include/libpc/FauxWriter.hpp	Wed Feb 23 18:00:03 2011 -0800
@@ -60,6 +60,9 @@
     float getMaxX() const { return m_maximumX; }
     float getMaxY() const { return m_maximumY; }
     float getMaxZ() const { return m_maximumZ; }
+    float getAvgX() const { return m_averageX; }
+    float getAvgY() const { return m_averageY; }
+    float getAvgZ() const { return m_averageZ; }
 
 private:
     float m_minimumX;
@@ -68,6 +71,9 @@
     float m_maximumX;
     float m_maximumY;
     float m_maximumZ;
+    float m_averageX;
+    float m_averageY;
+    float m_averageZ;
 
     void writeBegin();
     boost::uint32_t writeBuffer(const PointData&);
diff -r 13177ebbdcd8 -r d796f3aee4ff src/FauxWriter.cpp
--- a/src/FauxWriter.cpp	Wed Feb 23 17:59:11 2011 -0800
+++ b/src/FauxWriter.cpp	Wed Feb 23 18:00:03 2011 -0800
@@ -54,6 +54,7 @@
 {
     m_minimumX = m_minimumY = m_minimumZ = std::numeric_limits<float>::max();
     m_maximumX = m_maximumY = m_maximumZ = std::numeric_limits<float>::min();
+    m_averageX = m_averageY = m_averageZ = 0;
 
     return;
 }
@@ -61,17 +62,21 @@
 
 void FauxWriter::writeEnd()
 {
-    cout << "FauxWriter::writeEnd()" << endl;
-    cout << "  wrote " << m_actualNumPointsWritten << " points" << endl;
+    m_averageX /= (float)m_actualNumPointsWritten;
+    m_averageY /= (float)m_actualNumPointsWritten;
+    m_averageZ /= (float)m_actualNumPointsWritten;
 
-    cout << "  min X: " << m_minimumX << endl;
-    cout << "  min Y: " << m_minimumY << endl;
-    cout << "  min Z: " << m_minimumZ << endl;
-    cout << "  max X: " << m_maximumX << endl;
-    cout << "  max Y: " << m_maximumY << endl;
-    cout << "  max Z: " << m_maximumZ << endl;
-    
-    cout << endl;
+    //cout << "FauxWriter::writeEnd()" << endl;
+    //cout << "  wrote " << m_actualNumPointsWritten << " points" << endl;
+
+    //cout << "  min X: " << m_minimumX << endl;
+    //cout << "  min Y: " << m_minimumY << endl;
+    //cout << "  min Z: " << m_minimumZ << endl;
+    //cout << "  max X: " << m_maximumX << endl;
+    //cout << "  max Y: " << m_maximumY << endl;
+    //cout << "  max Z: " << m_maximumZ << endl;
+    //
+    //cout << endl;
 
     return;
 }
@@ -103,6 +108,10 @@
             m_maximumX = std::max(m_maximumX, x);
             m_maximumY = std::max(m_maximumY, y);
             m_maximumZ = std::max(m_maximumZ, z);
+
+            m_averageX += x;
+            m_averageY += y;
+            m_averageZ += z;
         }
     }
 
diff -r 13177ebbdcd8 -r d796f3aee4ff test/unit/FauxReaderTest.cpp
--- a/test/unit/FauxReaderTest.cpp	Wed Feb 23 17:59:11 2011 -0800
+++ b/test/unit/FauxReaderTest.cpp	Wed Feb 23 18:00:03 2011 -0800
@@ -3,14 +3,80 @@
 #include <boost/test/unit_test.hpp>
 #include <boost/cstdint.hpp>
 
-#include "libpc/FauxWriter.hpp"
+#include "libpc/FauxReader.hpp"
 
 using namespace libpc;
 
 BOOST_AUTO_TEST_SUITE(FauxReaderTest)
 
-BOOST_AUTO_TEST_CASE(test_ctor)
+BOOST_AUTO_TEST_CASE(test_constant)
 {
+    Bounds<double> bounds(1.0, 2.0, 3.0, 101.0, 102.0, 103.0);
+    FauxReader reader(bounds, 1000, FauxReader::Constant);
+
+    const Schema& schema = reader.getHeader().getSchema();
+    SchemaLayout layout(schema);
+
+    PointData data(layout, 750);
+    
+    boost::uint32_t numRead = reader.readPoints(data);
+
+    BOOST_CHECK(numRead == 750);
+
+    std::size_t offsetX = schema.getDimensionIndex(Dimension::Field_X);
+    std::size_t offsetY = schema.getDimensionIndex(Dimension::Field_Y);
+    std::size_t offsetZ = schema.getDimensionIndex(Dimension::Field_Z);
+    std::size_t offsetT = schema.getDimensionIndex(Dimension::Field_Time);
+
+    for (boost::uint32_t i=0; i<numRead; i++)
+    {
+        float x = data.getField<float>(i, offsetX);
+        float y = data.getField<float>(i, offsetY);
+        float z = data.getField<float>(i, offsetZ);
+        boost::uint64_t t = data.getField<boost::uint64_t>(i, offsetT);
+
+        BOOST_CHECK(x == 1.0);
+        BOOST_CHECK(y == 2.0);
+        BOOST_CHECK(z == 3.0);
+        BOOST_CHECK(t == i);
+    }
+
+    return;
+}
+
+
+BOOST_AUTO_TEST_CASE(test_random)
+{
+    Bounds<double> bounds(1.0, 2.0, 3.0, 101.0, 102.0, 103.0);
+    FauxReader reader(bounds, 1000, FauxReader::Random);
+
+    const Schema& schema = reader.getHeader().getSchema();
+    SchemaLayout layout(schema);
+
+    PointData data(layout, 750);
+    
+    boost::uint32_t numRead = reader.readPoints(data);
+
+    BOOST_CHECK(numRead == 750);
+
+    std::size_t offsetX = schema.getDimensionIndex(Dimension::Field_X);
+    std::size_t offsetY = schema.getDimensionIndex(Dimension::Field_Y);
+    std::size_t offsetZ = schema.getDimensionIndex(Dimension::Field_Z);
+    std::size_t offsetT = schema.getDimensionIndex(Dimension::Field_Time);
+
+    for (boost::uint32_t i=0; i<numRead; i++)
+    {
+        float x = data.getField<float>(i, offsetX);
+        float y = data.getField<float>(i, offsetY);
+        float z = data.getField<float>(i, offsetZ);
+        boost::uint64_t t = data.getField<boost::uint64_t>(i, offsetT);
+
+        BOOST_CHECK(x >= 1.0 && x <= 101.0);
+        BOOST_CHECK(y >= 2.0 && y <= 102.0);
+        BOOST_CHECK(z >= 3.0 && z <= 103.0);
+        BOOST_CHECK(t == i);
+    }
+
     return;
 }
 
diff -r 13177ebbdcd8 -r d796f3aee4ff test/unit/FauxWriterTest.cpp
--- a/test/unit/FauxWriterTest.cpp	Wed Feb 23 17:59:11 2011 -0800
+++ b/test/unit/FauxWriterTest.cpp	Wed Feb 23 18:00:03 2011 -0800
@@ -3,14 +3,59 @@
 #include <boost/test/unit_test.hpp>
 #include <boost/cstdint.hpp>
 
+#include "libpc/FauxReader.hpp"
 #include "libpc/FauxWriter.hpp"
 
 using namespace libpc;
 
 BOOST_AUTO_TEST_SUITE(FauxWriterTest)
 
-BOOST_AUTO_TEST_CASE(test_ctor)
+BOOST_AUTO_TEST_CASE(test_1)
 {
+    Bounds<double> bounds(1.0, 2.0, 3.0, 101.0, 102.0, 103.0);
+    FauxReader reader(bounds, 1000, FauxReader::Constant);
+
+    FauxWriter writer(reader);
+
+    boost::uint64_t numWritten = writer.write(750);
+
+    BOOST_CHECK(numWritten == 750);
+
+    BOOST_CHECK(writer.getMinX() == 1.0);
+    BOOST_CHECK(writer.getMinY() == 2.0);
+    BOOST_CHECK(writer.getMinZ() == 3.0);
+    BOOST_CHECK(writer.getMaxX() == 1.0);
+    BOOST_CHECK(writer.getMaxY() == 2.0);
+    BOOST_CHECK(writer.getMaxZ() == 3.0);
+    BOOST_CHECK(writer.getAvgX() == 1.0);
+    BOOST_CHECK(writer.getAvgY() == 2.0);
+    BOOST_CHECK(writer.getAvgZ() == 3.0);
+
+    return;
+}
+
+BOOST_AUTO_TEST_CASE(test_2)
+{
+    Bounds<double> bounds(1.0, 2.0, 3.0, 101.0, 102.0, 103.0);
+    FauxReader reader(bounds, 1000, FauxReader::Random);
+
+    FauxWriter writer(reader);
+
+    boost::uint64_t numWritten = writer.write(750);
+
+    BOOST_CHECK(numWritten == 750);
+
+    // test all the values to +/- 1.0
+    BOOST_CHECK(Utils::compare_approx<float>(writer.getMinX(), 1.0, 1.0));
+    BOOST_CHECK(Utils::compare_approx<float>(writer.getMinY(), 2.0, 1.0));
+    BOOST_CHECK(Utils::compare_approx<float>(writer.getMinZ(), 3.0, 1.0));
+    BOOST_CHECK(Utils::compare_approx<float>(writer.getMaxX(), 101.0, 1.0));
+    BOOST_CHECK(Utils::compare_approx<float>(writer.getMaxY(), 102.0, 1.0));
+    BOOST_CHECK(Utils::compare_approx<float>(writer.getMaxZ(), 103.0, 1.0));
+    BOOST_CHECK(Utils::compare_approx<float>(writer.getAvgX(), 51.0, 1.0));
+    BOOST_CHECK(Utils::compare_approx<float>(writer.getAvgY(), 52.0, 1.0));
+    BOOST_CHECK(Utils::compare_approx<float>(writer.getAvgZ(), 53.0, 1.0));
+
     return;
 }
 


More information about the Liblas-commits mailing list