From: Aki Koskinen Date: Sun, 28 Mar 2010 10:55:04 +0000 (+0300) Subject: Added operator== to KKJ class. X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;ds=sidebyside;h=9f14a8e6efc2c3b97abee4e99694fcf8eb9c983a;p=ptas Added operator== to KKJ class. Refactored the KKJ test to use a test fixture for the setup. --- diff --git a/src/kkj.cpp b/src/kkj.cpp index 2724ce0..5961353 100644 --- a/src/kkj.cpp +++ b/src/kkj.cpp @@ -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); diff --git a/src/kkj.h b/src/kkj.h index ac148fa..5daddde 100644 --- 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. */ diff --git a/tests/ut_kkj/ut_kkj.cpp b/tests/ut_kkj/ut_kkj.cpp index 36cac34..22ec962 100644 --- a/tests/ut_kkj/ut_kkj.cpp +++ b/tests/ut_kkj/ut_kkj.cpp @@ -3,15 +3,47 @@ #include #include -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);