From 4881ed4ddb8109e22800aafb6b4e90e30f73a3c7 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Wed, 8 Oct 2014 16:56:33 -0600 Subject: [PATCH] Change tests that try all base types to use different precision Before we assumed that we would only use the basic types specified by the widths of vtkm::Scalar and vtkm::Id. We want to expand this to make sure the code works on whatever data precision we need. --- vtkm/Types.h | 31 +++ ...tArrayManagerExecutionShareWithControl.cxx | 8 +- .../UnitTestArrayPortalFromIterators.cxx | 4 +- .../UnitTestIteratorFromArrayPortal.cxx | 4 +- .../UnitTestArrayPortalToIterators.cxx | 6 +- .../testing/UnitTestDynamicArrayHandle.cxx | 2 +- vtkm/cont/testing/UnitTestStorageBasic.cxx | 6 +- vtkm/cont/testing/UnitTestStorageImplicit.cxx | 2 +- vtkm/testing/Testing.h | 158 +++-------- vtkm/testing/UnitTestTypeTraits.cxx | 10 +- vtkm/testing/UnitTestTypes.cxx | 263 ++++++------------ 11 files changed, 171 insertions(+), 323 deletions(-) diff --git a/vtkm/Types.h b/vtkm/Types.h index 175559a3b..445576b40 100644 --- a/vtkm/Types.h +++ b/vtkm/Types.h @@ -1135,6 +1135,33 @@ VTKM_EXEC_CONT_EXPORT vtkm::Id3 make_Id3(vtkm::Id x, vtkm::Id y, vtkm::Id z) return vtkm::Id3(x, y, z); } +/// Initializes and returns a Vec of length 2. +/// +template +VTKM_EXEC_CONT_EXPORT +vtkm::Vec make_Vec(const T &x, const T &y) +{ + return vtkm::Vec(x, y); +} + +/// Initializes and returns a Vec of length 3. +/// +template +VTKM_EXEC_CONT_EXPORT +vtkm::Vec make_Vec(const T &x, const T &y, const T &z) +{ + return vtkm::Vec(x, y, z); +} + +/// Initializes and returns a Vec of length 4. +/// +template +VTKM_EXEC_CONT_EXPORT +vtkm::Vec make_Vec(const T &x, const T &y, const T &z, const T &w) +{ + return vtkm::Vec(x, y, z, w); +} + template VTKM_EXEC_CONT_EXPORT T dot(const vtkm::Vec &a, const vtkm::Vec &b) @@ -1171,9 +1198,13 @@ T dot(const vtkm::Vec &a, const vtkm::Vec &b) #define VTK_M_SCALAR_DOT(type) \ VTKM_EXEC_CONT_EXPORT type dot(type a, type b) { return a * b; } VTK_M_SCALAR_DOT(vtkm::Int8) +VTK_M_SCALAR_DOT(vtkm::UInt8) VTK_M_SCALAR_DOT(vtkm::Int16) +VTK_M_SCALAR_DOT(vtkm::UInt16) VTK_M_SCALAR_DOT(vtkm::Int32) +VTK_M_SCALAR_DOT(vtkm::UInt32) VTK_M_SCALAR_DOT(vtkm::Int64) +VTK_M_SCALAR_DOT(vtkm::UInt64) VTK_M_SCALAR_DOT(vtkm::Float32) VTK_M_SCALAR_DOT(vtkm::Float64) diff --git a/vtkm/cont/internal/testing/UnitTestArrayManagerExecutionShareWithControl.cxx b/vtkm/cont/internal/testing/UnitTestArrayManagerExecutionShareWithControl.cxx index d42db9750..44916c1aa 100644 --- a/vtkm/cont/internal/testing/UnitTestArrayManagerExecutionShareWithControl.cxx +++ b/vtkm/cont/internal/testing/UnitTestArrayManagerExecutionShareWithControl.cxx @@ -71,7 +71,7 @@ struct TemplatedTests void InputData() { - const ValueType INPUT_VALUE(4145); + const ValueType INPUT_VALUE(45); StorageType controlArray; controlArray.Allocate(ARRAY_SIZE); @@ -94,7 +94,7 @@ struct TemplatedTests void InPlaceData() { - const ValueType INPUT_VALUE(2350); + const ValueType INPUT_VALUE(50); StorageType controlArray; controlArray.Allocate(ARRAY_SIZE); @@ -121,7 +121,7 @@ struct TemplatedTests void OutputData() { - const ValueType OUTPUT_VALUE(6712); + const ValueType OUTPUT_VALUE(12); StorageType controlArray; @@ -154,7 +154,7 @@ struct TemplatedTests struct TestFunctor { template - void operator()(T) + void operator()(T) const { TemplatedTests tests; tests(); diff --git a/vtkm/cont/internal/testing/UnitTestArrayPortalFromIterators.cxx b/vtkm/cont/internal/testing/UnitTestArrayPortalFromIterators.cxx index c276d0c65..c9e9a6990 100644 --- a/vtkm/cont/internal/testing/UnitTestArrayPortalFromIterators.cxx +++ b/vtkm/cont/internal/testing/UnitTestArrayPortalFromIterators.cxx @@ -130,7 +130,7 @@ struct TemplatedTests VTKM_TEST_ASSERT(CheckPortal(const_portal, ORIGINAL_VALUE), "Const portal iterator has bad value."); - static const ComponentType SET_VALUE = 562; + static const ComponentType SET_VALUE = 62; std::cout << " Check get/set methods." << std::endl; for (vtkm::Id index = 0; index < ARRAY_SIZE; index++) @@ -156,7 +156,7 @@ struct TemplatedTests struct TestFunctor { template - void operator()(T) + void operator()(T) const { TemplatedTests tests; tests(); diff --git a/vtkm/cont/internal/testing/UnitTestIteratorFromArrayPortal.cxx b/vtkm/cont/internal/testing/UnitTestIteratorFromArrayPortal.cxx index 08134179c..d26d33b27 100644 --- a/vtkm/cont/internal/testing/UnitTestIteratorFromArrayPortal.cxx +++ b/vtkm/cont/internal/testing/UnitTestIteratorFromArrayPortal.cxx @@ -115,7 +115,7 @@ struct TemplatedTests IteratorType begin = vtkm::cont::internal::make_IteratorBegin(portal); IteratorType end = vtkm::cont::internal::make_IteratorEnd(portal); - static const ComponentType WRITE_VALUE = 873; + static const ComponentType WRITE_VALUE = 73; std::cout << " Write values to iterator." << std::endl; FillIterator(begin, end, WRITE_VALUE); @@ -150,7 +150,7 @@ struct TemplatedTests struct TestFunctor { template - void operator()(T) + void operator()(T) const { TemplatedTests tests; tests(); diff --git a/vtkm/cont/testing/UnitTestArrayPortalToIterators.cxx b/vtkm/cont/testing/UnitTestArrayPortalToIterators.cxx index c7d6ec91c..dd1cb1df8 100644 --- a/vtkm/cont/testing/UnitTestArrayPortalToIterators.cxx +++ b/vtkm/cont/testing/UnitTestArrayPortalToIterators.cxx @@ -119,7 +119,7 @@ struct TemplatedTests typedef ReadOnlyArrayPortal ArrayPortalType; typedef vtkm::cont::ArrayPortalToIterators GetIteratorsType; - static const ComponentType READ_VALUE = 23900; + static const ComponentType READ_VALUE = 23; ArrayPortalType portal(READ_VALUE); std::cout << " Testing read-only iterators with ArrayPortalToIterators." @@ -139,7 +139,7 @@ struct TemplatedTests typedef WriteOnlyArrayPortal ArrayPortalType; typedef vtkm::cont::ArrayPortalToIterators GetIteratorsType; - static const ComponentType WRITE_VALUE = 63400; + static const ComponentType WRITE_VALUE = 63; ArrayPortalType portal(WRITE_VALUE); std::cout << " Testing write-only iterators with ArrayPortalToIterators." @@ -164,7 +164,7 @@ struct TemplatedTests struct TestFunctor { template - void operator()(T) + void operator()(T) const { TemplatedTests tests; tests(); diff --git a/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx b/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx index 0c78465eb..f8c2def7e 100644 --- a/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx +++ b/vtkm/cont/testing/UnitTestDynamicArrayHandle.cxx @@ -155,7 +155,7 @@ void TryDefaultType(T) struct TryBasicVTKmType { template - void operator()(T) { + void operator()(T) const { CheckCalled = false; vtkm::cont::DynamicArrayHandle array = CreateDynamicArray(T()); diff --git a/vtkm/cont/testing/UnitTestStorageBasic.cxx b/vtkm/cont/testing/UnitTestStorageBasic.cxx index a7b4ce278..03dc775b1 100644 --- a/vtkm/cont/testing/UnitTestStorageBasic.cxx +++ b/vtkm/cont/testing/UnitTestStorageBasic.cxx @@ -58,7 +58,7 @@ struct TemplatedTests typename vtkm::VecTraits::ComponentType STOLEN_ARRAY_VALUE() { - return 4529; + return 29; } /// Returned value should later be passed to StealArray2. It is best to @@ -105,7 +105,7 @@ struct TemplatedTests VTKM_TEST_ASSERT(arrayStorage.GetNumberOfValues() == ARRAY_SIZE, "Array not properly allocated."); - const ValueType BASIC_ALLOC_VALUE = ValueType(548); + const ValueType BASIC_ALLOC_VALUE = ValueType(48); SetStorage(arrayStorage, BASIC_ALLOC_VALUE); VTKM_TEST_ASSERT(CheckStorage(arrayStorage, BASIC_ALLOC_VALUE), "Array not holding value."); @@ -144,7 +144,7 @@ struct TemplatedTests struct TestFunctor { template - void operator()(T) + void operator()(T) const { TemplatedTests tests; tests(); diff --git a/vtkm/cont/testing/UnitTestStorageImplicit.cxx b/vtkm/cont/testing/UnitTestStorageImplicit.cxx index 007d9a1b2..b0d48c415 100644 --- a/vtkm/cont/testing/UnitTestStorageImplicit.cxx +++ b/vtkm/cont/testing/UnitTestStorageImplicit.cxx @@ -128,7 +128,7 @@ struct TemplatedTests struct TestFunctor { template - void operator()(T) + void operator()(T) const { TemplatedTests tests; tests(); diff --git a/vtkm/testing/Testing.h b/vtkm/testing/Testing.h index 3f021c832..b904bd80a 100644 --- a/vtkm/testing/Testing.h +++ b/vtkm/testing/Testing.h @@ -20,6 +20,7 @@ #ifndef vtk_m_testing_Testing_h #define vtk_m_testing_Testing_h +#include #include #include #include @@ -202,130 +203,42 @@ public: } #endif - /// Check functors to be used with the TryAllTypes method. - /// - struct TypeCheckAlwaysTrue + template + struct InternalPrintTypeAndInvoke { - template - void operator()(T t, Functor function) const { function(t); } - }; - struct TypeCheckInteger - { - template - void operator()(T t, Functor function) const - { - this->DoInteger(typename vtkm::TypeTraits::NumericTag(), t, function); - } - private: - template - void DoInteger(Tag, T, const Functor&) const { } - template - void DoInteger(vtkm::TypeTraitsIntegerTag, T t, Functor function) const - { - function(t); - } - }; - struct TypeCheckReal - { - template - void operator()(T t, Functor function) const - { - this->DoReal(typename vtkm::TypeTraits::NumericTag(), t, function); - } - private: - template - void DoReal(Tag, T, const Functor&) const { } - template - void DoReal(vtkm::TypeTraitsRealTag, T t, Functor function) const - { - function(t); - } - }; - struct TypeCheckScalar - { - template - void operator()(T t, Functor func) const - { - this->DoScalar(typename vtkm::TypeTraits::DimensionalityTag(), t, func); - } - private: - template - void DoScalar(Tag, const T &, const Functor &) const { } - template - void DoScalar(vtkm::TypeTraitsScalarTag, T t, Functor function) const - { - function(t); - } - }; - struct TypeCheckVector - { - template - void operator()(T t, Functor func) const - { - this->DoVector(typename vtkm::TypeTraits::DimensionalityTag(), t, func); - } - private: - template - void DoVector(Tag, const T &, const Functor &) const { } - template - void DoVector(vtkm::TypeTraitsVectorTag, T t, Functor function) const - { - function(t); - } - }; + InternalPrintTypeAndInvoke(FunctionType function) : Function(function) { } - template - struct InternalPrintOnInvoke - { - InternalPrintOnInvoke(FunctionType function, std::string toprint) - : Function(function), ToPrint(toprint) { } - template void operator()(T t) + template + void operator()(T t) const { - std::cout << this->ToPrint << std::endl; + std::cout << "*** " + << vtkm::testing::TypeName::Name() + << " ***************" << std::endl; this->Function(t); } + private: FunctionType Function; - std::string ToPrint; }; - /// Runs templated \p function on all the basic types defined in VTKm. This is - /// helpful to test templated functions that should work on all types. If the - /// function is supposed to work on some subset of types, then \p check can - /// be set to restrict the types used. This Testing class contains several - /// helpful check functors. + /// Runs template \p function on all the types in the given list. /// - template - static void TryAllTypes(FunctionType function, CheckType check) + template + static void TryTypes(const FunctionType &function, TypeList) { - vtkm::Id id = 0; - check(id, InternalPrintOnInvoke( - function, "*** vtkm::Id ***************")); - - vtkm::Id3 id3 = vtkm::make_Id3(0, 0, 0); - check(id3, InternalPrintOnInvoke( - function, "*** vtkm::Id3 **************")); - - vtkm::Scalar scalar = 0.0; - check(scalar, InternalPrintOnInvoke( - function, "*** vtkm::Scalar ***********")); - - vtkm::Vector2 vector2 = vtkm::make_Vector2(0.0, 0.0); - check(vector2, InternalPrintOnInvoke( - function, "*** vtkm::Vector2 **********")); - - vtkm::Vector3 vector3 = vtkm::make_Vector3(0.0, 0.0, 0.0); - check(vector3, InternalPrintOnInvoke( - function, "*** vtkm::Vector3 **********")); - - vtkm::Vector4 vector4 = vtkm::make_Vector4(0.0, 0.0, 0.0, 0.0); - check(vector4, InternalPrintOnInvoke( - function, "*** vtkm::Vector4 **********")); + vtkm::ListForEach(InternalPrintTypeAndInvoke(function), + TypeList()); } + + /// Runs templated \p function on all the basic types defined in VTK-m. This + /// is helpful to test templated functions that should work on all types. If + /// the function is supposed to work on some subset of types, then use + /// \c TryTypes to restrict the call to some other list of types. + /// template - static void TryAllTypes(FunctionType function) + static void TryAllTypes(const FunctionType &function) { - TryAllTypes(function, TypeCheckAlwaysTrue()); + TryTypes(function, vtkm::TypeListTagAll()); } }; @@ -336,26 +249,31 @@ public: /// Helper function to test two quanitites for equality accounting for slight /// variance due to floating point numerical inaccuracies. /// -template +template VTKM_EXEC_CONT_EXPORT -bool test_equal(VectorType vector1, - VectorType vector2, - vtkm::Scalar tolerance = 0.0001) +bool test_equal(VectorType1 vector1, + VectorType2 vector2, + vtkm::Float64 tolerance = 0.0001) { - typedef typename vtkm::VecTraits Traits; + typedef typename vtkm::VecTraits Traits; + BOOST_STATIC_ASSERT( + Traits::NUM_COMPONENTS == vtkm::VecTraits::NUM_COMPONENTS); + for (vtkm::IdComponent component = 0; component < Traits::NUM_COMPONENTS; component++) { - vtkm::Scalar value1 = vtkm::Scalar(Traits::GetComponent(vector1, component)); - vtkm::Scalar value2 = vtkm::Scalar(Traits::GetComponent(vector2, component)); + vtkm::Float64 value1 = + vtkm::Float64(Traits::GetComponent(vector1, component)); + vtkm::Float64 value2 = + vtkm::Float64(Traits::GetComponent(vector2, component)); if ((fabs(value1) < 2*tolerance) && (fabs(value2) < 2*tolerance)) { continue; } - vtkm::Scalar ratio = value1/value2; - if ((ratio > vtkm::Scalar(1.0) - tolerance) - && (ratio < vtkm::Scalar(1.0) + tolerance)) + vtkm::Float64 ratio = value1/value2; + if ((ratio > vtkm::Float64(1.0) - tolerance) + && (ratio < vtkm::Float64(1.0) + tolerance)) { // This component is OK. The condition is checked in this way to // correctly handle non-finites that fail all comparisons. Thus, if a diff --git a/vtkm/testing/UnitTestTypeTraits.cxx b/vtkm/testing/UnitTestTypeTraits.cxx index 40cd80b98..97f92567e 100644 --- a/vtkm/testing/UnitTestTypeTraits.cxx +++ b/vtkm/testing/UnitTestTypeTraits.cxx @@ -28,7 +28,7 @@ namespace { struct TypeTraitTest { - template void operator()(T t) + template void operator()(T t) const { // If you get compiler errors here, it could be a TypeTraits instance // has missing or malformed tags. @@ -38,14 +38,14 @@ struct TypeTraitTest private: template - void TestDimensionality(T, vtkm::TypeTraitsScalarTag) + void TestDimensionality(T, vtkm::TypeTraitsScalarTag) const { std::cout << " scalar" << std::endl; VTKM_TEST_ASSERT(vtkm::VecTraits::NUM_COMPONENTS == 1, "Scalar type does not have one component."); } template - void TestDimensionality(T, vtkm::TypeTraitsVectorTag) + void TestDimensionality(T, vtkm::TypeTraitsVectorTag) const { std::cout << " vector" << std::endl; VTKM_TEST_ASSERT(vtkm::VecTraits::NUM_COMPONENTS > 1, @@ -53,7 +53,7 @@ private: } template - void TestNumeric(T, vtkm::TypeTraitsIntegerTag) + void TestNumeric(T, vtkm::TypeTraitsIntegerTag) const { std::cout << " integer" << std::endl; typedef typename vtkm::VecTraits::ComponentType VT; @@ -61,7 +61,7 @@ private: VTKM_TEST_ASSERT(value == 2, "Integer does not round to integer."); } template - void TestNumeric(T, vtkm::TypeTraitsRealTag) + void TestNumeric(T, vtkm::TypeTraitsRealTag) const { std::cout << " real" << std::endl; typedef typename vtkm::VecTraits::ComponentType VT; diff --git a/vtkm/testing/UnitTestTypes.cxx b/vtkm/testing/UnitTestTypes.cxx index b134ed524..19d3f0ee4 100644 --- a/vtkm/testing/UnitTestTypes.cxx +++ b/vtkm/testing/UnitTestTypes.cxx @@ -59,8 +59,11 @@ void CheckTypeSizes() } //general type test -template void TypeTest() +template +void GeneralVecTypeTest(const vtkm::Vec &) { + typedef vtkm::Vec T; + //grab the number of elements of T T a, b, c; typename T::ComponentType s(5); @@ -143,38 +146,49 @@ template void TypeTest() VTKM_TEST_ASSERT( (a != c), "operator != wrong"); } -template<> void TypeTest() +template +void TypeTest(const vtkm::Vec &) { - vtkm::Vector2 a = vtkm::make_Vector2(2, 4); - vtkm::Vector2 b = vtkm::make_Vector2(1, 2); - vtkm::Scalar s = 5; + GeneralVecTypeTest(vtkm::Vec()); +} - vtkm::Vector2 plus = a + b; - VTKM_TEST_ASSERT(test_equal(plus, vtkm::make_Vector2(3, 6)), +template +void TypeTest(const vtkm::Vec &) +{ + typedef vtkm::Vec Vector; + + GeneralVecTypeTest(Vector()); + + Vector a(2, 4); + Vector b(1, 2); + Scalar s = 5; + + Vector plus = a + b; + VTKM_TEST_ASSERT(test_equal(plus, vtkm::make_Vec(3, 6)), "Vectors do not add correctly."); - vtkm::Vector2 minus = a - b; - VTKM_TEST_ASSERT(test_equal(minus, vtkm::make_Vector2(1, 2)), + Vector minus = a - b; + VTKM_TEST_ASSERT(test_equal(minus, vtkm::make_Vec(1, 2)), "Vectors to not subtract correctly."); - vtkm::Vector2 mult = a * b; - VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector2(2, 8)), + Vector mult = a * b; + VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(2, 8)), "Vectors to not multiply correctly."); - vtkm::Vector2 div = a / b; + Vector div = a / b; VTKM_TEST_ASSERT(test_equal(div, vtkm::make_Vector2(2, 2)), "Vectors to not divide correctly."); mult = s * a; - VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector2(10, 20)), + VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(10, 20)), "Vector and scalar to not multiply correctly."); mult = a * s; - VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector2(10, 20)), + VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(10, 20)), "Vector and scalar to not multiply correctly."); - vtkm::Scalar d = vtkm::dot(a, b); - VTKM_TEST_ASSERT(test_equal(d, vtkm::Scalar(10)), "dot(Vector2) wrong"); + Scalar d = vtkm::dot(a, b); + VTKM_TEST_ASSERT(test_equal(d, Scalar(10)), "dot(Vector2) wrong"); VTKM_TEST_ASSERT(!(a < b), "operator< wrong"); VTKM_TEST_ASSERT((b < a), "operator< wrong"); @@ -189,7 +203,7 @@ template<> void TypeTest() VTKM_TEST_ASSERT(!(a != a), "operator!= wrong"); //test against a tuple that shares some values - const vtkm::Vector2 c = vtkm::make_Vector2(2,3); + const Vector c(2, 3); VTKM_TEST_ASSERT((c < a), "operator< wrong"); VTKM_TEST_ASSERT( !(c == a), "operator == wrong"); @@ -199,38 +213,43 @@ template<> void TypeTest() VTKM_TEST_ASSERT( (a != c), "operator != wrong"); } -template<> void TypeTest() +template +void TypeTest(const vtkm::Vec &) { - vtkm::Vector3 a = vtkm::make_Vector3(2, 4, 6); - vtkm::Vector3 b = vtkm::make_Vector3(1, 2, 3); - vtkm::Scalar s = 5; + typedef vtkm::Vec Vector; - vtkm::Vector3 plus = a + b; - VTKM_TEST_ASSERT(test_equal(plus, vtkm::make_Vector3(3, 6, 9)), + GeneralVecTypeTest(Vector()); + + Vector a(2, 4, 6); + Vector b(1, 2, 3); + Scalar s = 5; + + Vector plus = a + b; + VTKM_TEST_ASSERT(test_equal(plus, vtkm::make_Vec(3, 6, 9)), "Vectors do not add correctly."); - vtkm::Vector3 minus = a - b; - VTKM_TEST_ASSERT(test_equal(minus, vtkm::make_Vector3(1, 2, 3)), + Vector minus = a - b; + VTKM_TEST_ASSERT(test_equal(minus, vtkm::make_Vec(1, 2, 3)), "Vectors to not subtract correctly."); - vtkm::Vector3 mult = a * b; - VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector3(2, 8, 18)), + Vector mult = a * b; + VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(2, 8, 18)), "Vectors to not multiply correctly."); - vtkm::Vector3 div = a / b; - VTKM_TEST_ASSERT(test_equal(div, vtkm::make_Vector3(2, 2, 2)), + Vector div = a / b; + VTKM_TEST_ASSERT(test_equal(div, vtkm::make_Vec(2, 2, 2)), "Vectors to not divide correctly."); mult = s * a; - VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector3(10, 20, 30)), + VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(10, 20, 30)), "Vector and scalar to not multiply correctly."); mult = a * s; - VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector3(10, 20, 30)), + VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(10, 20, 30)), "Vector and scalar to not multiply correctly."); vtkm::Scalar d = vtkm::dot(a, b); - VTKM_TEST_ASSERT(test_equal(d, vtkm::Scalar(28)), "dot(Vector3) wrong"); + VTKM_TEST_ASSERT(test_equal(d, Scalar(28)), "dot(Vector3) wrong"); VTKM_TEST_ASSERT(!(a < b), "operator< wrong"); VTKM_TEST_ASSERT((b < a), "operator< wrong"); @@ -245,7 +264,7 @@ template<> void TypeTest() VTKM_TEST_ASSERT(!(a != a), "operator!= wrong"); //test against a tuple that shares some values - const vtkm::Vector3 c = vtkm::make_Vector3(2,4,5); + const Vector c(2,4,5); VTKM_TEST_ASSERT((c < a), "operator< wrong"); VTKM_TEST_ASSERT( !(c == a), "operator == wrong"); @@ -255,34 +274,39 @@ template<> void TypeTest() VTKM_TEST_ASSERT( (a != c), "operator != wrong"); } -template<> void TypeTest() +template +void TypeTest(const vtkm::Vec &) { - vtkm::Vector4 a = vtkm::make_Vector4(2, 4, 6, 8); - vtkm::Vector4 b = vtkm::make_Vector4(1, 2, 3, 4); - vtkm::Scalar s = 5; + typedef vtkm::Vec Vector; - vtkm::Vector4 plus = a + b; - VTKM_TEST_ASSERT(test_equal(plus, vtkm::make_Vector4(3, 6, 9, 12)), + GeneralVecTypeTest(Vector()); + + Vector a(2, 4, 6, 8); + Vector b(1, 2, 3, 4); + Scalar s = 5; + + Vector plus = a + b; + VTKM_TEST_ASSERT(test_equal(plus, vtkm::make_Vec(3, 6, 9, 12)), "Vectors do not add correctly."); - vtkm::Vector4 minus = a - b; - VTKM_TEST_ASSERT(test_equal(minus, vtkm::make_Vector4(1, 2, 3, 4)), + Vector minus = a - b; + VTKM_TEST_ASSERT(test_equal(minus, vtkm::make_Vec(1, 2, 3, 4)), "Vectors to not subtract correctly."); - vtkm::Vector4 mult = a * b; - VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector4(2, 8, 18, 32)), + Vector mult = a * b; + VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(2, 8, 18, 32)), "Vectors to not multiply correctly."); - vtkm::Vector4 div = a / b; - VTKM_TEST_ASSERT(test_equal(div, vtkm::make_Vector4(2, 2, 2, 2)), + Vector div = a / b; + VTKM_TEST_ASSERT(test_equal(div, vtkm::make_Vec(2, 2, 2, 2)), "Vectors to not divide correctly."); mult = s * a; - VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector4(10, 20, 30, 40)), + VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(10, 20, 30, 40)), "Vector and scalar to not multiply correctly."); mult = a * s; - VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vector4(10, 20, 30, 40)), + VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(10, 20, 30, 40)), "Vector and scalar to not multiply correctly."); vtkm::Scalar d = vtkm::dot(a, b); @@ -302,7 +326,7 @@ template<> void TypeTest() VTKM_TEST_ASSERT(!(a != a), "operator!= wrong"); //test against a tuple that shares some values - const vtkm::Vector4 c = vtkm::make_Vector4(2,4,6,7); + const Vector c(2,4,6,7); VTKM_TEST_ASSERT((c < a), "operator< wrong"); VTKM_TEST_ASSERT( !(c == a), "operator == wrong"); @@ -312,112 +336,31 @@ template<> void TypeTest() VTKM_TEST_ASSERT( (a != c), "operator != wrong"); } -template<> void TypeTest() +template +void TypeTest(Scalar) { - vtkm::Id3 a = vtkm::make_Id3(2, 4, 6); - vtkm::Id3 b = vtkm::make_Id3(1, 2, 3); - vtkm::Id s = 5; + Scalar a = 4; + Scalar b = 2; - vtkm::Id3 plus = a + b; - if ((plus[0] != 3) || (plus[1] != 6) || (plus[2] != 9)) - { - VTKM_TEST_FAIL("Vectors do not add correctly."); - } - - vtkm::Id3 minus = a - b; - if ((minus[0] != 1) || (minus[1] != 2) || (minus[2] != 3)) - { - VTKM_TEST_FAIL("Vectors to not subtract correctly."); - } - - vtkm::Id3 mult = a * b; - if ((mult[0] != 2) || (mult[1] != 8) || (mult[2] != 18)) - { - VTKM_TEST_FAIL("Vectors to not multiply correctly."); - } - - vtkm::Id3 div = a / b; - if ((div[0] != 2) || (div[1] != 2) || (div[2] != 2)) - { - VTKM_TEST_FAIL("Vectors to not divide correctly."); - } - - mult = s * a; - if ((mult[0] != 10) || (mult[1] != 20) || (mult[2] != 30)) - { - VTKM_TEST_FAIL("Vector and scalar to not multiply correctly."); - } - - mult = a * s; - if ((mult[0] != 10) || (mult[1] != 20) || (mult[2] != 30)) - { - VTKM_TEST_FAIL("Vector and scalar to not multiply correctly."); - } - - if (vtkm::dot(a, b) != 28) - { - VTKM_TEST_FAIL("dot(Id3) wrong"); - } - - VTKM_TEST_ASSERT(!(a < b), "operator< wrong"); - VTKM_TEST_ASSERT((b < a), "operator< wrong"); - VTKM_TEST_ASSERT(!(a < a), "operator< wrong"); - VTKM_TEST_ASSERT((a < plus), "operator< wrong"); - VTKM_TEST_ASSERT((minus < plus), "operator< wrong"); - - if (a == b) - { - VTKM_TEST_FAIL("operator== wrong"); - } - if (!(a == a)) - { - VTKM_TEST_FAIL("operator== wrong"); - } - - if (!(a != b)) - { - VTKM_TEST_FAIL("operator!= wrong"); - } - if (a != a) - { - VTKM_TEST_FAIL("operator!= wrong"); - } - - //test against a tuple that shares some values - const vtkm::Id3 c = vtkm::make_Id3(2,4,5); - VTKM_TEST_ASSERT((c < a), "operator< wrong"); - - if (c == a) { VTKM_TEST_FAIL("operator== wrong"); } - if (a == c) { VTKM_TEST_FAIL("operator== wrong"); } - - if (!(c != a)) { VTKM_TEST_FAIL("operator!= wrong"); } - if (!(a != c)) { VTKM_TEST_FAIL("operator!= wrong"); } -} - -template<> void TypeTest() -{ - vtkm::Scalar a = 4; - vtkm::Scalar b = 2; - - vtkm::Scalar plus = a + b; + Scalar plus = a + b; if (plus != 6) { VTKM_TEST_FAIL("Scalars do not add correctly."); } - vtkm::Scalar minus = a - b; + Scalar minus = a - b; if (minus != 2) { VTKM_TEST_FAIL("Scalars to not subtract correctly."); } - vtkm::Scalar mult = a * b; + Scalar mult = a * b; if (mult != 8) { VTKM_TEST_FAIL("Scalars to not multiply correctly."); } - vtkm::Scalar div = a / b; + Scalar div = a / b; if (div != 2) { VTKM_TEST_FAIL("Scalars to not divide correctly."); @@ -438,55 +381,11 @@ template<> void TypeTest() } } -template<> void TypeTest() -{ - vtkm::Id a = 4; - vtkm::Id b = 2; - - vtkm::Id plus = a + b; - if (plus != 6) - { - VTKM_TEST_FAIL("Scalars do not add correctly."); - } - - vtkm::Id minus = a - b; - if (minus != 2) - { - VTKM_TEST_FAIL("Scalars to not subtract correctly."); - } - - vtkm::Id mult = a * b; - if (mult != 8) - { - VTKM_TEST_FAIL("Scalars to not multiply correctly."); - } - - vtkm::Id div = a / b; - if (div != 2) - { - VTKM_TEST_FAIL("Scalars to not divide correctly."); - } - - if (a == b) - { - VTKM_TEST_FAIL("operator== wrong"); - } - if (!(a != b)) - { - VTKM_TEST_FAIL("operator!= wrong"); - } - - if (vtkm::dot(a, b) != 8) - { - VTKM_TEST_FAIL("dot(Id) wrong"); - } -} - struct TypeTestFunctor { template void operator()(const T&) const { - TypeTest(); + TypeTest(T()); } };