2014-02-10 18:58:41 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//
|
|
|
|
// Copyright 2014 Sandia Corporation.
|
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
2015-05-21 12:09:22 +00:00
|
|
|
// Copyright 2014 Los Alamos National Security.
|
2014-02-10 18:58:41 +00:00
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
|
|
|
// the U.S. Government retains certain rights in this software.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
|
|
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
|
|
|
// this software.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/Types.h>
|
|
|
|
|
|
|
|
#include <vtkm/testing/Testing.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2014-10-07 16:59:34 +00:00
|
|
|
void CheckTypeSizes()
|
|
|
|
{
|
2016-11-30 22:03:30 +00:00
|
|
|
std::cout << "Checking sizes of base types." << std::endl;
|
2014-10-07 16:59:34 +00:00
|
|
|
VTKM_TEST_ASSERT(sizeof(vtkm::Int8) == 1, "Int8 wrong size.");
|
|
|
|
VTKM_TEST_ASSERT(sizeof(vtkm::UInt8) == 1, "UInt8 wrong size.");
|
|
|
|
VTKM_TEST_ASSERT(sizeof(vtkm::Int16) == 2, "Int16 wrong size.");
|
|
|
|
VTKM_TEST_ASSERT(sizeof(vtkm::UInt16) == 2, "UInt16 wrong size.");
|
|
|
|
VTKM_TEST_ASSERT(sizeof(vtkm::Int32) == 4, "Int32 wrong size.");
|
|
|
|
VTKM_TEST_ASSERT(sizeof(vtkm::UInt32) == 4, "UInt32 wrong size.");
|
|
|
|
VTKM_TEST_ASSERT(sizeof(vtkm::Int64) == 8, "Int64 wrong size.");
|
|
|
|
VTKM_TEST_ASSERT(sizeof(vtkm::UInt64) == 8, "UInt64 wrong size.");
|
|
|
|
VTKM_TEST_ASSERT(sizeof(vtkm::Float32) == 4, "Float32 wrong size.");
|
|
|
|
VTKM_TEST_ASSERT(sizeof(vtkm::Float64) == 8, "Float32 wrong size.");
|
|
|
|
}
|
|
|
|
|
2015-06-30 19:58:56 +00:00
|
|
|
// This part of the test has to be broken out of GeneralVecTypeTest because
|
|
|
|
// the negate operation is only supported on vectors of signed types.
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ComponentType, vtkm::IdComponent Size>
|
|
|
|
void DoGeneralVecTypeTestNegate(const vtkm::Vec<ComponentType, Size>&)
|
2015-06-30 19:58:56 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
typedef vtkm::Vec<ComponentType, Size> VectorType;
|
2015-06-30 19:58:56 +00:00
|
|
|
for (vtkm::Id valueIndex = 0; valueIndex < 10; valueIndex++)
|
|
|
|
{
|
|
|
|
VectorType original = TestValue(valueIndex, VectorType());
|
|
|
|
VectorType negative = -original;
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent componentIndex = 0; componentIndex < Size; componentIndex++)
|
2015-06-30 19:58:56 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(-(original[componentIndex]), negative[componentIndex]),
|
|
|
|
"Vec did not negate correctly.");
|
2015-06-30 19:58:56 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(original, -negative), "Double Vec negative is not positive.");
|
2015-06-30 19:58:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ComponentType, vtkm::IdComponent Size>
|
|
|
|
void GeneralVecTypeTestNegate(const vtkm::Vec<ComponentType, Size>&)
|
2015-06-30 19:58:56 +00:00
|
|
|
{
|
|
|
|
// Do not test the negate operator unless it is a negatable type.
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <vtkm::IdComponent Size>
|
|
|
|
void GeneralVecTypeTestNegate(const vtkm::Vec<vtkm::Int8, Size>& x)
|
2015-06-30 19:58:56 +00:00
|
|
|
{
|
|
|
|
DoGeneralVecTypeTestNegate(x);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <vtkm::IdComponent Size>
|
|
|
|
void GeneralVecTypeTestNegate(const vtkm::Vec<vtkm::Int16, Size>& x)
|
2015-06-30 19:58:56 +00:00
|
|
|
{
|
|
|
|
DoGeneralVecTypeTestNegate(x);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <vtkm::IdComponent Size>
|
|
|
|
void GeneralVecTypeTestNegate(const vtkm::Vec<vtkm::Int32, Size>& x)
|
2015-06-30 19:58:56 +00:00
|
|
|
{
|
|
|
|
DoGeneralVecTypeTestNegate(x);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <vtkm::IdComponent Size>
|
|
|
|
void GeneralVecTypeTestNegate(const vtkm::Vec<vtkm::Int64, Size>& x)
|
2015-06-30 19:58:56 +00:00
|
|
|
{
|
|
|
|
DoGeneralVecTypeTestNegate(x);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <vtkm::IdComponent Size>
|
|
|
|
void GeneralVecTypeTestNegate(const vtkm::Vec<vtkm::Float32, Size>& x)
|
2015-06-30 19:58:56 +00:00
|
|
|
{
|
|
|
|
DoGeneralVecTypeTestNegate(x);
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <vtkm::IdComponent Size>
|
|
|
|
void GeneralVecTypeTestNegate(const vtkm::Vec<vtkm::Float64, Size>& x)
|
2015-06-30 19:58:56 +00:00
|
|
|
{
|
|
|
|
DoGeneralVecTypeTestNegate(x);
|
|
|
|
}
|
|
|
|
|
2016-11-30 22:03:30 +00:00
|
|
|
//general type test for VecC
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ComponentType, vtkm::IdComponent Size>
|
|
|
|
void GeneralVecCTypeTest(const vtkm::Vec<ComponentType, Size>&)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
std::cout << "Checking VecC functionality" << std::endl;
|
|
|
|
|
|
|
|
using T = vtkm::VecC<ComponentType>;
|
2017-05-18 14:29:41 +00:00
|
|
|
using VecT = vtkm::Vec<ComponentType, Size>;
|
2016-11-30 22:03:30 +00:00
|
|
|
|
|
|
|
//grab the number of elements of T
|
|
|
|
VecT aSrc, bSrc, cSrc;
|
|
|
|
T a(aSrc), b(bSrc), c(cSrc);
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(a.GetNumberOfComponents() == Size, "GetNumberOfComponents returns wrong size.");
|
2016-11-30 22:03:30 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < Size; ++i)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
a[i] = ComponentType((i + 1) * 2);
|
|
|
|
b[i] = ComponentType(i + 1);
|
2016-11-30 22:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c = a;
|
|
|
|
VTKM_TEST_ASSERT(test_equal(a, c), "Copy does not work.");
|
|
|
|
|
|
|
|
//verify prefix and postfix increment and decrement
|
2017-05-18 14:29:41 +00:00
|
|
|
++c[Size - 1];
|
|
|
|
c[Size - 1]++;
|
|
|
|
VTKM_TEST_ASSERT(test_equal(c[Size - 1], a[Size - 1] + 2), "Bad increment on component.");
|
|
|
|
--c[Size - 1];
|
|
|
|
c[Size - 1]--;
|
|
|
|
VTKM_TEST_ASSERT(test_equal(c[Size - 1], a[Size - 1]), "Bad decrement on component.");
|
2016-11-30 22:03:30 +00:00
|
|
|
|
|
|
|
c = a;
|
|
|
|
c += b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(c, aSrc + bSrc), "Bad +=");
|
2016-11-30 22:03:30 +00:00
|
|
|
c -= b;
|
|
|
|
VTKM_TEST_ASSERT(test_equal(c, a), "Bad -=");
|
|
|
|
c *= b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(c, aSrc * bSrc), "Bad *=");
|
2016-11-30 22:03:30 +00:00
|
|
|
c /= b;
|
|
|
|
VTKM_TEST_ASSERT(test_equal(c, a), "Bad /=");
|
|
|
|
|
|
|
|
//make c nearly alike a to verify == and != are correct.
|
|
|
|
c = a;
|
2017-05-18 14:29:41 +00:00
|
|
|
c[Size - 1] = ComponentType(c[Size - 1] - 1);
|
2016-11-30 22:03:30 +00:00
|
|
|
|
|
|
|
VecT correct_plus;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < Size; ++i)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
correct_plus[i] = ComponentType(a[i] + b[i]);
|
|
|
|
}
|
|
|
|
VecT plus = a + bSrc;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(plus, correct_plus), "Tuples not added correctly.");
|
2016-11-30 22:03:30 +00:00
|
|
|
plus = aSrc + b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(plus, correct_plus), "Tuples not added correctly.");
|
2016-11-30 22:03:30 +00:00
|
|
|
|
|
|
|
VecT correct_minus;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < Size; ++i)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
correct_minus[i] = ComponentType(a[i] - b[i]);
|
|
|
|
}
|
|
|
|
VecT minus = a - bSrc;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(minus, correct_minus), "Tuples not subtracted correctly.");
|
2016-11-30 22:03:30 +00:00
|
|
|
minus = aSrc - b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(minus, correct_minus), "Tuples not subtracted correctly.");
|
2016-11-30 22:03:30 +00:00
|
|
|
|
|
|
|
VecT correct_mult;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < Size; ++i)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
correct_mult[i] = ComponentType(a[i] * b[i]);
|
|
|
|
}
|
|
|
|
VecT mult = a * bSrc;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(mult, correct_mult), "Tuples not multiplied correctly.");
|
2016-11-30 22:03:30 +00:00
|
|
|
mult = aSrc * b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(mult, correct_mult), "Tuples not multiplied correctly.");
|
2016-11-30 22:03:30 +00:00
|
|
|
|
|
|
|
VecT correct_div;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < Size; ++i)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
correct_div[i] = ComponentType(a[i] / b[i]);
|
|
|
|
}
|
|
|
|
VecT div = a / bSrc;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(div, correct_div), "Tuples not divided correctly.");
|
2016-11-30 22:03:30 +00:00
|
|
|
div = aSrc / b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(div, correct_div), "Tuples not divided correctly.");
|
2016-11-30 22:03:30 +00:00
|
|
|
|
|
|
|
ComponentType d = vtkm::dot(a, b);
|
|
|
|
ComponentType correct_d = 0;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < Size; ++i)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
correct_d = ComponentType(correct_d + a[i] * b[i]);
|
|
|
|
}
|
|
|
|
VTKM_TEST_ASSERT(test_equal(d, correct_d), "dot(Tuple) wrong");
|
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(!(a < b), "operator< wrong");
|
2017-05-18 14:29:41 +00:00
|
|
|
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");
|
|
|
|
VTKM_TEST_ASSERT((c < a), "operator< wrong");
|
2016-11-30 22:03:30 +00:00
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(!(a == b), "operator== wrong");
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((a == a), "operator== wrong");
|
2016-11-30 22:03:30 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((a != b), "operator!= wrong");
|
2016-11-30 22:03:30 +00:00
|
|
|
VTKM_TEST_ASSERT(!(a != a), "operator!= wrong");
|
|
|
|
|
|
|
|
//test against a tuple that shares some values
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(!(c == a), "operator == wrong");
|
|
|
|
VTKM_TEST_ASSERT(!(a == c), "operator == wrong");
|
2016-11-30 22:03:30 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((c != a), "operator != wrong");
|
|
|
|
VTKM_TEST_ASSERT((a != c), "operator != wrong");
|
2016-11-30 22:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//general type test for VecC
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ComponentType, vtkm::IdComponent Size>
|
|
|
|
void GeneralVecCConstTypeTest(const vtkm::Vec<ComponentType, Size>&)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
std::cout << "Checking VecCConst functionality" << std::endl;
|
|
|
|
|
|
|
|
using T = vtkm::VecCConst<ComponentType>;
|
2017-05-18 14:29:41 +00:00
|
|
|
using VecT = vtkm::Vec<ComponentType, Size>;
|
2016-11-30 22:03:30 +00:00
|
|
|
|
|
|
|
//grab the number of elements of T
|
|
|
|
VecT aSrc, bSrc, cSrc;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < Size; ++i)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
aSrc[i] = ComponentType((i + 1) * 2);
|
|
|
|
bSrc[i] = ComponentType(i + 1);
|
2016-11-30 22:03:30 +00:00
|
|
|
}
|
|
|
|
cSrc = aSrc;
|
|
|
|
|
|
|
|
T a(aSrc), b(bSrc), c(cSrc);
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(a.GetNumberOfComponents() == Size, "GetNumberOfComponents returns wrong size.");
|
2016-11-30 22:03:30 +00:00
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(test_equal(a, c), "Comparison not working.");
|
|
|
|
|
|
|
|
//make c nearly alike a to verify == and != are correct.
|
|
|
|
cSrc = aSrc;
|
2017-05-18 14:29:41 +00:00
|
|
|
cSrc[Size - 1] = ComponentType(cSrc[Size - 1] - 1);
|
2016-11-30 22:03:30 +00:00
|
|
|
|
|
|
|
VecT correct_plus;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < Size; ++i)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
correct_plus[i] = ComponentType(a[i] + b[i]);
|
|
|
|
}
|
|
|
|
VecT plus = a + bSrc;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(plus, correct_plus), "Tuples not added correctly.");
|
2016-11-30 22:03:30 +00:00
|
|
|
plus = aSrc + b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(plus, correct_plus), "Tuples not added correctly.");
|
2016-11-30 22:03:30 +00:00
|
|
|
|
|
|
|
VecT correct_minus;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < Size; ++i)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
correct_minus[i] = ComponentType(a[i] - b[i]);
|
|
|
|
}
|
|
|
|
VecT minus = a - bSrc;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(minus, correct_minus), "Tuples not subtracted correctly.");
|
2016-11-30 22:03:30 +00:00
|
|
|
minus = aSrc - b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(minus, correct_minus), "Tuples not subtracted correctly.");
|
2016-11-30 22:03:30 +00:00
|
|
|
|
|
|
|
VecT correct_mult;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < Size; ++i)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
correct_mult[i] = ComponentType(a[i] * b[i]);
|
|
|
|
}
|
|
|
|
VecT mult = a * bSrc;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(mult, correct_mult), "Tuples not multiplied correctly.");
|
2016-11-30 22:03:30 +00:00
|
|
|
mult = aSrc * b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(mult, correct_mult), "Tuples not multiplied correctly.");
|
2016-11-30 22:03:30 +00:00
|
|
|
|
|
|
|
VecT correct_div;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < Size; ++i)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
correct_div[i] = ComponentType(a[i] / b[i]);
|
|
|
|
}
|
|
|
|
VecT div = a / bSrc;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(div, correct_div), "Tuples not divided correctly.");
|
2016-11-30 22:03:30 +00:00
|
|
|
div = aSrc / b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(div, correct_div), "Tuples not divided correctly.");
|
2016-11-30 22:03:30 +00:00
|
|
|
|
|
|
|
ComponentType d = vtkm::dot(a, b);
|
|
|
|
ComponentType correct_d = 0;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < Size; ++i)
|
2016-11-30 22:03:30 +00:00
|
|
|
{
|
|
|
|
correct_d = ComponentType(correct_d + a[i] * b[i]);
|
|
|
|
}
|
|
|
|
VTKM_TEST_ASSERT(test_equal(d, correct_d), "dot(Tuple) wrong");
|
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(!(a < b), "operator< wrong");
|
2017-05-18 14:29:41 +00:00
|
|
|
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");
|
|
|
|
VTKM_TEST_ASSERT((c < a), "operator< wrong");
|
2016-11-30 22:03:30 +00:00
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(!(a == b), "operator== wrong");
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((a == a), "operator== wrong");
|
2016-11-30 22:03:30 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((a != b), "operator!= wrong");
|
2016-11-30 22:03:30 +00:00
|
|
|
VTKM_TEST_ASSERT(!(a != a), "operator!= wrong");
|
|
|
|
|
|
|
|
//test against a tuple that shares some values
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(!(c == a), "operator == wrong");
|
|
|
|
VTKM_TEST_ASSERT(!(a == c), "operator == wrong");
|
2016-11-30 22:03:30 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((c != a), "operator != wrong");
|
|
|
|
VTKM_TEST_ASSERT((a != c), "operator != wrong");
|
2016-11-30 22:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//general type test for Vec
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ComponentType, vtkm::IdComponent Size>
|
|
|
|
void GeneralVecTypeTest(const vtkm::Vec<ComponentType, Size>&)
|
2014-02-10 18:58:41 +00:00
|
|
|
{
|
2016-11-30 22:03:30 +00:00
|
|
|
std::cout << "Checking general Vec functionality." << std::endl;
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
typedef vtkm::Vec<ComponentType, Size> T;
|
2015-08-07 23:58:52 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(T::NUM_COMPONENTS == Size, "NUM_COMPONENTS is wrong size.");
|
2016-08-02 18:21:19 +00:00
|
|
|
|
2014-02-10 18:58:41 +00:00
|
|
|
//grab the number of elements of T
|
|
|
|
T a, b, c;
|
2015-07-30 22:43:19 +00:00
|
|
|
ComponentType s(5);
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(a.GetNumberOfComponents() == Size, "GetNumberOfComponents returns wrong size.");
|
2015-08-07 23:58:52 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < T::NUM_COMPONENTS; ++i)
|
2014-02-11 21:20:30 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
a[i] = ComponentType((i + 1) * 2);
|
|
|
|
b[i] = ComponentType(i + 1);
|
2014-02-11 21:20:30 +00:00
|
|
|
}
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2015-08-07 23:58:52 +00:00
|
|
|
a.CopyInto(c);
|
|
|
|
VTKM_TEST_ASSERT(test_equal(a, c), "CopyInto does not work.");
|
|
|
|
|
2014-02-10 18:58:41 +00:00
|
|
|
//verify prefix and postfix increment and decrement
|
2017-05-18 14:29:41 +00:00
|
|
|
++c[T::NUM_COMPONENTS - 1];
|
|
|
|
c[T::NUM_COMPONENTS - 1]++;
|
|
|
|
VTKM_TEST_ASSERT(test_equal(c[T::NUM_COMPONENTS - 1], a[T::NUM_COMPONENTS - 1] + 2),
|
|
|
|
"Bad increment on component.");
|
|
|
|
--c[T::NUM_COMPONENTS - 1];
|
|
|
|
c[T::NUM_COMPONENTS - 1]--;
|
|
|
|
VTKM_TEST_ASSERT(test_equal(c[T::NUM_COMPONENTS - 1], a[T::NUM_COMPONENTS - 1]),
|
|
|
|
"Bad decrement on component.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
//make c nearly like a to verify == and != are correct.
|
2017-05-18 14:29:41 +00:00
|
|
|
c[T::NUM_COMPONENTS - 1] = ComponentType(c[T::NUM_COMPONENTS - 1] - 1);
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
T plus = a + b;
|
|
|
|
T correct_plus;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < T::NUM_COMPONENTS; ++i)
|
2015-07-30 22:43:19 +00:00
|
|
|
{
|
|
|
|
correct_plus[i] = ComponentType(a[i] + b[i]);
|
|
|
|
}
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(plus, correct_plus), "Tuples not added correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
T minus = a - b;
|
|
|
|
T correct_minus;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < T::NUM_COMPONENTS; ++i)
|
2015-07-30 22:43:19 +00:00
|
|
|
{
|
|
|
|
correct_minus[i] = ComponentType(a[i] - b[i]);
|
|
|
|
}
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(minus, correct_minus), "Tuples not subtracted correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
T mult = a * b;
|
|
|
|
T correct_mult;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < T::NUM_COMPONENTS; ++i)
|
2015-07-30 22:43:19 +00:00
|
|
|
{
|
|
|
|
correct_mult[i] = ComponentType(a[i] * b[i]);
|
|
|
|
}
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(mult, correct_mult), "Tuples not multiplied correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
T div = a / b;
|
|
|
|
T correct_div;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < T::NUM_COMPONENTS; ++i)
|
2015-07-30 22:43:19 +00:00
|
|
|
{
|
|
|
|
correct_div[i] = ComponentType(a[i] / b[i]);
|
|
|
|
}
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(div, correct_div), "Tuples not divided correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
mult = s * a;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < T::NUM_COMPONENTS; ++i)
|
2015-07-30 22:43:19 +00:00
|
|
|
{
|
|
|
|
correct_mult[i] = ComponentType(s * a[i]);
|
|
|
|
}
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(mult, correct_mult), "Scalar and Tuple did not multiply correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
mult = a * s;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(mult, correct_mult), "Tuple and Scalar to not multiply correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2016-08-02 18:21:19 +00:00
|
|
|
div = a / ComponentType(2);
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(div, b), "Tuple does not divide by Scalar correctly.");
|
2016-08-02 18:21:19 +00:00
|
|
|
|
2015-07-30 22:43:19 +00:00
|
|
|
ComponentType d = vtkm::dot(a, b);
|
|
|
|
ComponentType correct_d = 0;
|
2017-05-18 14:29:41 +00:00
|
|
|
for (vtkm::IdComponent i = 0; i < T::NUM_COMPONENTS; ++i)
|
2015-07-30 22:43:19 +00:00
|
|
|
{
|
|
|
|
correct_d = ComponentType(correct_d + a[i] * b[i]);
|
|
|
|
}
|
2014-02-10 18:58:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(d, correct_d), "dot(Tuple) wrong");
|
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(!(a < b), "operator< wrong");
|
2017-05-18 14:29:41 +00:00
|
|
|
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");
|
|
|
|
VTKM_TEST_ASSERT((c < a), "operator< wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(!(a == b), "operator== wrong");
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((a == a), "operator== wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((a != b), "operator!= wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
VTKM_TEST_ASSERT(!(a != a), "operator!= wrong");
|
|
|
|
|
|
|
|
//test against a tuple that shares some values
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(!(c == a), "operator == wrong");
|
|
|
|
VTKM_TEST_ASSERT(!(a == c), "operator == wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((c != a), "operator != wrong");
|
|
|
|
VTKM_TEST_ASSERT((a != c), "operator != wrong");
|
2015-06-30 19:58:56 +00:00
|
|
|
|
|
|
|
GeneralVecTypeTestNegate(T());
|
2016-11-30 22:03:30 +00:00
|
|
|
GeneralVecCTypeTest(T());
|
|
|
|
GeneralVecCConstTypeTest(T());
|
2014-02-10 18:58:41 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ComponentType, vtkm::IdComponent Size>
|
|
|
|
void TypeTest(const vtkm::Vec<ComponentType, Size>&)
|
2014-10-08 22:56:33 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
GeneralVecTypeTest(vtkm::Vec<ComponentType, Size>());
|
2014-10-08 22:56:33 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Scalar>
|
|
|
|
void TypeTest(const vtkm::Vec<Scalar, 2>&)
|
2014-02-10 18:58:41 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
typedef vtkm::Vec<Scalar, 2> Vector;
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2014-10-08 22:56:33 +00:00
|
|
|
GeneralVecTypeTest(Vector());
|
|
|
|
|
|
|
|
Vector a(2, 4);
|
|
|
|
Vector b(1, 2);
|
|
|
|
Scalar s = 5;
|
|
|
|
|
|
|
|
Vector plus = a + b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(plus, vtkm::make_Vec(3, 6)), "Vectors do not add correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2014-10-08 22:56:33 +00:00
|
|
|
Vector minus = a - b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(minus, vtkm::make_Vec(1, 2)), "Vectors to not subtract correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2014-10-08 22:56:33 +00:00
|
|
|
Vector mult = a * b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(2, 8)), "Vectors to not multiply correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2014-10-08 22:56:33 +00:00
|
|
|
Vector div = a / b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(div, vtkm::make_Vec(2, 2)), "Vectors to not divide correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
mult = s * a;
|
2014-10-08 22:56:33 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(10, 20)),
|
2014-02-11 21:20:30 +00:00
|
|
|
"Vector and scalar to not multiply correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
mult = a * s;
|
2014-10-08 22:56:33 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(10, 20)),
|
2014-02-11 21:20:30 +00:00
|
|
|
"Vector and scalar to not multiply correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2016-08-02 18:21:19 +00:00
|
|
|
div = a / Scalar(2);
|
|
|
|
VTKM_TEST_ASSERT(test_equal(div, vtkm::make_Vec(1, 2)),
|
|
|
|
"Vector does not divide by Scalar correctly.");
|
|
|
|
|
2014-10-08 22:56:33 +00:00
|
|
|
Scalar d = vtkm::dot(a, b);
|
|
|
|
VTKM_TEST_ASSERT(test_equal(d, Scalar(10)), "dot(Vector2) wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(!(a < b), "operator< wrong");
|
2017-05-18 14:29:41 +00:00
|
|
|
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");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(!(a == b), "operator== wrong");
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((a == a), "operator== wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((a != b), "operator!= wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
VTKM_TEST_ASSERT(!(a != a), "operator!= wrong");
|
|
|
|
|
|
|
|
//test against a tuple that shares some values
|
2014-10-08 22:56:33 +00:00
|
|
|
const Vector c(2, 3);
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((c < a), "operator< wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(!(c == a), "operator == wrong");
|
|
|
|
VTKM_TEST_ASSERT(!(a == c), "operator == wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((c != a), "operator != wrong");
|
|
|
|
VTKM_TEST_ASSERT((a != c), "operator != wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Scalar>
|
|
|
|
void TypeTest(const vtkm::Vec<Scalar, 3>&)
|
2014-02-10 18:58:41 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
typedef vtkm::Vec<Scalar, 3> Vector;
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2014-10-08 22:56:33 +00:00
|
|
|
GeneralVecTypeTest(Vector());
|
|
|
|
|
|
|
|
Vector a(2, 4, 6);
|
|
|
|
Vector b(1, 2, 3);
|
|
|
|
Scalar s = 5;
|
|
|
|
|
|
|
|
Vector plus = a + b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(plus, vtkm::make_Vec(3, 6, 9)), "Vectors do not add correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2014-10-08 22:56:33 +00:00
|
|
|
Vector minus = a - b;
|
|
|
|
VTKM_TEST_ASSERT(test_equal(minus, vtkm::make_Vec(1, 2, 3)),
|
2014-02-11 21:20:30 +00:00
|
|
|
"Vectors to not subtract correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2014-10-08 22:56:33 +00:00
|
|
|
Vector mult = a * b;
|
|
|
|
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(2, 8, 18)),
|
2014-02-11 21:20:30 +00:00
|
|
|
"Vectors to not multiply correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2014-10-08 22:56:33 +00:00
|
|
|
Vector div = a / b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(div, vtkm::make_Vec(2, 2, 2)), "Vectors to not divide correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
mult = s * a;
|
2014-10-08 22:56:33 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(10, 20, 30)),
|
2014-02-11 21:20:30 +00:00
|
|
|
"Vector and scalar to not multiply correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
mult = a * s;
|
2014-10-08 22:56:33 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(10, 20, 30)),
|
2014-02-11 21:20:30 +00:00
|
|
|
"Vector and scalar to not multiply correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2016-08-02 18:21:19 +00:00
|
|
|
div = a / Scalar(2);
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(div, b), "Vector does not divide by Scalar correctly.");
|
2016-08-02 18:21:19 +00:00
|
|
|
|
2014-10-09 14:54:56 +00:00
|
|
|
Scalar d = vtkm::dot(a, b);
|
2014-10-08 22:56:33 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(d, Scalar(28)), "dot(Vector3) wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(!(a < b), "operator< wrong");
|
2017-05-18 14:29:41 +00:00
|
|
|
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");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(!(a == b), "operator== wrong");
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((a == a), "operator== wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((a != b), "operator!= wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
VTKM_TEST_ASSERT(!(a != a), "operator!= wrong");
|
|
|
|
|
|
|
|
//test against a tuple that shares some values
|
2017-05-18 14:29:41 +00:00
|
|
|
const Vector c(2, 4, 5);
|
|
|
|
VTKM_TEST_ASSERT((c < a), "operator< wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(!(c == a), "operator == wrong");
|
|
|
|
VTKM_TEST_ASSERT(!(a == c), "operator == wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((c != a), "operator != wrong");
|
|
|
|
VTKM_TEST_ASSERT((a != c), "operator != wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Scalar>
|
|
|
|
void TypeTest(const vtkm::Vec<Scalar, 4>&)
|
2014-02-10 18:58:41 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
typedef vtkm::Vec<Scalar, 4> Vector;
|
2014-10-08 22:56:33 +00:00
|
|
|
|
|
|
|
GeneralVecTypeTest(Vector());
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2014-10-08 22:56:33 +00:00
|
|
|
Vector a(2, 4, 6, 8);
|
|
|
|
Vector b(1, 2, 3, 4);
|
|
|
|
Scalar s = 5;
|
|
|
|
|
|
|
|
Vector plus = a + b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(plus, vtkm::make_Vec(3, 6, 9, 12)), "Vectors do not add correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2014-10-08 22:56:33 +00:00
|
|
|
Vector minus = a - b;
|
|
|
|
VTKM_TEST_ASSERT(test_equal(minus, vtkm::make_Vec(1, 2, 3, 4)),
|
2014-02-11 21:20:30 +00:00
|
|
|
"Vectors to not subtract correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2014-10-08 22:56:33 +00:00
|
|
|
Vector mult = a * b;
|
|
|
|
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(2, 8, 18, 32)),
|
2014-02-11 21:20:30 +00:00
|
|
|
"Vectors to not multiply correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2014-10-08 22:56:33 +00:00
|
|
|
Vector div = a / b;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(div, vtkm::make_Vec(2, 2, 2, 2)), "Vectors to not divide correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
mult = s * a;
|
2014-10-08 22:56:33 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(10, 20, 30, 40)),
|
2014-02-11 21:20:30 +00:00
|
|
|
"Vector and scalar to not multiply correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
mult = a * s;
|
2014-10-08 22:56:33 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(mult, vtkm::make_Vec(10, 20, 30, 40)),
|
2014-02-11 21:20:30 +00:00
|
|
|
"Vector and scalar to not multiply correctly.");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2016-08-02 18:21:19 +00:00
|
|
|
div = a / Scalar(2);
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(div, b), "Vector does not divide by Scalar correctly.");
|
2016-08-02 18:21:19 +00:00
|
|
|
|
2014-10-09 14:54:56 +00:00
|
|
|
Scalar d = vtkm::dot(a, b);
|
|
|
|
VTKM_TEST_ASSERT(test_equal(d, Scalar(60)), "dot(Vector4) wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(!(a < b), "operator< wrong");
|
2017-05-18 14:29:41 +00:00
|
|
|
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");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(!(a == b), "operator== wrong");
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((a == a), "operator== wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((a != b), "operator!= wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
VTKM_TEST_ASSERT(!(a != a), "operator!= wrong");
|
|
|
|
|
|
|
|
//test against a tuple that shares some values
|
2017-05-18 14:29:41 +00:00
|
|
|
const Vector c(2, 4, 6, 7);
|
|
|
|
VTKM_TEST_ASSERT((c < a), "operator< wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(!(c == a), "operator == wrong");
|
|
|
|
VTKM_TEST_ASSERT(!(a == c), "operator == wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT((c != a), "operator != wrong");
|
|
|
|
VTKM_TEST_ASSERT((a != c), "operator != wrong");
|
2014-02-10 18:58:41 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Scalar>
|
2014-10-08 22:56:33 +00:00
|
|
|
void TypeTest(Scalar)
|
2014-02-10 18:58:41 +00:00
|
|
|
{
|
2016-11-30 22:03:30 +00:00
|
|
|
std::cout << "Test functionality of scalar type." << std::endl;
|
|
|
|
|
2014-10-08 22:56:33 +00:00
|
|
|
Scalar a = 4;
|
|
|
|
Scalar b = 2;
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2015-07-30 22:43:19 +00:00
|
|
|
Scalar plus = Scalar(a + b);
|
2014-02-10 18:58:41 +00:00
|
|
|
if (plus != 6)
|
2014-02-11 21:20:30 +00:00
|
|
|
{
|
2014-02-10 18:58:41 +00:00
|
|
|
VTKM_TEST_FAIL("Scalars do not add correctly.");
|
2014-02-11 21:20:30 +00:00
|
|
|
}
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2015-07-30 22:43:19 +00:00
|
|
|
Scalar minus = Scalar(a - b);
|
2014-02-10 18:58:41 +00:00
|
|
|
if (minus != 2)
|
2014-02-11 21:20:30 +00:00
|
|
|
{
|
2014-02-10 18:58:41 +00:00
|
|
|
VTKM_TEST_FAIL("Scalars to not subtract correctly.");
|
2014-02-11 21:20:30 +00:00
|
|
|
}
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2015-07-30 22:43:19 +00:00
|
|
|
Scalar mult = Scalar(a * b);
|
2014-02-10 18:58:41 +00:00
|
|
|
if (mult != 8)
|
2014-02-11 21:20:30 +00:00
|
|
|
{
|
2014-02-10 18:58:41 +00:00
|
|
|
VTKM_TEST_FAIL("Scalars to not multiply correctly.");
|
2014-02-11 21:20:30 +00:00
|
|
|
}
|
2014-02-10 18:58:41 +00:00
|
|
|
|
2015-07-30 22:43:19 +00:00
|
|
|
Scalar div = Scalar(a / b);
|
2014-02-10 18:58:41 +00:00
|
|
|
if (div != 2)
|
2014-02-11 21:20:30 +00:00
|
|
|
{
|
2014-02-10 18:58:41 +00:00
|
|
|
VTKM_TEST_FAIL("Scalars to not divide correctly.");
|
2014-02-11 21:20:30 +00:00
|
|
|
}
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
if (a == b)
|
2014-02-11 21:20:30 +00:00
|
|
|
{
|
2014-02-10 18:58:41 +00:00
|
|
|
VTKM_TEST_FAIL("operator== wrong");
|
2014-02-11 21:20:30 +00:00
|
|
|
}
|
2014-02-10 18:58:41 +00:00
|
|
|
if (!(a != b))
|
2014-02-11 21:20:30 +00:00
|
|
|
{
|
2014-02-10 18:58:41 +00:00
|
|
|
VTKM_TEST_FAIL("operator!= wrong");
|
2014-02-11 21:20:30 +00:00
|
|
|
}
|
2014-02-10 18:58:41 +00:00
|
|
|
|
|
|
|
if (vtkm::dot(a, b) != 8)
|
2014-02-11 21:20:30 +00:00
|
|
|
{
|
2014-02-10 18:58:41 +00:00
|
|
|
VTKM_TEST_FAIL("dot(Scalar) wrong");
|
2014-02-11 21:20:30 +00:00
|
|
|
}
|
2014-02-10 18:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct TypeTestFunctor
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
|
|
|
void operator()(const T&) const
|
2014-02-11 21:20:30 +00:00
|
|
|
{
|
2014-10-08 22:56:33 +00:00
|
|
|
TypeTest(T());
|
2014-02-10 18:58:41 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-26 17:53:28 +00:00
|
|
|
struct TypesToTest : vtkm::ListTagJoin<vtkm::testing::Testing::TypeListTagExemplarTypes,
|
|
|
|
vtkm::ListTagBase<vtkm::Vec<vtkm::FloatDefault, 6>,
|
|
|
|
vtkm::Vec<vtkm::Id, 4>,
|
|
|
|
vtkm::Vec<unsigned char, 4>,
|
|
|
|
vtkm::Vec<vtkm::Id, 1>,
|
|
|
|
vtkm::Vec<vtkm::Float64, 1>>>
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
|
|
|
};
|
2016-11-30 22:03:30 +00:00
|
|
|
|
2014-02-10 18:58:41 +00:00
|
|
|
void TestTypes()
|
|
|
|
{
|
2014-10-07 16:59:34 +00:00
|
|
|
CheckTypeSizes();
|
|
|
|
|
2016-11-30 22:03:30 +00:00
|
|
|
vtkm::testing::Testing::TryTypes(TypeTestFunctor(), TypesToTest());
|
2014-02-10 18:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
int UnitTestTypes(int, char* [])
|
2014-02-10 18:58:41 +00:00
|
|
|
{
|
|
|
|
return vtkm::testing::Testing::Run(TestTypes);
|
|
|
|
}
|