2014-02-11 17:34:56 +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.
|
|
|
|
// Copyright 2014. Los Alamos National Security
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_SERIAL
|
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandleCounting.h>
|
2014-07-17 20:35:39 +00:00
|
|
|
#include <vtkm/cont/Assert.h>
|
2014-02-11 17:34:56 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
|
2014-07-17 20:35:39 +00:00
|
|
|
#include <string>
|
|
|
|
|
2014-02-11 17:34:56 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
const vtkm::Id ARRAY_SIZE = 10;
|
|
|
|
|
2014-07-17 20:35:39 +00:00
|
|
|
// An unusual data type that represents a number with a string of a
|
|
|
|
// particular length. This makes sure that the ArrayHandleCounting
|
|
|
|
// works correctly with type casts.
|
|
|
|
class StringInt
|
2014-02-11 17:34:56 +00:00
|
|
|
{
|
2014-07-17 20:35:39 +00:00
|
|
|
public:
|
|
|
|
StringInt() {}
|
|
|
|
StringInt(vtkm::Id v)
|
|
|
|
{
|
|
|
|
VTKM_ASSERT_CONT(v >= 0);
|
|
|
|
for (vtkm::Id i = 0; i < v; i++)
|
|
|
|
{
|
|
|
|
++(*this);
|
|
|
|
}
|
|
|
|
}
|
2014-02-11 17:34:56 +00:00
|
|
|
|
2015-05-07 22:34:06 +00:00
|
|
|
operator vtkm::Id() const { return vtkm::Id(this->Value.size()); }
|
|
|
|
|
2014-07-17 20:35:39 +00:00
|
|
|
StringInt operator+(const StringInt &rhs) const
|
|
|
|
{
|
|
|
|
return StringInt(this->Value + rhs.Value);
|
|
|
|
}
|
2014-02-11 17:34:56 +00:00
|
|
|
|
2014-07-17 20:35:39 +00:00
|
|
|
bool operator==(const StringInt &other) const
|
|
|
|
{
|
|
|
|
return this->Value.size() == other.Value.size();
|
|
|
|
}
|
2014-06-19 17:12:54 +00:00
|
|
|
|
2014-07-17 20:35:39 +00:00
|
|
|
StringInt &operator++()
|
|
|
|
{
|
|
|
|
this->Value.append(".");
|
|
|
|
return *this;
|
|
|
|
}
|
2014-02-11 17:34:56 +00:00
|
|
|
|
2014-07-17 20:35:39 +00:00
|
|
|
private:
|
|
|
|
StringInt(const std::string &v) : Value(v) { }
|
2014-02-11 17:34:56 +00:00
|
|
|
|
2014-07-17 20:35:39 +00:00
|
|
|
std::string Value;
|
2014-02-11 17:34:56 +00:00
|
|
|
};
|
|
|
|
|
2015-05-07 22:34:06 +00:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
VTKM_BASIC_TYPE_VECTOR(StringInt)
|
|
|
|
|
|
|
|
namespace {
|
2014-02-11 17:34:56 +00:00
|
|
|
|
|
|
|
template< typename ValueType>
|
|
|
|
struct TemplatedTests
|
|
|
|
{
|
|
|
|
typedef vtkm::cont::ArrayHandleCounting<ValueType> ArrayHandleType;
|
|
|
|
|
|
|
|
typedef vtkm::cont::ArrayHandle<ValueType,
|
2014-02-11 21:20:30 +00:00
|
|
|
typename vtkm::cont::internal::ArrayHandleCountingTraits<ValueType>::Tag>
|
|
|
|
ArrayHandleType2;
|
2014-02-11 17:34:56 +00:00
|
|
|
|
|
|
|
typedef typename ArrayHandleType::PortalConstControl PortalType;
|
|
|
|
|
|
|
|
void operator()( const ValueType startingValue )
|
|
|
|
{
|
2014-02-11 21:20:30 +00:00
|
|
|
ArrayHandleType arrayConst(startingValue, ARRAY_SIZE);
|
2014-02-11 17:34:56 +00:00
|
|
|
|
2014-02-11 21:20:30 +00:00
|
|
|
ArrayHandleType arrayMake = vtkm::cont::make_ArrayHandleCounting(startingValue,ARRAY_SIZE);
|
2014-02-11 17:34:56 +00:00
|
|
|
|
2014-02-11 21:20:30 +00:00
|
|
|
ArrayHandleType2 arrayHandle =
|
2014-02-11 17:34:56 +00:00
|
|
|
ArrayHandleType2(PortalType(startingValue, ARRAY_SIZE));
|
|
|
|
|
2014-02-11 21:20:30 +00:00
|
|
|
VTKM_TEST_ASSERT(arrayConst.GetNumberOfValues() == ARRAY_SIZE,
|
|
|
|
"Counting array using constructor has wrong size.");
|
2014-02-11 17:34:56 +00:00
|
|
|
|
2014-02-11 21:20:30 +00:00
|
|
|
VTKM_TEST_ASSERT(arrayMake.GetNumberOfValues() == ARRAY_SIZE,
|
|
|
|
"Counting array using make has wrong size.");
|
2014-02-11 17:34:56 +00:00
|
|
|
|
2014-02-11 21:20:30 +00:00
|
|
|
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
|
|
|
|
"Counting array using raw array handle + tag has wrong size.");
|
2014-02-11 17:34:56 +00:00
|
|
|
|
2014-02-11 21:20:30 +00:00
|
|
|
ValueType properValue = startingValue;
|
|
|
|
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
2014-02-11 17:34:56 +00:00
|
|
|
{
|
2014-02-11 21:20:30 +00:00
|
|
|
VTKM_TEST_ASSERT(arrayConst.GetPortalConstControl().Get(index) == properValue,
|
|
|
|
"Counting array using constructor has unexpected value.");
|
|
|
|
VTKM_TEST_ASSERT(arrayMake.GetPortalConstControl().Get(index) == properValue,
|
|
|
|
"Counting array using make has unexpected value.");
|
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(arrayHandle.GetPortalConstControl().Get(index) == properValue,
|
|
|
|
"Counting array using raw array handle + tag has unexpected value.");
|
|
|
|
++properValue;
|
2014-02-11 17:34:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TestFunctor
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
void operator()(const T t)
|
|
|
|
{
|
|
|
|
TemplatedTests<T> tests;
|
|
|
|
tests(t);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestArrayHandleCounting()
|
|
|
|
{
|
|
|
|
TestFunctor()(vtkm::Id(0));
|
2014-10-09 14:54:56 +00:00
|
|
|
TestFunctor()(vtkm::Float32(0));
|
|
|
|
TestFunctor()(vtkm::Float64(0));
|
2014-07-17 20:35:39 +00:00
|
|
|
TestFunctor()(StringInt(0));
|
|
|
|
TestFunctor()(StringInt(10));
|
2014-02-11 17:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // annonymous namespace
|
|
|
|
|
|
|
|
int UnitTestArrayHandleCounting(int, char *[])
|
|
|
|
{
|
|
|
|
return vtkm::cont::testing::Testing::Run(TestArrayHandleCounting);
|
|
|
|
}
|