DoorKeeper/test/unit/vector.cpp
2015-08-19 21:06:58 +02:00

76 lines
1.9 KiB
C++

/* Copyright 2015, Michele Santullo
* This file is part of DoorKeeper.
*
* DoorKeeper 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 3 of the License, or
* (at your option) any later version.
*
* DoorKeeper 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 DoorKeeper. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include "doorkeeper/primitivetypes.hpp"
TEST(vector, misc) {
typedef dk::Vector<2> coords2;
typedef dk::Vector<3> coords3;
typedef dk::Vector<8> coords8;
EXPECT_EQ(coords2::dimensions, 2);
EXPECT_EQ(coords3::dimensions, 3);
EXPECT_EQ(coords8::dimensions, 8);
{
const coords2 small(5, 6);
EXPECT_EQ(small.x(), 5);
EXPECT_EQ(small.y(), 6);
const coords2 med(1200, 4000);
EXPECT_LT(small, med);
EXPECT_LE(small, med);
EXPECT_GT(med, small);
EXPECT_GE(med, small);
const coords2 big(10000, 12345);
EXPECT_GT(big, med);
EXPECT_GT(big, small);
EXPECT_LT(small, big);
const coords2 med2_a(1200, 4001);
EXPECT_LE(med, med2_a);
EXPECT_GE(med2_a, med);
EXPECT_FALSE(med2_a < med);
EXPECT_FALSE(med2_a == med);
EXPECT_FALSE(med > med2_a);
}
{
const coords8 small(1, 2, 3, 4, 5, 6, 7, 8);
const coords8 big(small * 100);
for (int z = 0; z < coords8::dimensions; ++z) {
EXPECT_EQ(big[z], (z + 1) * 100);
}
EXPECT_LT(small, big);
}
{
coords3 vec(1, 2, 3);
vec += coords3(3, 2, 1);
EXPECT_EQ(vec, coords3(4));
vec *= 3;
EXPECT_EQ(vec, coords3(12));
vec = coords3(2, 4, 8) / 2;
EXPECT_EQ(vec, coords3(1, 2, 4));
}
}