vtk-m2/vtkm/testing/UnitTestVecFromPortalPermute.cxx

121 lines
3.9 KiB
C++
Raw Normal View History

2015-08-14 14:10:17 +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 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
2015-08-14 14:10:17 +00:00
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
2015-08-14 14:10:17 +00:00
// 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/VecFromPortalPermute.h>
2015-08-14 14:10:17 +00:00
#include <vtkm/VecVariable.h>
#include <vtkm/testing/Testing.h>
2017-05-18 14:29:41 +00:00
namespace UnitTestVecFromPortalPermuteNamespace
{
2015-08-14 14:10:17 +00:00
static const vtkm::IdComponent ARRAY_SIZE = 10;
2017-05-18 14:29:41 +00:00
template <typename T>
2015-08-14 14:10:17 +00:00
void CheckType(T, T)
{
// Check passes if this function is called correctly.
}
2017-05-18 14:29:41 +00:00
template <typename T>
2015-08-14 14:10:17 +00:00
class TestPortal
{
public:
typedef T ValueType;
VTKM_EXEC
2015-08-14 14:10:17 +00:00
vtkm::Id GetNumberOfValues() const { return ARRAY_SIZE; }
VTKM_EXEC
2015-08-14 14:10:17 +00:00
ValueType Get(vtkm::Id index) const { return TestValue(index, ValueType()); }
};
struct VecFromPortalPermuteTestFunctor
{
2017-05-18 14:29:41 +00:00
template <typename T>
2015-08-14 14:10:17 +00:00
void operator()(T) const
{
typedef TestPortal<T> PortalType;
2017-05-18 14:29:41 +00:00
typedef vtkm::VecVariable<vtkm::Id, ARRAY_SIZE> IndexVecType;
typedef vtkm::VecFromPortalPermute<IndexVecType, PortalType> VecType;
2015-08-14 14:10:17 +00:00
typedef vtkm::TypeTraits<VecType> TTraits;
typedef vtkm::VecTraits<VecType> VTraits;
std::cout << "Checking VecFromPortal traits" << std::endl;
// The statements will fail to compile if the traits is not working as
// expected.
2017-05-18 14:29:41 +00:00
CheckType(typename TTraits::DimensionalityTag(), vtkm::TypeTraitsVectorTag());
2015-08-14 14:10:17 +00:00
CheckType(typename VTraits::ComponentType(), T());
2017-05-18 14:29:41 +00:00
CheckType(typename VTraits::HasMultipleComponents(), vtkm::VecTraitsTagMultipleComponents());
CheckType(typename VTraits::IsSizeStatic(), vtkm::VecTraitsTagSizeVariable());
2015-08-14 14:10:17 +00:00
std::cout << "Checking VecFromPortal contents" << std::endl;
PortalType portal;
for (vtkm::Id offset = 0; offset < ARRAY_SIZE; offset++)
{
2017-05-18 14:29:41 +00:00
for (vtkm::IdComponent length = 0; 2 * length + offset < ARRAY_SIZE; length++)
2015-08-14 14:10:17 +00:00
{
IndexVecType indices;
for (vtkm::IdComponent index = 0; index < length; index++)
{
2017-05-18 14:29:41 +00:00
indices.Append(offset + 2 * index);
2015-08-14 14:10:17 +00:00
}
VecType vec(&indices, portal);
2015-08-14 14:10:17 +00:00
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(vec.GetNumberOfComponents() == length, "Wrong length.");
VTKM_TEST_ASSERT(VTraits::GetNumberOfComponents(vec) == length, "Wrong length.");
2015-08-14 14:10:17 +00:00
2017-05-18 14:29:41 +00:00
vtkm::Vec<T, ARRAY_SIZE> copyDirect;
2015-08-14 14:10:17 +00:00
vec.CopyInto(copyDirect);
2017-05-18 14:29:41 +00:00
vtkm::Vec<T, ARRAY_SIZE> copyTraits;
2015-08-14 14:10:17 +00:00
VTraits::CopyInto(vec, copyTraits);
for (vtkm::IdComponent index = 0; index < length; index++)
{
2017-05-18 14:29:41 +00:00
T expected = TestValue(2 * index + offset, T());
2015-08-14 14:10:17 +00:00
VTKM_TEST_ASSERT(test_equal(vec[index], expected), "Wrong value.");
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(test_equal(VTraits::GetComponent(vec, index), expected), "Wrong value.");
VTKM_TEST_ASSERT(test_equal(copyDirect[index], expected), "Wrong copied value.");
VTKM_TEST_ASSERT(test_equal(copyTraits[index], expected), "Wrong copied value.");
2015-08-14 14:10:17 +00:00
}
}
}
}
};
void VecFromPortalPermuteTest()
{
2017-05-18 14:29:41 +00:00
vtkm::testing::Testing::TryTypes(VecFromPortalPermuteTestFunctor(), vtkm::TypeListTagCommon());
2015-08-14 14:10:17 +00:00
}
} // namespace UnitTestVecFromPortalPermuteNamespace
2015-08-14 14:10:17 +00:00
2017-05-18 14:29:41 +00:00
int UnitTestVecFromPortalPermute(int, char* [])
2015-08-14 14:10:17 +00:00
{
return vtkm::testing::Testing::Run(
2017-05-18 14:29:41 +00:00
UnitTestVecFromPortalPermuteNamespace::VecFromPortalPermuteTest);
2015-08-14 14:10:17 +00:00
}