vtk-m2/vtkm/testing/UnitTestBinaryOperators.cxx

126 lines
3.8 KiB
C++
Raw Normal View History

2015-08-04 13:59:00 +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 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
2015-08-04 13:59:00 +00:00
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
2015-08-04 13:59:00 +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/BinaryOperators.h>
#include <vtkm/testing/Testing.h>
2017-05-18 14:29:41 +00:00
namespace
{
2015-08-04 13:59:00 +00:00
//general pair test
template <typename T>
2017-05-18 14:29:41 +00:00
void BinaryOperatorTest(){
2015-08-04 13:59:00 +00:00
//Not using TestValue method as it causes roll-over to occur with
//uint8 and int8 leading to unexpected comparisons.
//test Sum
2017-05-18 14:29:41 +00:00
{ vtkm::Sum sum;
T result;
2015-08-04 13:59:00 +00:00
2017-05-18 14:29:41 +00:00
result = sum(vtkm::TypeTraits<T>::ZeroInitialization(), T(1));
VTKM_TEST_ASSERT(result == T(1), "Sum wrong.");
2015-08-04 13:59:00 +00:00
2017-05-18 14:29:41 +00:00
result = sum(T(1), T(1));
VTKM_TEST_ASSERT(result == T(2), "Sum wrong.");
}
2015-08-04 13:59:00 +00:00
2017-05-18 14:29:41 +00:00
//test Product
{
2015-08-04 13:59:00 +00:00
vtkm::Product product;
T result;
2017-05-18 14:29:41 +00:00
result = product(vtkm::TypeTraits<T>::ZeroInitialization(), T(1));
VTKM_TEST_ASSERT(result == vtkm::TypeTraits<T>::ZeroInitialization(), "Product wrong.");
2015-08-04 13:59:00 +00:00
2017-05-18 14:29:41 +00:00
result = product(T(1), T(1));
VTKM_TEST_ASSERT(result == T(1), "Product wrong.");
2015-08-04 13:59:00 +00:00
2017-05-18 14:29:41 +00:00
result = product(T(2), T(3));
VTKM_TEST_ASSERT(result == T(6), "Product wrong.");
}
2015-08-04 13:59:00 +00:00
2017-05-18 14:29:41 +00:00
//test Maximum
{
2015-08-04 13:59:00 +00:00
vtkm::Maximum maximum;
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(maximum(T(1), T(2)) == T(2), "Maximum wrong.");
VTKM_TEST_ASSERT(maximum(T(2), T(2)) == T(2), "Maximum wrong.");
VTKM_TEST_ASSERT(maximum(T(2), T(1)) == T(2), "Maximum wrong.");
}
2015-08-04 13:59:00 +00:00
2017-05-18 14:29:41 +00:00
//test Minimum
{
2015-08-04 13:59:00 +00:00
vtkm::Minimum minimum;
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(minimum(T(1), T(2)) == T(1), "Minimum wrong.");
VTKM_TEST_ASSERT(minimum(T(1), T(1)) == T(1), "Minimum wrong.");
VTKM_TEST_ASSERT(minimum(T(3), T(2)) == T(2), "Minimum wrong.");
}
}
;
2015-08-04 13:59:00 +00:00
struct BinaryOperatorTestFunctor
{
2017-05-18 14:29:41 +00:00
template <typename T>
void operator()(const T&) const
2015-08-04 13:59:00 +00:00
{
BinaryOperatorTest<T>();
}
};
void TestBinaryOperators()
{
vtkm::testing::Testing::TryTypes(BinaryOperatorTestFunctor());
2015-08-04 13:59:00 +00:00
//test BitwiseAnd
{
2017-05-18 14:29:41 +00:00
vtkm::BitwiseAnd bitwise_and;
VTKM_TEST_ASSERT(bitwise_and(true, true) == true, "bitwise_and true wrong.");
VTKM_TEST_ASSERT(bitwise_and(true, false) == false, "bitwise_and true wrong.");
VTKM_TEST_ASSERT(bitwise_and(false, true) == false, "bitwise_and true wrong.");
VTKM_TEST_ASSERT(bitwise_and(false, false) == false, "bitwise_and true wrong.");
2015-08-04 13:59:00 +00:00
}
//test BitwiseOr
{
2017-05-18 14:29:41 +00:00
vtkm::BitwiseOr bitwise_or;
VTKM_TEST_ASSERT(bitwise_or(true, true) == true, "bitwise_or true wrong.");
VTKM_TEST_ASSERT(bitwise_or(true, false) == true, "bitwise_or true wrong.");
VTKM_TEST_ASSERT(bitwise_or(false, true) == true, "bitwise_or true wrong.");
VTKM_TEST_ASSERT(bitwise_or(false, false) == false, "bitwise_or true wrong.");
2015-08-04 13:59:00 +00:00
}
//test BitwiseXor
{
2017-05-18 14:29:41 +00:00
vtkm::BitwiseXor bitwise_xor;
VTKM_TEST_ASSERT(bitwise_xor(true, true) == false, "bitwise_xor true wrong.");
VTKM_TEST_ASSERT(bitwise_xor(true, false) == true, "bitwise_xor true wrong.");
VTKM_TEST_ASSERT(bitwise_xor(false, true) == true, "bitwise_xor true wrong.");
VTKM_TEST_ASSERT(bitwise_xor(false, false) == false, "bitwise_xor true wrong.");
2015-08-04 13:59:00 +00:00
}
}
} // anonymous namespace
2017-05-18 14:29:41 +00:00
int UnitTestBinaryOperators(int, char* [])
2015-08-04 13:59:00 +00:00
{
return vtkm::testing::Testing::Run(TestBinaryOperators);
}