Fix vector comparison and add unit test.
This commit is contained in:
parent
6aa4d15381
commit
971cd54688
3 changed files with 39 additions and 14 deletions
|
@ -199,35 +199,27 @@ namespace cloonel {
|
|||
///--------------------------------------------------------------------------
|
||||
template <typename T, typename U, uint32_t S>
|
||||
inline bool operator< (const Vector<T, S>& parA, const Vector<U, S>& parB) {
|
||||
bool retVal = false;
|
||||
bool retVal = true;
|
||||
for (uint32_t z = 0; z < S; ++z) {
|
||||
retVal |= static_cast<bool>(parA[z] < parB[z]);
|
||||
retVal &= static_cast<bool>(parA[z] < parB[z]);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
template <typename T, typename U, uint32_t S>
|
||||
inline bool operator> (const Vector<T, S>& parA, const Vector<U, S>& parB) {
|
||||
bool retVal = false;
|
||||
for (uint32_t z = 0; z < S; ++z) {
|
||||
retVal |= static_cast<bool>(parA[z] > parB[z]);
|
||||
}
|
||||
return retVal;
|
||||
return not (parA <= parB);
|
||||
}
|
||||
template <typename T, typename U, uint32_t S>
|
||||
inline bool operator<= (const Vector<T, S>& parA, const Vector<U, S>& parB) {
|
||||
bool retVal = false;
|
||||
bool retVal = true;
|
||||
for (uint32_t z = 0; z < S; ++z) {
|
||||
retVal |= static_cast<bool>(parA[z] <= parB[z]);
|
||||
retVal &= static_cast<bool>(parA[z] <= parB[z]);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
template <typename T, typename U, uint32_t S>
|
||||
inline bool operator>= (const Vector<T, S>& parA, const Vector<U, S>& parB) {
|
||||
bool retVal = false;
|
||||
for (uint32_t z = 0; z < S; ++z) {
|
||||
retVal |= static_cast<bool>(parA[z] >= parB[z]);
|
||||
}
|
||||
return retVal;
|
||||
return not (parA < parB);
|
||||
}
|
||||
template <typename T, typename U, uint32_t S>
|
||||
inline bool operator== (const Vector<T, S>& parA, const Vector<U, S>& parB) {
|
||||
|
|
|
@ -11,6 +11,7 @@ include_directories(SYSTEM
|
|||
add_executable(${PROJECT_NAME}
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../gtest-1.7.0/src/gtest_main.cc"
|
||||
tilecoords.cpp
|
||||
vector.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
|
|
32
test/unit/vector.cpp
Normal file
32
test/unit/vector.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include "doorkeeper/primitivetypes.hpp"
|
||||
|
||||
|
||||
TEST(misc, vector) {
|
||||
{
|
||||
typedef dk::Vector<2> coords2;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue