/* -*- 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: 2004-11-17 (C) Copyright 2004-2026 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 "vctDynamicVectorRefTest.h" #include "vctGenericContainerTest.h" #include "vctGenericVectorTest.h" #include #include #include // this macro creates a vector##number by reference and the // associatied storage based on SIZE and STRIDE##number #define CREATE_STORAGE_AND_REF(number) \ value_type storage##number[SIZE * STRIDE##number]; \ vctDynamicVectorRef vector##number; \ vector##number.SetRef(SIZE, storage##number, STRIDE##number) template void vctDynamicVectorRefTest::TestAssignment(void) { enum {SIZE = 7, STRIDE1 = 3, STRIDE2 = 2}; typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); vctRandom(vector1, value_type(-10), value_type(10)); vctGenericVectorTest::TestAssignment(vector1, vector2); } void vctDynamicVectorRefTest::TestAssignmentDouble(void) { TestAssignment(); } void vctDynamicVectorRefTest::TestAssignmentFloat(void) { TestAssignment(); } void vctDynamicVectorRefTest::TestAssignmentInt(void) { TestAssignment(); } template void vctDynamicVectorRefTest::TestAccessMethods(void) { enum {SIZE = 7, STRIDE1 = 4}; typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); vctRandom(vector1, value_type(-10), value_type(10)); vctDynamicConstVectorRef vector2(SIZE, vector1.Pointer(), STRIDE1); vctGenericVectorTest::TestAccessMethods(vector1, vector2); } void vctDynamicVectorRefTest::TestAccessMethodsDouble(void) { TestAccessMethods(); } void vctDynamicVectorRefTest::TestAccessMethodsFloat(void) { TestAccessMethods(); } void vctDynamicVectorRefTest::TestAccessMethodsInt(void) { TestAccessMethods(); } template void vctDynamicVectorRefTest::TestSoViOperations(void) { enum {SIZE = 6, STRIDE1 = 2, STRIDE2 = 4}; typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); vctRandom(vector1, value_type(-10), value_type(10)); vctGenericContainerTest::TestSoCiOperations(vector1, vector2); } void vctDynamicVectorRefTest::TestSoViOperationsDouble(void) { TestSoViOperations(); } void vctDynamicVectorRefTest::TestSoViOperationsFloat(void) { TestSoViOperations(); } void vctDynamicVectorRefTest::TestSoViOperationsInt(void) { TestSoViOperations(); } template void vctDynamicVectorRefTest::TestSoViViOperations(void) { enum {SIZE = 5, STRIDE1 = 1, STRIDE2 = 2, STRIDE3 = 3}; typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); CREATE_STORAGE_AND_REF(3); vctRandom(vector1, value_type(-10), value_type(10)); vctRandom(vector2, value_type(-10), value_type(10)); vctGenericContainerTest::TestSoCiCiOperations(vector1, vector2, vector3); } void vctDynamicVectorRefTest::TestSoViViOperationsDouble(void) { TestSoViViOperations(); } void vctDynamicVectorRefTest::TestSoViViOperationsFloat(void) { TestSoViViOperations(); } void vctDynamicVectorRefTest::TestSoViViOperationsInt(void) { TestSoViViOperations(); } template void vctDynamicVectorRefTest::TestVioViOperations(void) { enum {SIZE = 8, STRIDE1 = 3, STRIDE2 = 2, STRIDE3 = 2}; typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); CREATE_STORAGE_AND_REF(3); vctRandom(vector1, value_type(-10), value_type(10)); vctRandom(vector2, value_type(-10), value_type(10)); RemoveQuasiZero(vector2); vctGenericContainerTest::TestCioCiOperations(vector1, vector2, vector3); } void vctDynamicVectorRefTest::TestVioViOperationsDouble(void) { TestVioViOperations(); } void vctDynamicVectorRefTest::TestVioViOperationsFloat(void) { TestVioViOperations(); } void vctDynamicVectorRefTest::TestVioViOperationsInt(void) { TestVioViOperations(); } template void vctDynamicVectorRefTest::TestVioSiViOperations(void) { enum {SIZE = 8, STRIDE1 = 3, STRIDE2 = 2, STRIDE3 = 2}; typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); CREATE_STORAGE_AND_REF(3); value_type scalar; 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, vector3); } void vctDynamicVectorRefTest::TestVioSiViOperationsDouble(void) { TestVioSiViOperations(); } void vctDynamicVectorRefTest::TestVioSiViOperationsFloat(void) { TestVioSiViOperations(); } void vctDynamicVectorRefTest::TestVioSiViOperationsInt(void) { TestVioSiViOperations(); } template void vctDynamicVectorRefTest::TestVioViViOperations(void) { enum {SIZE = 8, STRIDE1 = 3, STRIDE2 = 2, STRIDE3 = 2, STRIDE4 = 1}; typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); CREATE_STORAGE_AND_REF(3); CREATE_STORAGE_AND_REF(4); 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, vector4); } void vctDynamicVectorRefTest::TestVioViViOperationsDouble(void) { TestVioViViOperations(); } void vctDynamicVectorRefTest::TestVioViViOperationsFloat(void) { TestVioViViOperations(); } void vctDynamicVectorRefTest::TestVioViViOperationsInt(void) { TestVioViViOperations(); } template void vctDynamicVectorRefTest::TestVoViViOperations(void) { enum {SIZE = 4, STRIDE1 = 4, STRIDE2 = 1, STRIDE3 = 2}; typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); CREATE_STORAGE_AND_REF(3); vctRandom(vector1, value_type(-10), value_type(10)); vctRandom(vector2, value_type(-10), value_type(10)); RemoveQuasiZero(vector2); vctGenericContainerTest::TestCoCiCiOperations(vector1, vector2, vector3); } void vctDynamicVectorRefTest::TestVoViViOperationsDouble(void) { TestVoViViOperations(); } void vctDynamicVectorRefTest::TestVoViViOperationsFloat(void) { TestVoViViOperations(); } void vctDynamicVectorRefTest::TestVoViViOperationsInt(void) { TestVoViViOperations(); } template void vctDynamicVectorRefTest::TestCrossProduct(void) { enum {SIZE = 3, STRIDE1 = 3, STRIDE2 = 1, STRIDE3 = 2}; typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); CREATE_STORAGE_AND_REF(3); vctRandom(vector1, value_type(-10), value_type(10)); vctRandom(vector2, value_type(-10), value_type(10)); vctGenericVectorTest::TestCrossProduct(vector1, vector2, vector3); } void vctDynamicVectorRefTest::TestCrossProductDouble(void) { TestCrossProduct(); } void vctDynamicVectorRefTest::TestCrossProductFloat(void) { TestCrossProduct(); } void vctDynamicVectorRefTest::TestCrossProductInt(void) { TestCrossProduct(); } template void vctDynamicVectorRefTest::TestDotProduct(void) { enum {SIZE = 8, STRIDE1 = 3, STRIDE2 = 1}; typedef _elementType value_type; vctDynamicVectorRef vector1; value_type storage1[SIZE * STRIDE1]; vector1.SetRef(SIZE, storage1, STRIDE1); vctDynamicVectorRef vector2; value_type storage2[SIZE * STRIDE2]; vector2.SetRef(SIZE, storage2, STRIDE2); vctRandom(vector1, value_type(-10), value_type(10)); vctRandom(vector2, value_type(-10), value_type(10)); vctGenericVectorTest::TestDotProduct(vector1, vector2); } void vctDynamicVectorRefTest::TestDotProductDouble(void) { TestDotProduct(); } void vctDynamicVectorRefTest::TestDotProductFloat(void) { TestDotProduct(); } void vctDynamicVectorRefTest::TestDotProductInt(void) { TestDotProduct(); } template void vctDynamicVectorRefTest::TestVoViOperations(void) { enum {SIZE = 4, STRIDE1 = 1, STRIDE2 = 3}; typedef _elementType value_type; vctDynamicVectorRef vector1; value_type storage1[SIZE * STRIDE1]; vector1.SetRef(SIZE, storage1, STRIDE1); vctDynamicVectorRef vector2; value_type storage2[SIZE * STRIDE2]; vector2.SetRef(SIZE, storage2, STRIDE2); vctRandom(vector1, value_type(-10), value_type(10)); vctGenericContainerTest::TestCoCiOperations(vector1, vector2); } void vctDynamicVectorRefTest::TestVoViOperationsDouble(void) { TestVoViOperations(); } void vctDynamicVectorRefTest::TestVoViOperationsFloat(void) { TestVoViOperations(); } void vctDynamicVectorRefTest::TestVoViOperationsInt(void) { TestVoViOperations(); } template void vctDynamicVectorRefTest::TestVoViSiOperations(void) { enum {SIZE = 8, STRIDE1 = 3, STRIDE2 = 4}; typedef _elementType value_type; value_type scalar; cmnRandomSequence & randomSequence = cmnRandomSequence::GetInstance(); randomSequence.ExtractRandomValue(value_type(-5), value_type(5), scalar); CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); if ((scalar < value_type(1)) && (scalar > -value_type(1))) { scalar = value_type(3); } vctRandom(vector1, value_type(-10), value_type(10)); vctGenericContainerTest::TestCoCiSiOperations(vector1, scalar, vector2); } void vctDynamicVectorRefTest::TestVoViSiOperationsDouble(void) { TestVoViSiOperations(); } void vctDynamicVectorRefTest::TestVoViSiOperationsFloat(void) { TestVoViSiOperations(); } void vctDynamicVectorRefTest::TestVoViSiOperationsInt(void) { TestVoViSiOperations(); } template void vctDynamicVectorRefTest::TestVoSiViOperations(void) { enum {SIZE = 10, STRIDE1 = 3, STRIDE2 = 1}; typedef _elementType value_type; value_type scalar; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); cmnRandomSequence & randomSequence = cmnRandomSequence::GetInstance(); randomSequence.ExtractRandomValue(value_type(-5), value_type(5), scalar); vctRandom(vector1, value_type(-10), value_type(10)); RemoveQuasiZero(vector1); vctGenericContainerTest::TestCoSiCiOperations(scalar, vector1, vector2); } void vctDynamicVectorRefTest::TestVoSiViOperationsDouble(void) { TestVoSiViOperations(); } void vctDynamicVectorRefTest::TestVoSiViOperationsFloat(void) { TestVoSiViOperations(); } void vctDynamicVectorRefTest::TestVoSiViOperationsInt(void) { TestVoSiViOperations(); } template void vctDynamicVectorRefTest::TestVioSiOperations(void) { enum {SIZE = 9, STRIDE1 = 1, STRIDE2 = 2}; typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); 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(vector1, value_type(-10), value_type(10)); vctGenericContainerTest::TestCioSiOperations(vector1, scalar, vector2); } void vctDynamicVectorRefTest::TestVioSiOperationsDouble(void) { TestVioSiOperations(); } void vctDynamicVectorRefTest::TestVioSiOperationsFloat(void) { TestVioSiOperations(); } void vctDynamicVectorRefTest::TestVioSiOperationsInt(void) { TestVioSiOperations(); } template void vctDynamicVectorRefTest::TestVioOperations(void) { enum {SIZE = 9, STRIDE1 = 2, STRIDE2 = 4}; typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); vctRandom(vector1, value_type(-10), value_type(10)); vctGenericContainerTest::TestCioOperations(vector1, vector2); } void vctDynamicVectorRefTest::TestVioOperationsDouble(void) { TestVioOperations(); } void vctDynamicVectorRefTest::TestVioOperationsFloat(void) { TestVioOperations(); } void vctDynamicVectorRefTest::TestVioOperationsInt(void) { TestVioOperations(); } template void vctDynamicVectorRefTest::TestSoViSiOperations(void) { enum {SIZE = 9, STRIDE1 = 1, STRIDE2 = 2}; typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); value_type scalar; cmnRandomSequence & randomSequence = cmnRandomSequence::GetInstance(); randomSequence.ExtractRandomValue(value_type(-5), value_type(5), scalar); vctRandom(vector1, value_type(-10), value_type(10)); vctGenericContainerTest::TestSoCiSiOperations(vector1, scalar, vector2); } void vctDynamicVectorRefTest::TestSoViSiOperationsDouble(void) { TestSoViSiOperations(); } void vctDynamicVectorRefTest::TestSoViSiOperationsFloat(void) { TestSoViSiOperations(); } void vctDynamicVectorRefTest::TestSoViSiOperationsInt(void) { TestSoViSiOperations(); } template void vctDynamicVectorRefTest::TestMinAndMax(void) { enum {SIZE = 12, STRIDE1 = 2}; typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); vctRandom(vector1, value_type(-50), value_type(50)); vctGenericContainerTest::TestMinAndMax(vector1); } void vctDynamicVectorRefTest::TestMinAndMaxDouble(void) { TestMinAndMax(); } void vctDynamicVectorRefTest::TestMinAndMaxFloat(void) { TestMinAndMax(); } void vctDynamicVectorRefTest::TestMinAndMaxInt(void) { TestMinAndMax(); } template void vctDynamicVectorRefTest::TestIterators(void) { enum {SIZE = 9, STRIDE1 = 5}; typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); vctRandom(vector1, value_type(-10), value_type(10)); vctGenericContainerTest::TestIterators(vector1); } void vctDynamicVectorRefTest::TestIteratorsDouble(void) { TestIterators(); } void vctDynamicVectorRefTest::TestIteratorsFloat(void) { TestIterators(); } void vctDynamicVectorRefTest::TestIteratorsInt(void) { TestIterators(); } template void vctDynamicVectorRefTest::TestSTLFunctions(void) { enum {SIZE = 9, STRIDE1 = 5, STRIDE2 = 1}; typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); CREATE_STORAGE_AND_REF(2); vctRandom(vector1, value_type(-10), value_type(10)); vctGenericContainerTest::TestSTLFunctions(vector1, vector2); } void vctDynamicVectorRefTest::TestSTLFunctionsDouble(void) { TestSTLFunctions(); } void vctDynamicVectorRefTest::TestSTLFunctionsFloat(void) { TestSTLFunctions(); } void vctDynamicVectorRefTest::TestSTLFunctionsInt(void) { TestSTLFunctions(); } template void vctDynamicVectorRefTest::TestNormalization(void) { enum {SIZE = 4, STRIDE1 = 1}; typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); vctRandom(vector1, value_type(-10), value_type(10)); vctGenericVectorTest::TestNormalization(vector1); } void vctDynamicVectorRefTest::TestNormalizationDouble(void) { TestNormalization(); } void vctDynamicVectorRefTest::TestNormalizationFloat(void) { TestNormalization(); } template void vctDynamicVectorRefTest::TestRandomTemporaryRef(void) { enum {SIZE = 7, STRIDE1 = 3}; typedef _elementType value_type; CREATE_STORAGE_AND_REF(1); vector1.SetAll(value_type(100)); vctRandom(vctDynamicVectorRef(SIZE, storage1, STRIDE1), value_type(-10), value_type(10)); vctGenericContainerTest::TestElementsInRange(vector1, value_type(-10), value_type(10)); } void vctDynamicVectorRefTest::TestRandomTemporaryRefDouble(void) { TestRandomTemporaryRef(); } void vctDynamicVectorRefTest::TestRandomTemporaryRefFloat(void) { TestRandomTemporaryRef(); } void vctDynamicVectorRefTest::TestRandomTemporaryRefInt(void) { TestRandomTemporaryRef(); } CPPUNIT_TEST_SUITE_REGISTRATION(vctDynamicVectorRefTest);