1 #include "VectorTest.h"
5 CPPUNIT_TEST_SUITE_REGISTRATION(test_math::VectorTest);
12 void VectorTest::setUp() {
16 void VectorTest::tearDown() {
21 void VectorTest::testComparison() {
22 CPPUNIT_ASSERT_EQUAL(Vector<int>(0, 0), Vector<int>(0, 0));
24 CPPUNIT_ASSERT(Vector<int>(0, 0) != Vector<int>(0, 1));
25 CPPUNIT_ASSERT(Vector<int>(0, 0) != Vector<int>(1, 0));
26 CPPUNIT_ASSERT(Vector<int>(0, 0) != Vector<int>(1, 1));
29 void VectorTest::testSum() {
32 Vector<int>(1, 1) + Vector<int>(0, 0));
35 Vector<int>(0, 1) + Vector<int>(1, 0));
39 Vector<int>(1, 1) - Vector<int>(0, 0));
42 Vector<int>(1, 1) - Vector<int>(1, 0));
45 void VectorTest::testProduct() {
48 Vector<int>(2, 3) * Vector<int>(1, 1));
51 Vector<int>(2, 3) * Vector<int>(5, 4));
54 Vector<int>(2, 3) * 1);
57 Vector<int>(2, 3) * 2);
60 1 * Vector<int>(2, 3));
63 2 * Vector<int>(2, 3));
67 Vector<int>(10, 12) / Vector<int>(1, 1));
70 Vector<int>(10, 12) / Vector<int>(5, 4));
73 Vector<int>(4, 6) / 1);
76 Vector<int>(4, 6) / 2);
79 12 / Vector<int>(4, 3));
82 void VectorTest::testModulo() {
85 Vector<int>(1, 2) % Vector<int>(1, 1));
88 Vector<int>(1, 2) % 1);
91 Vector<int>(3, 5) % Vector<int>(4, 2));
94 Vector<int>(3, 5) % 4);
96 Vector<float> vecf = Vector<float>(4.0f, 5.0f) % Vector<float>(2.0f, 3.0f);
97 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, vecf.X(), std::numeric_limits<float>::epsilon());
98 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0f, vecf.Y(), std::numeric_limits<float>::epsilon());
100 vecf = Vector<float>(4.0f, 5.0f) % 4.0f;
101 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, vecf.X(), std::numeric_limits<float>::epsilon());
102 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0f, vecf.Y(), std::numeric_limits<float>::epsilon());
104 Vector<double> vecd = Vector<double>(4.0, 5.0) % Vector<double>(2.0, 3.0);
105 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, vecd.X(), std::numeric_limits<double>::epsilon());
106 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, vecd.Y(), std::numeric_limits<double>::epsilon());
108 vecd = Vector<double>(4.0, 5.0) % 4.0;
109 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, vecd.X(), std::numeric_limits<double>::epsilon());
110 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, vecd.Y(), std::numeric_limits<double>::epsilon());
113 void VectorTest::testFunctional() {
114 const Vector<int> vec(2, 5);
115 CPPUNIT_ASSERT_EQUAL(2, vec.X());
116 CPPUNIT_ASSERT_EQUAL(5, vec.Y());
117 CPPUNIT_ASSERT_EQUAL(52, vec.Index(10));
119 const Vector<int> indexVec = Vector<int>::FromIndex(52, 10);
120 CPPUNIT_ASSERT_EQUAL(vec, indexVec);
122 Vector<int> lockedVec = Vector<int>(vec);
123 lockedVec.Lock(Vector<int>(2, 2));
124 CPPUNIT_ASSERT_EQUAL(Vector<int>(2, 4), lockedVec);