mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
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.
This commit is contained in:
parent
0cc9d27e26
commit
4881ed4ddb
31
vtkm/Types.h
31
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<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T,2> make_Vec(const T &x, const T &y)
|
||||
{
|
||||
return vtkm::Vec<T,2>(x, y);
|
||||
}
|
||||
|
||||
/// Initializes and returns a Vec of length 3.
|
||||
///
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T,3> make_Vec(const T &x, const T &y, const T &z)
|
||||
{
|
||||
return vtkm::Vec<T,3>(x, y, z);
|
||||
}
|
||||
|
||||
/// Initializes and returns a Vec of length 4.
|
||||
///
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<T,4> make_Vec(const T &x, const T &y, const T &z, const T &w)
|
||||
{
|
||||
return vtkm::Vec<T,4>(x, y, z, w);
|
||||
}
|
||||
|
||||
template<typename T, vtkm::IdComponent Size>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
T dot(const vtkm::Vec<T,Size> &a, const vtkm::Vec<T,Size> &b)
|
||||
@ -1171,9 +1198,13 @@ T dot(const vtkm::Vec<T,4> &a, const vtkm::Vec<T,4> &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)
|
||||
|
||||
|
@ -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 <typename T>
|
||||
void operator()(T)
|
||||
void operator()(T) const
|
||||
{
|
||||
TemplatedTests<T> tests;
|
||||
tests();
|
||||
|
@ -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<typename T>
|
||||
void operator()(T)
|
||||
void operator()(T) const
|
||||
{
|
||||
TemplatedTests<T> tests;
|
||||
tests();
|
||||
|
@ -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<typename T>
|
||||
void operator()(T)
|
||||
void operator()(T) const
|
||||
{
|
||||
TemplatedTests<T> tests;
|
||||
tests();
|
||||
|
@ -119,7 +119,7 @@ struct TemplatedTests
|
||||
typedef ReadOnlyArrayPortal ArrayPortalType;
|
||||
typedef vtkm::cont::ArrayPortalToIterators<ArrayPortalType> 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<ArrayPortalType> 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<typename T>
|
||||
void operator()(T)
|
||||
void operator()(T) const
|
||||
{
|
||||
TemplatedTests<T> tests;
|
||||
tests();
|
||||
|
@ -155,7 +155,7 @@ void TryDefaultType(T)
|
||||
struct TryBasicVTKmType
|
||||
{
|
||||
template<typename T>
|
||||
void operator()(T) {
|
||||
void operator()(T) const {
|
||||
CheckCalled = false;
|
||||
|
||||
vtkm::cont::DynamicArrayHandle array = CreateDynamicArray(T());
|
||||
|
@ -58,7 +58,7 @@ struct TemplatedTests
|
||||
|
||||
typename vtkm::VecTraits<ValueType>::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 <typename T>
|
||||
void operator()(T)
|
||||
void operator()(T) const
|
||||
{
|
||||
TemplatedTests<T> tests;
|
||||
tests();
|
||||
|
@ -128,7 +128,7 @@ struct TemplatedTests
|
||||
struct TestFunctor
|
||||
{
|
||||
template <typename T>
|
||||
void operator()(T)
|
||||
void operator()(T) const
|
||||
{
|
||||
TemplatedTests<T> tests;
|
||||
tests();
|
||||
|
@ -20,6 +20,7 @@
|
||||
#ifndef vtk_m_testing_Testing_h
|
||||
#define vtk_m_testing_Testing_h
|
||||
|
||||
#include <vtkm/TypeListTag.h>
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/TypeTraits.h>
|
||||
#include <vtkm/VecTraits.h>
|
||||
@ -202,130 +203,42 @@ public:
|
||||
}
|
||||
#endif
|
||||
|
||||
/// Check functors to be used with the TryAllTypes method.
|
||||
///
|
||||
struct TypeCheckAlwaysTrue
|
||||
template<typename FunctionType>
|
||||
struct InternalPrintTypeAndInvoke
|
||||
{
|
||||
template <typename T, class Functor>
|
||||
void operator()(T t, Functor function) const { function(t); }
|
||||
};
|
||||
struct TypeCheckInteger
|
||||
{
|
||||
template <typename T, class Functor>
|
||||
void operator()(T t, Functor function) const
|
||||
{
|
||||
this->DoInteger(typename vtkm::TypeTraits<T>::NumericTag(), t, function);
|
||||
}
|
||||
private:
|
||||
template <class Tag, typename T, class Functor>
|
||||
void DoInteger(Tag, T, const Functor&) const { }
|
||||
template <typename T, class Functor>
|
||||
void DoInteger(vtkm::TypeTraitsIntegerTag, T t, Functor function) const
|
||||
{
|
||||
function(t);
|
||||
}
|
||||
};
|
||||
struct TypeCheckReal
|
||||
{
|
||||
template <typename T, class Functor>
|
||||
void operator()(T t, Functor function) const
|
||||
{
|
||||
this->DoReal(typename vtkm::TypeTraits<T>::NumericTag(), t, function);
|
||||
}
|
||||
private:
|
||||
template <class Tag, typename T, class Functor>
|
||||
void DoReal(Tag, T, const Functor&) const { }
|
||||
template <typename T, class Functor>
|
||||
void DoReal(vtkm::TypeTraitsRealTag, T t, Functor function) const
|
||||
{
|
||||
function(t);
|
||||
}
|
||||
};
|
||||
struct TypeCheckScalar
|
||||
{
|
||||
template <typename T, class Functor>
|
||||
void operator()(T t, Functor func) const
|
||||
{
|
||||
this->DoScalar(typename vtkm::TypeTraits<T>::DimensionalityTag(), t, func);
|
||||
}
|
||||
private:
|
||||
template <class Tag, typename T, class Functor>
|
||||
void DoScalar(Tag, const T &, const Functor &) const { }
|
||||
template <typename T, class Functor>
|
||||
void DoScalar(vtkm::TypeTraitsScalarTag, T t, Functor function) const
|
||||
{
|
||||
function(t);
|
||||
}
|
||||
};
|
||||
struct TypeCheckVector
|
||||
{
|
||||
template <typename T, class Functor>
|
||||
void operator()(T t, Functor func) const
|
||||
{
|
||||
this->DoVector(typename vtkm::TypeTraits<T>::DimensionalityTag(), t, func);
|
||||
}
|
||||
private:
|
||||
template <class Tag, typename T, class Functor>
|
||||
void DoVector(Tag, const T &, const Functor &) const { }
|
||||
template <typename T, class Functor>
|
||||
void DoVector(vtkm::TypeTraitsVectorTag, T t, Functor function) const
|
||||
{
|
||||
function(t);
|
||||
}
|
||||
};
|
||||
InternalPrintTypeAndInvoke(FunctionType function) : Function(function) { }
|
||||
|
||||
template<class FunctionType>
|
||||
struct InternalPrintOnInvoke
|
||||
{
|
||||
InternalPrintOnInvoke(FunctionType function, std::string toprint)
|
||||
: Function(function), ToPrint(toprint) { }
|
||||
template <typename T> void operator()(T t)
|
||||
template<typename T>
|
||||
void operator()(T t) const
|
||||
{
|
||||
std::cout << this->ToPrint << std::endl;
|
||||
std::cout << "*** "
|
||||
<< vtkm::testing::TypeName<T>::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<class FunctionType, class CheckType>
|
||||
static void TryAllTypes(FunctionType function, CheckType check)
|
||||
template<class FunctionType, class TypeList>
|
||||
static void TryTypes(const FunctionType &function, TypeList)
|
||||
{
|
||||
vtkm::Id id = 0;
|
||||
check(id, InternalPrintOnInvoke<FunctionType>(
|
||||
function, "*** vtkm::Id ***************"));
|
||||
|
||||
vtkm::Id3 id3 = vtkm::make_Id3(0, 0, 0);
|
||||
check(id3, InternalPrintOnInvoke<FunctionType>(
|
||||
function, "*** vtkm::Id3 **************"));
|
||||
|
||||
vtkm::Scalar scalar = 0.0;
|
||||
check(scalar, InternalPrintOnInvoke<FunctionType>(
|
||||
function, "*** vtkm::Scalar ***********"));
|
||||
|
||||
vtkm::Vector2 vector2 = vtkm::make_Vector2(0.0, 0.0);
|
||||
check(vector2, InternalPrintOnInvoke<FunctionType>(
|
||||
function, "*** vtkm::Vector2 **********"));
|
||||
|
||||
vtkm::Vector3 vector3 = vtkm::make_Vector3(0.0, 0.0, 0.0);
|
||||
check(vector3, InternalPrintOnInvoke<FunctionType>(
|
||||
function, "*** vtkm::Vector3 **********"));
|
||||
|
||||
vtkm::Vector4 vector4 = vtkm::make_Vector4(0.0, 0.0, 0.0, 0.0);
|
||||
check(vector4, InternalPrintOnInvoke<FunctionType>(
|
||||
function, "*** vtkm::Vector4 **********"));
|
||||
vtkm::ListForEach(InternalPrintTypeAndInvoke<FunctionType>(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<class FunctionType>
|
||||
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<typename VectorType>
|
||||
template<typename VectorType1, typename VectorType2>
|
||||
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<VectorType> Traits;
|
||||
typedef typename vtkm::VecTraits<VectorType1> Traits;
|
||||
BOOST_STATIC_ASSERT(
|
||||
Traits::NUM_COMPONENTS == vtkm::VecTraits<VectorType2>::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
|
||||
|
@ -28,7 +28,7 @@ namespace {
|
||||
|
||||
struct TypeTraitTest
|
||||
{
|
||||
template <typename T> void operator()(T t)
|
||||
template <typename T> 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 <typename T>
|
||||
void TestDimensionality(T, vtkm::TypeTraitsScalarTag)
|
||||
void TestDimensionality(T, vtkm::TypeTraitsScalarTag) const
|
||||
{
|
||||
std::cout << " scalar" << std::endl;
|
||||
VTKM_TEST_ASSERT(vtkm::VecTraits<T>::NUM_COMPONENTS == 1,
|
||||
"Scalar type does not have one component.");
|
||||
}
|
||||
template <typename T>
|
||||
void TestDimensionality(T, vtkm::TypeTraitsVectorTag)
|
||||
void TestDimensionality(T, vtkm::TypeTraitsVectorTag) const
|
||||
{
|
||||
std::cout << " vector" << std::endl;
|
||||
VTKM_TEST_ASSERT(vtkm::VecTraits<T>::NUM_COMPONENTS > 1,
|
||||
@ -53,7 +53,7 @@ private:
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void TestNumeric(T, vtkm::TypeTraitsIntegerTag)
|
||||
void TestNumeric(T, vtkm::TypeTraitsIntegerTag) const
|
||||
{
|
||||
std::cout << " integer" << std::endl;
|
||||
typedef typename vtkm::VecTraits<T>::ComponentType VT;
|
||||
@ -61,7 +61,7 @@ private:
|
||||
VTKM_TEST_ASSERT(value == 2, "Integer does not round to integer.");
|
||||
}
|
||||
template <typename T>
|
||||
void TestNumeric(T, vtkm::TypeTraitsRealTag)
|
||||
void TestNumeric(T, vtkm::TypeTraitsRealTag) const
|
||||
{
|
||||
std::cout << " real" << std::endl;
|
||||
typedef typename vtkm::VecTraits<T>::ComponentType VT;
|
||||
|
@ -59,8 +59,11 @@ void CheckTypeSizes()
|
||||
}
|
||||
|
||||
//general type test
|
||||
template <typename T> void TypeTest()
|
||||
template<typename ComponentType, vtkm::IdComponent Size>
|
||||
void GeneralVecTypeTest(const vtkm::Vec<ComponentType,Size> &)
|
||||
{
|
||||
typedef vtkm::Vec<ComponentType,Size> T;
|
||||
|
||||
//grab the number of elements of T
|
||||
T a, b, c;
|
||||
typename T::ComponentType s(5);
|
||||
@ -143,38 +146,49 @@ template <typename T> void TypeTest()
|
||||
VTKM_TEST_ASSERT( (a != c), "operator != wrong");
|
||||
}
|
||||
|
||||
template<> void TypeTest<vtkm::Vector2>()
|
||||
template<typename ComponentType, vtkm::IdComponent Size>
|
||||
void TypeTest(const vtkm::Vec<ComponentType,Size> &)
|
||||
{
|
||||
vtkm::Vector2 a = vtkm::make_Vector2(2, 4);
|
||||
vtkm::Vector2 b = vtkm::make_Vector2(1, 2);
|
||||
vtkm::Scalar s = 5;
|
||||
GeneralVecTypeTest(vtkm::Vec<ComponentType,Size>());
|
||||
}
|
||||
|
||||
vtkm::Vector2 plus = a + b;
|
||||
VTKM_TEST_ASSERT(test_equal(plus, vtkm::make_Vector2(3, 6)),
|
||||
template<typename Scalar>
|
||||
void TypeTest(const vtkm::Vec<Scalar,2> &)
|
||||
{
|
||||
typedef vtkm::Vec<Scalar,2> 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::Vector2>()
|
||||
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::Vector2>()
|
||||
VTKM_TEST_ASSERT( (a != c), "operator != wrong");
|
||||
}
|
||||
|
||||
template<> void TypeTest<vtkm::Vector3>()
|
||||
template<typename Scalar>
|
||||
void TypeTest(const vtkm::Vec<Scalar,3> &)
|
||||
{
|
||||
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<Scalar,3> 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::Vector3>()
|
||||
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::Vector3>()
|
||||
VTKM_TEST_ASSERT( (a != c), "operator != wrong");
|
||||
}
|
||||
|
||||
template<> void TypeTest<vtkm::Vector4>()
|
||||
template<typename Scalar>
|
||||
void TypeTest(const vtkm::Vec<Scalar,4> &)
|
||||
{
|
||||
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<Scalar,4> 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::Vector4>()
|
||||
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::Vector4>()
|
||||
VTKM_TEST_ASSERT( (a != c), "operator != wrong");
|
||||
}
|
||||
|
||||
template<> void TypeTest<vtkm::Id3>()
|
||||
template<typename Scalar>
|
||||
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>()
|
||||
{
|
||||
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<vtkm::Scalar>()
|
||||
}
|
||||
}
|
||||
|
||||
template<> void TypeTest<vtkm::Id>()
|
||||
{
|
||||
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 <typename T> void operator()(const T&) const
|
||||
{
|
||||
TypeTest<T>();
|
||||
TypeTest(T());
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user