vtk-m/vtkm/testing/UnitTestVecFromPortalPermute.cxx

111 lines
3.5 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.
2019-04-15 23:24:21 +00:00
//
2015-08-14 14:10:17 +00:00
// 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.
//============================================================================
#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 constexpr vtkm::IdComponent ARRAY_SIZE = 10;
2015-08-14 14:10:17 +00:00
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:
2018-02-22 13:29:13 +00:00
using ValueType = T;
2015-08-14 14:10:17 +00:00
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
{
2018-02-22 13:29:13 +00:00
using PortalType = TestPortal<T>;
using IndexVecType = vtkm::VecVariable<vtkm::Id, ARRAY_SIZE>;
using VecType = vtkm::VecFromPortalPermute<IndexVecType, PortalType>;
using TTraits = vtkm::TypeTraits<VecType>;
using VTraits = vtkm::VecTraits<VecType>;
2015-08-14 14:10:17 +00:00
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()
{
vtkm::testing::Testing::TryTypes(VecFromPortalPermuteTestFunctor(), vtkm::TypeListCommon());
2015-08-14 14:10:17 +00:00
}
} // namespace UnitTestVecFromPortalPermuteNamespace
2015-08-14 14:10:17 +00:00
int UnitTestVecFromPortalPermute(int argc, char* argv[])
2015-08-14 14:10:17 +00:00
{
return vtkm::testing::Testing::Run(
UnitTestVecFromPortalPermuteNamespace::VecFromPortalPermuteTest, argc, argv);
2015-08-14 14:10:17 +00:00
}