vtk-m/vtkm/testing/UnitTestBinaryPredicates.cxx

108 lines
3.3 KiB
C++
Raw Normal View History

2015-08-04 13:34:38 +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.
//============================================================================
#include <vtkm/BinaryPredicates.h>
#include <vtkm/testing/Testing.h>
2017-05-18 14:29:41 +00:00
namespace
{
2015-08-04 13:34:38 +00:00
//general pair test
template <typename T>
2017-05-18 14:29:41 +00:00
void BinaryPredicateTest(){
2015-08-04 13:34:38 +00:00
//Not using TestValue method as it causes roll-over to occur with
//uint8 and int8 leading to unexpected comparisons.
//test Equal
2017-05-18 14:29:41 +00:00
{ vtkm::Equal is_equal;
VTKM_TEST_ASSERT(is_equal(vtkm::TypeTraits<T>::ZeroInitialization(),
vtkm::TypeTraits<T>::ZeroInitialization()),
"Equal wrong.");
2015-08-04 13:34:38 +00:00
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(is_equal(T(1), T(2)) == false, "Equal wrong.");
}
2015-08-04 13:34:38 +00:00
2017-05-18 14:29:41 +00:00
//test NotEqual
{
2015-08-04 13:34:38 +00:00
vtkm::NotEqual not_equal;
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(not_equal(vtkm::TypeTraits<T>::ZeroInitialization(), T(1)), "NotEqual wrong.");
2015-08-04 13:34:38 +00:00
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(not_equal(T(1), T(1)) == false, "NotEqual wrong.");
}
2015-08-04 13:34:38 +00:00
2017-05-18 14:29:41 +00:00
//test SortLess
{
2015-08-04 13:34:38 +00:00
vtkm::SortLess sort_less;
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(sort_less(T(1), T(2)) == true, "SortLess wrong.");
VTKM_TEST_ASSERT(sort_less(T(2), T(2)) == false, "SortLess wrong.");
VTKM_TEST_ASSERT(sort_less(T(2), T(1)) == false, "SortLess wrong.");
}
2015-08-04 13:34:38 +00:00
2017-05-18 14:29:41 +00:00
//test SortGreater
{
2015-08-04 13:34:38 +00:00
vtkm::SortGreater sort_greater;
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(sort_greater(T(1), T(2)) == false, "SortGreater wrong.");
VTKM_TEST_ASSERT(sort_greater(T(1), T(1)) == false, "SortGreater wrong.");
VTKM_TEST_ASSERT(sort_greater(T(3), T(2)) == true, "SortGreater wrong.");
}
}
;
2015-08-04 13:34:38 +00:00
struct BinaryPredicateTestFunctor
{
2017-05-18 14:29:41 +00:00
template <typename T>
void operator()(const T&) const
2015-08-04 13:34:38 +00:00
{
BinaryPredicateTest<T>();
}
};
void TestBinaryPredicates()
{
vtkm::testing::Testing::TryTypes(BinaryPredicateTestFunctor());
2015-08-04 13:34:38 +00:00
//test LogicalAnd
{
2017-05-18 14:29:41 +00:00
vtkm::LogicalAnd logical_and;
VTKM_TEST_ASSERT(logical_and(true, true) == true, "logical_and true wrong.");
VTKM_TEST_ASSERT(logical_and(true, false) == false, "logical_and true wrong.");
VTKM_TEST_ASSERT(logical_and(false, true) == false, "logical_and true wrong.");
VTKM_TEST_ASSERT(logical_and(false, false) == false, "logical_and true wrong.");
2015-08-04 13:34:38 +00:00
}
//test LogicalOr
{
2017-05-18 14:29:41 +00:00
vtkm::LogicalOr logical_or;
VTKM_TEST_ASSERT(logical_or(true, true) == true, "logical_or true wrong.");
VTKM_TEST_ASSERT(logical_or(true, false) == true, "logical_or true wrong.");
VTKM_TEST_ASSERT(logical_or(false, true) == true, "logical_or true wrong.");
VTKM_TEST_ASSERT(logical_or(false, false) == false, "logical_or true wrong.");
2015-08-04 13:34:38 +00:00
}
}
} // anonymous namespace
2017-05-18 14:29:41 +00:00
int UnitTestBinaryPredicates(int, char* [])
2015-08-04 13:34:38 +00:00
{
return vtkm::testing::Testing::Run(TestBinaryPredicates);
}