aboutsummaryrefslogblamecommitdiffstats
path: root/test/utils/point.cpp
blob: 6284ea2c6a48c79529e6a871f9536b7f8038b716 (plain) (tree)
























































                                                                        





                                                              






                                                            





                                                              






                                                            



                                                              






                                                            



                                                              







                                                                        
/*
 * 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 <exception>
#include <cppunit/extensions/HelperMacros.h>
#include <log4cpp/Category.hh>

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<int> p1(100, 200), p2(50, 70);
			Point<int> p3 = p1 + p2;

			CPPUNIT_ASSERT_EQUAL(p1.get_x(), 100);
			CPPUNIT_ASSERT_EQUAL(p1.get_y(), 200);
			CPPUNIT_ASSERT_EQUAL(p2.get_x(), 50);
			CPPUNIT_ASSERT_EQUAL(p2.get_y(), 70);
			CPPUNIT_ASSERT_EQUAL(p3.get_x(), 150);
			CPPUNIT_ASSERT_EQUAL(p3.get_y(), 270);
		}

		void testDiff()
		{
			Point<int> p1(100, 200), p2(50, 70);
			Point<int> p3 = p1 - p2;

			CPPUNIT_ASSERT_EQUAL(p1.get_x(), 100);
			CPPUNIT_ASSERT_EQUAL(p1.get_y(), 200);
			CPPUNIT_ASSERT_EQUAL(p2.get_x(), 50);
			CPPUNIT_ASSERT_EQUAL(p2.get_y(), 70);
			CPPUNIT_ASSERT_EQUAL(p3.get_x(), 50);
			CPPUNIT_ASSERT_EQUAL(p3.get_y(), 130);
		}

		void testCompoundSum()
		{
			Point<int> p1(100, 200), p2(50, 70);
			p1 += p2;

			CPPUNIT_ASSERT_EQUAL(p1.get_x(), 150);
			CPPUNIT_ASSERT_EQUAL(p1.get_y(), 270);
			CPPUNIT_ASSERT_EQUAL(p2.get_x(), 50);
			CPPUNIT_ASSERT_EQUAL(p2.get_y(), 70);
		}

		void testCompoundDiff()
		{
			Point<int> p1(100, 200), p2(50, 70);
			p1 -= p2;

			CPPUNIT_ASSERT_EQUAL(p1.get_x(), 50);
			CPPUNIT_ASSERT_EQUAL(p1.get_y(), 130);
			CPPUNIT_ASSERT_EQUAL(p2.get_x(), 50);
			CPPUNIT_ASSERT_EQUAL(p2.get_y(), 70);
		}
	};

	log4cpp::Category&  PointTest::log =
		log4cpp::Category::getInstance("test.usdx.utils.point");

	CPPUNIT_TEST_SUITE_REGISTRATION(PointTest);
};