From 14989ee5a4bf1c60cb1455500f3dfabfa22441cb Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 21 Mar 2012 15:50:09 +0100 Subject: tests: added test of operator overloading for point --- test/utils/point.cpp | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 test/utils/point.cpp (limited to 'test') diff --git a/test/utils/point.cpp b/test/utils/point.cpp new file mode 100644 index 00000000..64fa2216 --- /dev/null +++ b/test/utils/point.cpp @@ -0,0 +1,106 @@ +/* + * UltraStar Deluxe - Karaoke Game + * + * UltraStar Deluxe is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + */ + +#include "point.hpp" + +#include +#include +#include + +namespace usdx +{ + class PointTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(PointTest); + CPPUNIT_TEST(testSum); + CPPUNIT_TEST(testDiff); + CPPUNIT_TEST(testCompoundSum); + CPPUNIT_TEST(testCompoundDiff); + CPPUNIT_TEST_SUITE_END(); + private: + static log4cpp::Category& log; + public: + void setUp() + { + } + + void tearDown() + { + } + + void testSum() + { + Point p1(100, 200), p2(50, 70); + Point p3 = p1 + p2; + + CPPUNIT_ASSERT(p1.get_x() == 100); + CPPUNIT_ASSERT(p1.get_y() == 200); + CPPUNIT_ASSERT(p2.get_x() == 50); + CPPUNIT_ASSERT(p2.get_y() == 70); + CPPUNIT_ASSERT(p3.get_x() == 150); + CPPUNIT_ASSERT(p3.get_y() == 270); + } + + void testDiff() + { + Point p1(100, 200), p2(50, 70); + Point p3 = p1 - p2; + + CPPUNIT_ASSERT(p1.get_x() == 100); + CPPUNIT_ASSERT(p1.get_y() == 200); + CPPUNIT_ASSERT(p2.get_x() == 50); + CPPUNIT_ASSERT(p2.get_y() == 70); + CPPUNIT_ASSERT(p3.get_x() == 50); + CPPUNIT_ASSERT(p3.get_y() == 130); + } + + void testCompoundSum() + { + Point p1(100, 200), p2(50, 70); + p1 += p2; + + CPPUNIT_ASSERT(p1.get_x() == 150); + CPPUNIT_ASSERT(p1.get_y() == 270); + CPPUNIT_ASSERT(p2.get_x() == 50); + CPPUNIT_ASSERT(p2.get_y() == 70); + } + + void testCompoundDiff() + { + Point p1(100, 200), p2(50, 70); + p1 -= p2; + + CPPUNIT_ASSERT(p1.get_x() == 50); + CPPUNIT_ASSERT(p1.get_y() == 130); + CPPUNIT_ASSERT(p2.get_x() == 50); + CPPUNIT_ASSERT(p2.get_y() == 70); + } + }; + + log4cpp::Category& PointTest::log = + log4cpp::Category::getInstance("test.usdx.utils.point"); + + CPPUNIT_TEST_SUITE_REGISTRATION(PointTest); +}; -- cgit v1.2.3