Added equality/inequality tests for vector and region.
This commit is contained in:
parent
ddc54e0862
commit
7bbdb1a29d
@ -44,6 +44,11 @@ namespace PolyVox
|
||||
Region(const Vector3DInt32& v3dLowerCorner, const Vector3DInt32& v3dUpperCorner);
|
||||
Region(int32_t iLowerX, int32_t iLowerY, int32_t iLowerZ, int32_t iUpperX, int32_t iUpperY, int32_t iUpperZ);
|
||||
|
||||
///Equality Operator.
|
||||
bool operator==(const Region& rhs) const throw();
|
||||
///Inequality Operator.
|
||||
bool operator!=(const Region& rhs) const throw();
|
||||
|
||||
const Vector3DInt32& getLowerCorner(void) const;
|
||||
const Vector3DInt32& getUpperCorner(void) const;
|
||||
|
||||
|
@ -81,6 +81,8 @@ namespace PolyVox
|
||||
Vector<Size,Type>& operator=(const Vector<Size,Type>& rhs) throw();
|
||||
///Equality Operator.
|
||||
bool operator==(const Vector<Size,Type>& rhs) const throw();
|
||||
///Inequality Operator.
|
||||
bool operator!=(const Vector<Size,Type>& rhs) const throw();
|
||||
///Comparison Operator.
|
||||
bool operator<(const Vector<Size,Type>& rhs) const throw();
|
||||
///Addition and Assignment Operator.
|
||||
|
@ -150,6 +150,18 @@ namespace PolyVox
|
||||
return equal;
|
||||
}
|
||||
|
||||
/**
|
||||
Checks whether two Vectors are not equal.
|
||||
\param rhs The Vector to compare to.
|
||||
\return true if the Vectors do not match.
|
||||
\see operator==
|
||||
*/
|
||||
template <uint32_t Size, typename Type>
|
||||
inline bool Vector<Size, Type>::operator!=(const Vector<Size, Type> &rhs) const throw()
|
||||
{
|
||||
return !(*this == rhs); //Just call equality operator and invert the result.
|
||||
}
|
||||
|
||||
/**
|
||||
Checks whether this vector is less than the parameter. The metric is
|
||||
meaningless but it allows Vectors to me used as key in sdt::map, etc.
|
||||
|
@ -60,6 +60,28 @@ namespace PolyVox
|
||||
assert(m_v3dUpperCorner.getZ() >= m_v3dLowerCorner.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
Checks whether two Regions are equal.
|
||||
\param rhs The Region to compare to.
|
||||
\return true if the Regions match.
|
||||
\see operator!=
|
||||
*/
|
||||
bool Region::operator==(const Region& rhs) const throw()
|
||||
{
|
||||
return ((m_v3dLowerCorner == rhs.m_v3dLowerCorner) && (m_v3dUpperCorner == rhs.m_v3dUpperCorner));
|
||||
}
|
||||
|
||||
/**
|
||||
Checks whether two Regions are not equal.
|
||||
\param rhs The Region to compare to.
|
||||
\return true if the Regions do not match.
|
||||
\see operator==
|
||||
*/
|
||||
bool Region::operator!=(const Region& rhs) const throw()
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
const Vector3DInt32& Region::getLowerCorner(void) const
|
||||
{
|
||||
return m_v3dLowerCorner;
|
||||
|
@ -59,10 +59,15 @@ ADD_TEST(VolumeSizeTest ${LATEST_TEST} testSize)
|
||||
CREATE_TEST(testmaterial.h testmaterial.cpp testmaterial)
|
||||
ADD_TEST(MaterialTestCompile ${LATEST_TEST} testCompile)
|
||||
|
||||
# Region tests
|
||||
CREATE_TEST(TestRegion.h TestRegion.cpp TestRegion)
|
||||
ADD_TEST(RegionEqualityTest ${LATEST_TEST} testEquality)
|
||||
|
||||
#Vector tests
|
||||
CREATE_TEST(testvector.h testvector.cpp testvector)
|
||||
ADD_TEST(VectorLengthTest ${LATEST_TEST} testLength)
|
||||
ADD_TEST(VectorDotProductTest ${LATEST_TEST} testDotProduct)
|
||||
ADD_TEST(VectorEqualityTest ${LATEST_TEST} testEquality)
|
||||
|
||||
# Volume subclass tests
|
||||
CREATE_TEST(TestVolumeSubclass.h TestVolumeSubclass.cpp TestVolumeSubclass)
|
||||
|
42
tests/TestRegion.cpp
Normal file
42
tests/TestRegion.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2010 Matt Williams
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#include "TestRegion.h"
|
||||
|
||||
#include "PolyVoxCore/Region.h"
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
using namespace PolyVox;
|
||||
|
||||
void TestRegion::testEquality()
|
||||
{
|
||||
Region reg1(1,2,3,4,5,6);
|
||||
Region reg2(0,0,0,10,20,30);
|
||||
Region reg3(Vector3DInt32(1,2,3), Vector3DInt32(4,5,6));
|
||||
|
||||
QCOMPARE(reg1 != reg2, true);
|
||||
QCOMPARE(reg1 == reg3, true);
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestRegion)
|
37
tests/TestRegion.h
Normal file
37
tests/TestRegion.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2010 Matt Williams
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __PolyVox_TestRegion_H__
|
||||
#define __PolyVox_TestRegion_H__
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class TestRegion: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void testEquality();
|
||||
};
|
||||
|
||||
#endif
|
@ -43,4 +43,12 @@ void TestVector::testDotProduct()
|
||||
QCOMPARE(vecxy.dot(vecz), int8_t(0)); //QCOMPARE is very strict on the types matching
|
||||
}
|
||||
|
||||
void TestVector::testEquality()
|
||||
{
|
||||
Vector3DInt8 vecxy(3, 4, 0);
|
||||
Vector3DInt8 vecz(0, 0, 1);
|
||||
|
||||
QCOMPARE(vecxy != vecz, true);
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestVector)
|
||||
|
@ -33,6 +33,7 @@ class TestVector: public QObject
|
||||
private slots:
|
||||
void testLength();
|
||||
void testDotProduct();
|
||||
void testEquality();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user