Added unit test for Array class.
This commit is contained in:
parent
8240d477bd
commit
5e687fbd58
@ -42,7 +42,7 @@ namespace PolyVox
|
||||
|
||||
public:
|
||||
Array<noOfDims, ElementType>(const uint32_t (&Dimensions)[noOfDims])
|
||||
: m_pElements(0)
|
||||
:m_pElements(0)
|
||||
,m_pDimensions(0)
|
||||
,m_pOffsets(0)
|
||||
,m_uNoOfElements(0)
|
||||
@ -75,8 +75,8 @@ namespace PolyVox
|
||||
Array<noOfDims-1, ElementType>(&m_pElements[uIndex*m_pOffsets[0]],
|
||||
m_pDimensions+1, m_pOffsets+1);
|
||||
}
|
||||
const Array<noOfDims-1, ElementType>
|
||||
operator [](uint32_t uIndex) const
|
||||
|
||||
const Array<noOfDims-1, ElementType> operator [](uint32_t uIndex) const
|
||||
{
|
||||
assert(uIndex<m_pDimensions[0]);
|
||||
return
|
||||
|
@ -21,11 +21,15 @@ INCLUDE(${QT_USE_FILE})
|
||||
|
||||
INCLUDE_DIRECTORIES(${PolyVox_SOURCE_DIR}/PolyVoxCore/include ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
# Volume tests
|
||||
CREATE_TEST(testvolume.h testvolume.cpp testvolume)
|
||||
ADD_TEST(VolumeSizeTest ${LATEST_TEST} testSize)
|
||||
# Array tests
|
||||
CREATE_TEST(TestArray.h TestArray.cpp TestArray)
|
||||
ADD_TEST(ArrayReadWriteTest ${LATEST_TEST} testReadWrite)
|
||||
|
||||
#Vector tests
|
||||
CREATE_TEST(testvector.h testvector.cpp testvector)
|
||||
ADD_TEST(VectorLengthTest ${LATEST_TEST} testLength)
|
||||
ADD_TEST(VectorDotProductTest ${LATEST_TEST} testDotProduct)
|
||||
|
||||
# Volume tests
|
||||
CREATE_TEST(testvolume.h testvolume.cpp testvolume)
|
||||
ADD_TEST(VolumeSizeTest ${LATEST_TEST} testSize)
|
||||
|
82
tests/TestArray.cpp
Normal file
82
tests/TestArray.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
/*******************************************************************************
|
||||
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 "TestArray.h"
|
||||
|
||||
#include <Array.h>
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
using namespace PolyVox;
|
||||
|
||||
void TestArray::testReadWrite()
|
||||
{
|
||||
int width = 5;
|
||||
int height = 10;
|
||||
int depth = 20;
|
||||
|
||||
Array<3, int> myArray(ArraySizes(width)(height)(depth));
|
||||
|
||||
int ct = 1;
|
||||
int expectedTotal = 0;
|
||||
for(int z = 0; z < depth; z++)
|
||||
{
|
||||
for(int y = 0; y < height; y++)
|
||||
{
|
||||
for(int x = 0; x < width; x++)
|
||||
{
|
||||
myArray[x][y][z] = ct;
|
||||
expectedTotal += myArray[x][y][z];
|
||||
ct++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ct = 1;
|
||||
int total = 0;
|
||||
for(int z = 0; z < depth; z++)
|
||||
{
|
||||
for(int y = 0; y < height; y++)
|
||||
{
|
||||
for(int x = 0; x < width; x++)
|
||||
{
|
||||
QCOMPARE(myArray[x][y][z], ct);
|
||||
total += myArray[x][y][z];
|
||||
ct++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QCOMPARE(total, expectedTotal);
|
||||
|
||||
/*const PolyVox::uint16_t g_uVolumeSideLength = 128;
|
||||
Volume<PolyVox::uint8_t> volData(g_uVolumeSideLength, g_uVolumeSideLength, g_uVolumeSideLength);
|
||||
|
||||
volData.tidyUpMemory(0);
|
||||
|
||||
QCOMPARE(volData.getWidth(), g_uVolumeSideLength);
|
||||
QCOMPARE(volData.getHeight(), g_uVolumeSideLength);
|
||||
QCOMPARE(volData.getDepth(), g_uVolumeSideLength);*/
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestArray)
|
37
tests/TestArray.h
Normal file
37
tests/TestArray.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_TestVolume_H__
|
||||
#define __PolyVox_TestVolume_H__
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class TestArray: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void testReadWrite();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user