Added operator== to KKJ class.
authorAki Koskinen <maemo@akikoskinen.info>
Sun, 28 Mar 2010 10:55:04 +0000 (13:55 +0300)
committerAki Koskinen <maemo@akikoskinen.info>
Sun, 28 Mar 2010 16:32:33 +0000 (19:32 +0300)
Refactored the KKJ test to use a test fixture for the setup.

src/kkj.cpp
src/kkj.h
tests/ut_kkj/ut_kkj.cpp

index 2724ce0..5961353 100644 (file)
@@ -32,6 +32,11 @@ KKJ::~KKJ()
 {
 }
 
+bool KKJ::operator==(const KKJ &rhs) const
+{
+    return northing() == rhs.northing() && easting() == rhs.easting();
+}
+
 unsigned int KKJ::northing() const
 {
     Q_D(const KKJ);
index ac148fa..5daddde 100644 (file)
--- a/src/kkj.h
+++ b/src/kkj.h
@@ -24,6 +24,15 @@ public:
     virtual ~KKJ();
 
     /**
+     * Equals operator.
+     * Tests the equality of this coordinate and another coordinate and returns \c true
+     * if the coordinates represent the same position.
+     * @param rhs the other coordinate to test against.
+     * @return \c true if the coordinates are the same, \c false otherwise.
+     */
+    bool operator==(const KKJ &rhs) const;
+
+    /**
      * Returns the northing of the coordinate.
      * @return the northing.
      */
index 36cac34..22ec962 100644 (file)
@@ -3,15 +3,47 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
-TEST(KKJ, ConstructorValuesReceivedViaGetters)
+class KKJTest : public ::testing::Test
+{
+public:
+    const unsigned int northing;
+    const unsigned int easting;
+
+    KKJTest() :
+        northing(6682815),
+        easting(2556686)
+    {
+    }
+};
+
+TEST_F(KKJTest, ConstructorValuesReceivedViaGetters)
 {
-    unsigned int northing = 6682815;
-    unsigned int easting = 2556686;
     KKJ kkj(northing , easting);
     ASSERT_EQ(northing, kkj.northing());
     ASSERT_EQ(easting, kkj.easting());
 }
 
+TEST_F(KKJTest, EqualsOperatorReturnsTrueForEqualCoordinates)
+{
+    KKJ kkj1(northing, easting);
+    KKJ kkj2(northing, easting);
+    ASSERT_TRUE(kkj1 == kkj2);
+}
+
+TEST_F(KKJTest, EqualsOperatorReturnsFalseForCoordinatesWithDifferentNorthing)
+{
+    KKJ kkj1(northing - 1, easting);
+    KKJ kkj2(northing, easting);
+    ASSERT_FALSE(kkj1 == kkj2);
+}
+
+TEST_F(KKJTest, EqualsOperatorReturnsFalseForCoordinatesWithDifferentEasting)
+{
+    KKJ kkj1(northing, easting - 1);
+    KKJ kkj2(northing, easting);
+    ASSERT_FALSE(kkj1 == kkj2);
+}
+
 int main(int argc, char *argv[])
 {
     ::testing::InitGoogleMock(&argc, argv);