/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */ /* Author(s): Anton Deguet Created on: 2003-08-20 (C) Copyright 2003-2013 Johns Hopkins University (JHU), All Rights Reserved. --- begin cisst license - do not edit --- This software is provided "as is" under an open source license, with no warranty. The complete license can be found in license.txt and http://www.cisst.org/cisst/license.txt. --- end cisst license --- */ #include "vctFixedSizeVectorTest.h" #include "vctGenericContainerTest.h" #include "vctGenericVectorTest.h" #include #include #include #include #include #include void vctFixedSizeVectorTest::TestSubsequence(void) { typedef float ElementType; enum {SIZE0 = 14}; enum {STRIDE1=3, POSITION1=1, SIZE1= (SIZE0 - POSITION1) / STRIDE1 + ( ((SIZE0-POSITION1)%STRIDE1) != 0) }; enum {STRIDE2=2, POSITION2=0, SIZE2= (SIZE1 - POSITION2) / STRIDE2 + ( ((SIZE1-POSITION2)%STRIDE2) != 0) }; typedef vctFixedSizeVector VectorType; /* build an initial array */ VectorType initialArray; unsigned int i; for (i = 0; i < initialArray.size(); ++i) { initialArray[i] = (ElementType) i; } /* use an iterator to browse the elements */ i = 0; VectorType::iterator elementIterator = initialArray.begin(); for (; elementIterator != initialArray.end(); ++elementIterator) { CPPUNIT_ASSERT(((*elementIterator) == initialArray[i])); CPPUNIT_ASSERT((*elementIterator) == (ElementType) i); i++; } /* get a subsequence and make sure the elements match */ typedef vctFixedSizeVectorRef Subsequence1Type; int initialPosition1 = POSITION1; Subsequence1Type subsequence1(initialArray.Pointer(initialPosition1)); Subsequence1Type::const_iterator subsequence1Iterator = subsequence1.begin(); i = 0; for (; subsequence1Iterator != subsequence1.end(); ++subsequence1Iterator) { CPPUNIT_ASSERT( (*subsequence1Iterator) == initialArray[POSITION1 + i * STRIDE1] ); i++; } /* modify the last element of the subsequence and make use the initial array is modified */ subsequence1[SIZE1 - 1]++; CPPUNIT_ASSERT( subsequence1[SIZE1 - 1] == initialArray[POSITION1 + (SIZE1 - 1) * STRIDE1]); /* get a subsequence of the subsequence */ typedef vctFixedSizeConstVectorRef Subsequence2Type; int initialPosition2 = POSITION2; Subsequence2Type subsequence2(subsequence1.Pointer(initialPosition2)); i = 0; Subsequence2Type::const_iterator subsequence2Iterator = ((const Subsequence2Type &)subsequence2).begin(); for (; subsequence2Iterator != subsequence2.end(); ++subsequence2Iterator) { CPPUNIT_ASSERT( *subsequence2Iterator == subsequence1[POSITION2 + i * STRIDE2] ); CPPUNIT_ASSERT( *subsequence2Iterator == initialArray[POSITION1 + POSITION2 + i * STRIDE1 * STRIDE2] ); i++; } /* test the reverse iterator on the initial array */ VectorType::const_reverse_iterator reverseIterator = initialArray.rbegin(); i = SIZE0 - 1; for (; reverseIterator != initialArray.rend(); ++reverseIterator) { /* special case because the last element has been modified */ if (reverseIterator == initialArray.rbegin()) { CPPUNIT_ASSERT( (*reverseIterator) == (i + 1) ); } else { CPPUNIT_ASSERT( (*reverseIterator) == i ); } CPPUNIT_ASSERT( (*reverseIterator) == initialArray[i] ); i--; } } template void vctFixedSizeVectorTest::TestConcatenation(void) { typedef vctFixedSizeVector<_elementType, 3> VectorType3; typedef vctFixedSizeVector<_elementType, 4> VectorType4; unsigned int i; VectorType3 testVector3; VectorType4 testVector4; _elementType refVector[4] = {_elementType(122), _elementType(-25), _elementType(33), _elementType(-10)}; testVector3.Assign(refVector[0], refVector[1], refVector[2]); testVector4.ConcatenationOf(testVector3, -10); for (i = 0; i < testVector4.size(); i++) { CPPUNIT_ASSERT(refVector[i] == testVector4[i]); } } void vctFixedSizeVectorTest::TestConcatenationDouble(void) { TestConcatenation(); } void vctFixedSizeVectorTest::TestConcatenationFloat(void) { TestConcatenation(); } void vctFixedSizeVectorTest::TestConcatenationInt(void) { TestConcatenation(); } void vctFixedSizeVectorTest::TestConcatenationChar(void) { TestConcatenation(); } template void vctFixedSizeVectorTest::TestConcatenationOperator() { typedef vctFixedSizeVector<_elementType, 2> VectorType2; typedef vctFixedSizeVector<_elementType, 3> VectorType3; typedef vctFixedSizeVector<_elementType, 5> VectorType5; typedef vctFixedSizeVector<_elementType, 7> VectorType7; typedef vctFixedSizeVector<_elementType, 8> VectorType8; VectorType3 testVector3_1(1, 2, 3); VectorType2 testVector2_1(11, 12); VectorType5 testVector5_1 = testVector3_1 & testVector2_1; const vctFixedSizeConstVectorRef<_elementType, 3, 1> subsequence1(testVector5_1.Pointer(0)); const vctFixedSizeConstVectorRef<_elementType, 2, 1> subsequence2(testVector5_1.Pointer(3)); CPPUNIT_ASSERT( subsequence1 == testVector3_1 ); CPPUNIT_ASSERT( subsequence2 == testVector2_1 ); VectorType2 testVector2_2(21, 22); VectorType7 testVector7_1 = testVector2_1 & testVector3_1 & testVector2_2; const vctFixedSizeConstVectorRef<_elementType, 2, 1> subsequence3(testVector7_1.Pointer(0)); const vctFixedSizeConstVectorRef<_elementType, 3, 1> subsequence4(testVector7_1.Pointer(2)); const vctFixedSizeConstVectorRef<_elementType, 2, 1> subsequence5(testVector7_1.Pointer(5)); CPPUNIT_ASSERT(subsequence3 == testVector2_1); CPPUNIT_ASSERT(subsequence4 == testVector3_1); CPPUNIT_ASSERT(subsequence5 == testVector2_2); VectorType3 testVector3_2(31, 32, 33); VectorType8 testVector8_1 = testVector3_1 & testVector3_2 & testVector2_1; const vctFixedSizeConstVectorRef<_elementType, 3, 1> subsequence6(testVector8_1.Pointer(0)); const vctFixedSizeConstVectorRef<_elementType, 3, 1> subsequence7(testVector8_1.Pointer(3)); const vctFixedSizeConstVectorRef<_elementType, 2, 1> subsequence8(testVector8_1.Pointer(6)); CPPUNIT_ASSERT(subsequence6 == testVector3_1); CPPUNIT_ASSERT(subsequence7 == testVector3_2); CPPUNIT_ASSERT(subsequence8 == testVector2_1); } void vctFixedSizeVectorTest::TestConcatenationOperatorDouble() { TestConcatenationOperator(); } void vctFixedSizeVectorTest::TestConcatenationOperatorFloat() { TestConcatenationOperator(); } void vctFixedSizeVectorTest::TestConcatenationOperatorInt() { TestConcatenationOperator(); } void vctFixedSizeVectorTest::TestConcatenationOperatorChar() { TestConcatenationOperator(); } template void vctFixedSizeVectorTest::TestAssignment(void) { enum {SIZE = 7}; typedef _elementType value_type; vctFixedSizeVector inputVector; vctRandom(inputVector, value_type(-10), value_type(10)); vctFixedSizeVector outputVector; vctGenericVectorTest::TestAssignment(inputVector, outputVector); } void vctFixedSizeVectorTest::TestAssignmentDouble(void) { TestAssignment(); } void vctFixedSizeVectorTest::TestAssignmentFloat(void) { TestAssignment(); } void vctFixedSizeVectorTest::TestAssignmentInt(void) { TestAssignment(); } template void vctFixedSizeVectorTest::TestAccessMethods(void) { enum {SIZE = 7}; typedef _elementType value_type; vctFixedSizeVector inputVector; vctRandom(inputVector, value_type(-10), value_type(10)); vctFixedSizeConstVectorRef constInputVector(inputVector.Pointer()); vctGenericVectorTest::TestAccessMethods(inputVector, constInputVector); } void vctFixedSizeVectorTest::TestAccessMethodsDouble(void) { TestAccessMethods(); } void vctFixedSizeVectorTest::TestAccessMethodsFloat(void) { TestAccessMethods(); } void vctFixedSizeVectorTest::TestAccessMethodsInt(void) { TestAccessMethods(); } template void vctFixedSizeVectorTest::TestXYZWMethods(void) { vctFixedSizeVector<_elementType, 16> inputVector1; vctRandom(inputVector1, _elementType(-10), _elementType(10)); vctGenericVectorTest::TestConstXYZW(inputVector1); vctGenericVectorTest::TestNonConstXYZW(inputVector1); vctFixedSizeVectorRef<_elementType, 4, 4> inputVector2(inputVector1.Pointer(0)); vctGenericVectorTest::TestConstXYZW(inputVector2); vctGenericVectorTest::TestNonConstXYZW(inputVector2); vctFixedSizeConstVectorRef<_elementType, 4, 2> inputVector3(inputVector1.Pointer(1)); vctGenericVectorTest::TestConstXYZW(inputVector3); } void vctFixedSizeVectorTest::TestXYZWMethodsDouble() { TestXYZWMethods(); } void vctFixedSizeVectorTest::TestXYZWMethodsFloat() { TestXYZWMethods(); } void vctFixedSizeVectorTest::TestXYZWMethodsInt() { TestXYZWMethods(); } template void vctFixedSizeVectorTest::TestSelect(void) { enum {INPUT_SIZE = 12, OUTPUT_SIZE = 5}; vctFixedSizeVector<_elementType, INPUT_SIZE> inputVector; vctFixedSizeVector<_elementType, OUTPUT_SIZE> outputVector; vctFixedSizeVector indexVector; vctRandom(inputVector, _elementType(-10), _elementType(10)); vctRandom(indexVector, static_cast(0), static_cast(INPUT_SIZE)); vctGenericVectorTest::TestSelect(inputVector, indexVector, outputVector); } void vctFixedSizeVectorTest::TestSelectDouble(void) { vctFixedSizeVectorTest::TestSelect(); } void vctFixedSizeVectorTest::TestSelectFloat(void) { vctFixedSizeVectorTest::TestSelect(); } void vctFixedSizeVectorTest::TestSelectInt(void) { vctFixedSizeVectorTest::TestSelect(); } template void vctFixedSizeVectorTest::TestSwapElements(void) { enum {SIZE = 6}; typedef _elementType value_type; typedef vctFixedSizeVector<_elementType, SIZE> VectorType; VectorType v1, v2; vctRandom(v1, value_type(-10), value_type(10)); vctRandom(v2, value_type(-10), value_type(10)); vctGenericVectorTest::TestSwapElements(v1, v2); typedef vctFixedSizeVectorRef<_elementType, SIZE/2, 1> Sequence1Type; Sequence1Type h1(v1.Pointer(0)); Sequence1Type h2(v1.Pointer(SIZE/2)); vctGenericVectorTest::TestSwapElements(h1, h2); typedef vctFixedSizeVectorRef<_elementType, SIZE/2, 2> Sequence2Type; Sequence2Type s1(v2.Pointer(0)); Sequence2Type s2(v2.Pointer(1)); vctGenericVectorTest::TestSwapElements(s1, s2); } void vctFixedSizeVectorTest::TestSwapElementsDouble(void) { TestSwapElements(); } void vctFixedSizeVectorTest::TestSwapElementsFloat(void) { TestSwapElements(); } void vctFixedSizeVectorTest::TestSwapElementsInt(void) { TestSwapElements(); } template void vctFixedSizeVectorTest::TestSoViOperations(void) { enum {SIZE = 6}; typedef _elementType value_type; vctFixedSizeVector vector; vctFixedSizeVector result; vctRandom(vector, value_type(-10), value_type(10)); vctGenericContainerTest::TestSoCiOperations(vector, result); } void vctFixedSizeVectorTest::TestSoViOperationsDouble(void) { TestSoViOperations(); } void vctFixedSizeVectorTest::TestSoViOperationsFloat(void) { TestSoViOperations(); } void vctFixedSizeVectorTest::TestSoViOperationsInt(void) { TestSoViOperations(); } template void vctFixedSizeVectorTest::TestSoViViOperations(void) { enum {SIZE = 5}; typedef _elementType value_type; vctFixedSizeVector vector1; vctFixedSizeVector vector2; vctFixedSizeVector vector3; vctRandom(vector1, value_type(-10), value_type(10)); vctRandom(vector2, value_type(-10), value_type(10)); vctGenericContainerTest::TestSoCiCiOperations(vector1, vector2, vector3); } void vctFixedSizeVectorTest::TestSoViViOperationsDouble(void) { TestSoViViOperations(); } void vctFixedSizeVectorTest::TestSoViViOperationsFloat(void) { TestSoViViOperations(); } void vctFixedSizeVectorTest::TestSoViViOperationsInt(void) { TestSoViViOperations(); } template void vctFixedSizeVectorTest::TestVioViOperations(void) { enum {SIZE = 8}; typedef _elementType value_type; vctFixedSizeVector vector1; vctFixedSizeVector vector2; vctFixedSizeVector result; vctRandom(vector1, value_type(-10), value_type(10)); vctRandom(vector2, value_type(-10), value_type(10)); RemoveQuasiZero(vector2); vctGenericContainerTest::TestCioCiOperations(vector1, vector2, result); } void vctFixedSizeVectorTest::TestVioViOperationsDouble(void) { TestVioViOperations(); } void vctFixedSizeVectorTest::TestVioViOperationsFloat(void) { TestVioViOperations(); } void vctFixedSizeVectorTest::TestVioViOperationsInt(void) { TestVioViOperations(); } template void vctFixedSizeVectorTest::TestVoViViOperations(void) { enum {SIZE = 4}; typedef _elementType value_type; vctFixedSizeVector vector1; vctFixedSizeVector vector2; vctFixedSizeVector result; vctRandom(vector1, value_type(-10), value_type(10)); vctRandom(vector2, value_type(-10), value_type(10)); RemoveQuasiZero(vector2); vctGenericContainerTest::TestCoCiCiOperations(vector1, vector2, result); } void vctFixedSizeVectorTest::TestVoViViOperationsDouble(void) { TestVoViViOperations(); } void vctFixedSizeVectorTest::TestVoViViOperationsFloat(void) { TestVoViViOperations(); } void vctFixedSizeVectorTest::TestVoViViOperationsInt(void) { TestVoViViOperations(); } template void vctFixedSizeVectorTest::TestCrossProduct(void) { enum {SIZE = 3}; typedef _elementType value_type; vctFixedSizeVector vector1; vctFixedSizeVector vector2; vctFixedSizeVector result; vctRandom(vector1, value_type(-10), value_type(10)); vctRandom(vector2, value_type(-10), value_type(10)); vctGenericVectorTest::TestCrossProduct(vector1, vector2, result); } void vctFixedSizeVectorTest::TestCrossProductDouble(void) { TestCrossProduct(); } void vctFixedSizeVectorTest::TestCrossProductFloat(void) { TestCrossProduct(); } void vctFixedSizeVectorTest::TestCrossProductInt(void) { TestCrossProduct(); } template void vctFixedSizeVectorTest::TestDotProduct(void) { enum {SIZE = 8}; typedef _elementType value_type; vctFixedSizeVector vector1; vctFixedSizeVector vector2; vctRandom(vector1, value_type(-10), value_type(10)); vctRandom(vector2, value_type(-10), value_type(10)); vctGenericVectorTest::TestDotProduct(vector1, vector2); } void vctFixedSizeVectorTest::TestDotProductDouble(void) { TestDotProduct(); } void vctFixedSizeVectorTest::TestDotProductFloat(void) { TestDotProduct(); } void vctFixedSizeVectorTest::TestDotProductInt(void) { TestDotProduct(); } template void vctFixedSizeVectorTest::TestVoViOperations(void) { enum {SIZE = 4}; typedef _elementType value_type; vctFixedSizeVector vector; vctFixedSizeVector result; vctRandom(vector, value_type(-10), value_type(10)); vctGenericContainerTest::TestCoCiOperations(vector, result); } void vctFixedSizeVectorTest::TestVoViOperationsDouble(void) { TestVoViOperations(); } void vctFixedSizeVectorTest::TestVoViOperationsFloat(void) { TestVoViOperations(); } void vctFixedSizeVectorTest::TestVoViOperationsInt(void) { TestVoViOperations(); } template void vctFixedSizeVectorTest::TestVoViSiOperations(void) { enum {SIZE = 8}; typedef _elementType value_type; value_type scalar; cmnRandomSequence & randomSequence = cmnRandomSequence::GetInstance(); randomSequence.ExtractRandomValue(value_type(-5), value_type(5), scalar); vctFixedSizeVector vector; vctFixedSizeVector result; if ((scalar < value_type(1)) && (scalar > -value_type(1))) { scalar = value_type(3); } vctRandom(vector, value_type(-10), value_type(10)); vctGenericContainerTest::TestCoCiSiOperations(vector, scalar, result); } void vctFixedSizeVectorTest::TestVoViSiOperationsDouble(void) { TestVoViSiOperations(); } void vctFixedSizeVectorTest::TestVoViSiOperationsFloat(void) { TestVoViSiOperations(); } void vctFixedSizeVectorTest::TestVoViSiOperationsInt(void) { TestVoViSiOperations(); } template void vctFixedSizeVectorTest::TestVoSiViOperations(void) { enum {SIZE = 10}; typedef _elementType value_type; value_type scalar; vctFixedSizeVector vector; vctFixedSizeVector result; cmnRandomSequence & randomSequence = cmnRandomSequence::GetInstance(); randomSequence.ExtractRandomValue(value_type(-5), value_type(5), scalar); vctRandom(vector, value_type(-10), value_type(10)); RemoveQuasiZero(vector); vctGenericContainerTest::TestCoSiCiOperations(scalar, vector, result); } void vctFixedSizeVectorTest::TestVoSiViOperationsDouble(void) { TestVoSiViOperations(); } void vctFixedSizeVectorTest::TestVoSiViOperationsFloat(void) { TestVoSiViOperations(); } void vctFixedSizeVectorTest::TestVoSiViOperationsInt(void) { TestVoSiViOperations(); } template void vctFixedSizeVectorTest::TestVioSiOperations(void) { enum {SIZE = 9}; typedef _elementType value_type; vctFixedSizeVector vector; vctFixedSizeVector result; value_type scalar; cmnRandomSequence & randomSequence = cmnRandomSequence::GetInstance(); randomSequence.ExtractRandomValue(value_type(-5), value_type(5), scalar); if ((scalar < value_type(1)) && (scalar > -value_type(1))) { scalar = value_type(3); } vctRandom(vector, value_type(-10), value_type(10)); vctGenericContainerTest::TestCioSiOperations(vector, scalar, result); } void vctFixedSizeVectorTest::TestVioSiOperationsDouble(void) { TestVioSiOperations(); } void vctFixedSizeVectorTest::TestVioSiOperationsFloat(void) { TestVioSiOperations(); } void vctFixedSizeVectorTest::TestVioSiOperationsInt(void) { TestVioSiOperations(); } template void vctFixedSizeVectorTest::TestVioSiViOperations(void) { enum {SIZE = 7}; typedef _elementType value_type; vctFixedSizeVector vector1; value_type scalar; vctFixedSizeVector vector2; vctFixedSizeVector result; vctRandom(vector1, value_type(-10), value_type(10)); cmnRandomSequence & randomSequence = cmnRandomSequence::GetInstance(); randomSequence.ExtractRandomValue(value_type(-10), value_type(10), scalar); vctRandom(vector2, value_type(-10), value_type(10)); RemoveQuasiZero(vector2); vctGenericContainerTest::TestCioSiCiOperations(vector1, scalar, vector2, result); } void vctFixedSizeVectorTest::TestVioSiViOperationsDouble(void) { TestVioSiViOperations(); } void vctFixedSizeVectorTest::TestVioSiViOperationsFloat(void) { TestVioSiViOperations(); } void vctFixedSizeVectorTest::TestVioSiViOperationsInt(void) { TestVioSiViOperations(); } template void vctFixedSizeVectorTest::TestVioViViOperations(void) { enum {SIZE = 7}; typedef _elementType value_type; vctFixedSizeVector vector1; vctFixedSizeVector vector2; vctFixedSizeVector vector3; vctFixedSizeVector result; vctRandom(vector1, value_type(-10), value_type(10)); vctRandom(vector2, value_type(-10), value_type(10)); vctRandom(vector3, value_type(-10), value_type(10)); RemoveQuasiZero(vector3); vctGenericContainerTest::TestCioCiCiOperations(vector1, vector2, vector3, result); } void vctFixedSizeVectorTest::TestVioViViOperationsDouble(void) { TestVioViViOperations(); } void vctFixedSizeVectorTest::TestVioViViOperationsFloat(void) { TestVioViViOperations(); } void vctFixedSizeVectorTest::TestVioViViOperationsInt(void) { TestVioViViOperations(); } template void vctFixedSizeVectorTest::TestVioOperations(void) { enum {SIZE = 9}; typedef _elementType value_type; vctFixedSizeVector vector; vctFixedSizeVector result; vctRandom(vector, value_type(-10), value_type(10)); vctGenericContainerTest::TestCioOperations(vector, result); } void vctFixedSizeVectorTest::TestVioOperationsDouble(void) { TestVioOperations(); } void vctFixedSizeVectorTest::TestVioOperationsFloat(void) { TestVioOperations(); } void vctFixedSizeVectorTest::TestVioOperationsInt(void) { TestVioOperations(); } template void vctFixedSizeVectorTest::TestSoViSiOperations(void) { enum {SIZE = 9}; typedef _elementType value_type; vctFixedSizeVector vector; vctFixedSizeVector result; value_type scalar; cmnRandomSequence & randomSequence = cmnRandomSequence::GetInstance(); randomSequence.ExtractRandomValue(value_type(-5), value_type(5), scalar); vctRandom(vector, value_type(-10), value_type(10)); vctGenericContainerTest::TestSoCiSiOperations(vector, scalar, result); } void vctFixedSizeVectorTest::TestSoViSiOperationsDouble(void) { TestSoViSiOperations(); } void vctFixedSizeVectorTest::TestSoViSiOperationsFloat(void) { TestSoViSiOperations(); } void vctFixedSizeVectorTest::TestSoViSiOperationsInt(void) { TestSoViSiOperations(); } template void vctFixedSizeVectorTest::TestMinAndMax(void) { enum {SIZE = 9}; typedef _elementType value_type; vctFixedSizeVector vector; vctRandom(vector, value_type(-50), value_type(50)); vctGenericContainerTest::TestMinAndMax(vector); } void vctFixedSizeVectorTest::TestMinAndMaxDouble(void) { TestMinAndMax(); } void vctFixedSizeVectorTest::TestMinAndMaxFloat(void) { TestMinAndMax(); } void vctFixedSizeVectorTest::TestMinAndMaxInt(void) { TestMinAndMax(); } template void vctFixedSizeVectorTest::TestIterators(void) { enum {SIZE = 9}; typedef _elementType value_type; vctFixedSizeVector vector1; vctRandom(vector1, value_type(-10), value_type(10)); vctGenericContainerTest::TestIterators(vector1); } void vctFixedSizeVectorTest::TestIteratorsDouble(void) { TestIterators(); } void vctFixedSizeVectorTest::TestIteratorsFloat(void) { TestIterators(); } void vctFixedSizeVectorTest::TestIteratorsInt(void) { TestIterators(); } template void vctFixedSizeVectorTest::TestSTLFunctions(void) { enum {SIZE = 9}; typedef _elementType value_type; vctFixedSizeVector vector1; vctFixedSizeVector vector2; vctRandom(vector1, value_type(-10), value_type(10)); vctGenericContainerTest::TestSTLFunctions(vector1, vector2); } void vctFixedSizeVectorTest::TestSTLFunctionsDouble(void) { TestSTLFunctions(); } void vctFixedSizeVectorTest::TestSTLFunctionsFloat(void) { TestSTLFunctions(); } void vctFixedSizeVectorTest::TestSTLFunctionsInt(void) { TestSTLFunctions(); } template void vctFixedSizeVectorTest::TestFastCopyOf(void) { enum {SIZE = 6}; typedef _elementType value_type; // dynamic vector vctFixedSizeVector destination; vctDynamicVector validSource(SIZE); vctRandom(validSource, value_type(-10), value_type(10)); vctGenericContainerTest::TestFastCopyOf(validSource, destination); // test for exception if different size vctDynamicVector largerVector(SIZE * 2); vctGenericContainerTest::TestFastCopyOfException(largerVector, destination); // test for not compact vctDynamicVectorRef invalidRef(SIZE, largerVector.Pointer(), 2); CPPUNIT_ASSERT(!destination.FastCopyCompatible(invalidRef)); CPPUNIT_ASSERT(!destination.FastCopyOf(invalidRef)); // safe tests using a larger source and not performing checks CPPUNIT_ASSERT(largerVector.FastCopyOf(destination, false)); // fixed size vector vctFixedSizeVector validSourceFixed; vctRandom(validSourceFixed, value_type(-10), value_type(10)); vctGenericContainerTest::TestFastCopyOf(validSourceFixed, destination); } void vctFixedSizeVectorTest::TestFastCopyOfDouble(void) { TestFastCopyOf(); } void vctFixedSizeVectorTest::TestFastCopyOfFloat(void) { TestFastCopyOf(); } void vctFixedSizeVectorTest::TestFastCopyOfInt(void) { TestFastCopyOf(); } template void vctFixedSizeVectorTest::TestZeros(void) { enum {SIZE = 7}; typedef _elementType value_type; // dynamic vector vctFixedSizeVector destination; CPPUNIT_ASSERT(destination.Zeros()); CPPUNIT_ASSERT(destination.Equal(static_cast(0))); // test for not compact (every other element) vctFixedSizeVectorRef nonCompact(destination.Pointer()); CPPUNIT_ASSERT(!nonCompact.Zeros()); CPPUNIT_ASSERT(nonCompact.Equal(static_cast(0))); } void vctFixedSizeVectorTest::TestZerosDouble(void) { TestZeros(); } void vctFixedSizeVectorTest::TestZerosFloat(void) { TestZeros(); } void vctFixedSizeVectorTest::TestZerosInt(void) { TestZeros(); } template void vctFixedSizeVectorTest::TestNormalization(void) { enum {SIZE = 9}; typedef _elementType value_type; vctFixedSizeVector vector1; vctRandom(vector1, value_type(-10), value_type(10)); vctGenericVectorTest::TestNormalization(vector1); } void vctFixedSizeVectorTest::TestNormalizationDouble(void) { TestNormalization(); } void vctFixedSizeVectorTest::TestNormalizationFloat(void) { TestNormalization(); } CPPUNIT_TEST_SUITE_REGISTRATION(vctFixedSizeVectorTest);