Fixed defects found in the review coordinate_classes
authorSami Rämö <sami.ramo@ixonos.com>
Tue, 20 Jul 2010 11:29:31 +0000 (14:29 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Tue, 20 Jul 2010 11:29:31 +0000 (14:29 +0300)
 - Reviewed by Jussi Laitinen

 - Review was only done for new classes, unit tests and for some
   biggest implementation changes

src/coordinates/geocoordinate.cpp
src/coordinates/scenecoordinate.cpp
src/coordinates/scenecoordinate.h
tests/coordinates/geocoordinate/testgeocoordinate.cpp

index 5a521df..ddf2d99 100644 (file)
@@ -79,7 +79,7 @@ bool GeoCoordinate::isNull() const
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (m_latitude == 0 && m_longitude == 0)
+    if ((m_latitude == 0) && (m_longitude == 0))
         return true;
 
     return false;
@@ -95,8 +95,8 @@ bool GeoCoordinate::isValid()
     const double MAX_LONGITUDE = 180.0;
 
     if ((m_validityFlags & LatitudeSet) && (m_validityFlags & LongitudeSet) &&
-        (m_latitude >= MIN_LATITUDE) && (m_latitude < MAX_LATITUDE) &&
-        (m_longitude >= MIN_LONGITUDE) && (m_longitude < MAX_LONGITUDE))
+        (m_latitude >= MIN_LATITUDE) && (m_latitude <= MAX_LATITUDE) &&
+        (m_longitude >= MIN_LONGITUDE) && (m_longitude <= MAX_LONGITUDE))
 
         return true;
     else
index 7bfdb4e..fbe4204 100644 (file)
@@ -128,6 +128,13 @@ SceneCoordinate::operator QVariant() const
     return QVariant::fromValue(*this);
 }
 
+QDebug operator<<(QDebug dbg, const SceneCoordinate &coordinate)
+{
+    dbg.nospace() << "(" << coordinate.x() << ", " << coordinate.y() << ")";
+
+    return dbg.space();
+}
+
 SceneCoordinate & SceneCoordinate::operator*=(double factor)
 {
     m_x *= factor;
index aaf66dd..8d823c8 100644 (file)
@@ -117,7 +117,7 @@ private:
      *
      *    scene has 2^18 * 256 - 1 = 67108864 pixels per side
      *    one pixel width is 360º / 67108864 = 0.00000536441802978516º
-     *    so the last scene pixel is 180º - 0.00000536441802978516º = 179.99999463558197021484º     *
+     *    so the last scene pixel is 180º - 0.00000536441802978516º = 179.99999463558197021484º
      *
      * @param coordinate Geological coordinate
      */
@@ -183,7 +183,7 @@ public:
 /**
 * @brief Operator for writing the coordinate to QDebug stream.
 */
-QDebug operator<<(QDebug dbg, const SceneCoordinate &c);
+QDebug operator<<(QDebug dbg, const SceneCoordinate &coordinate);
 
 /**
 * @brief Returns a SceneCoordinate object that is multiplied by the given factor.
index e1753a6..d4b99c6 100644 (file)
@@ -41,6 +41,8 @@ private Q_SLOTS:
     void conversion();
     void conversion_data();
     void isNullAndIsValid();
+    void isValid();
+    void isValid_data();
     void settersAndGetters();
     void streamOperators();
 };
@@ -140,6 +142,30 @@ void TestGeoCoordinate::isNullAndIsValid()
     QVERIFY(coordinate5.isValid());
 }
 
+void TestGeoCoordinate::isValid()
+{
+    QFETCH(GeoCoordinate, coordinate);
+    QFETCH(bool, expectedValidity);
+
+    QCOMPARE(coordinate.isValid(), expectedValidity);
+}
+
+void TestGeoCoordinate::isValid_data()
+{
+    QTest::addColumn<GeoCoordinate>("coordinate");
+    QTest::addColumn<bool>("expectedValidity");
+
+    QTest::newRow("null") << GeoCoordinate(0, 0) << true;
+    QTest::newRow("min latitude") << GeoCoordinate(-90, 0) << true;
+    QTest::newRow("latitude too small") << GeoCoordinate(-90.000000001, 0) << false;
+    QTest::newRow("mad latitude") << GeoCoordinate(90, 0) << true;
+    QTest::newRow("latitude too big") << GeoCoordinate(90.000000001, 0) << false;
+    QTest::newRow("min longitude") << GeoCoordinate(0, -180) << true;
+    QTest::newRow("longitude too small") << GeoCoordinate(0, -180.0000000001) << false;
+    QTest::newRow("max longitude") << GeoCoordinate(0, 180) << true;
+    QTest::newRow("longitude too big") << GeoCoordinate(0, 180.0000000001) << false;
+}
+
 void TestGeoCoordinate::settersAndGetters()
 {
     GeoCoordinate coordinate;