Commit af0460ba authored by Nickolas Davis's avatar Nickolas Davis 🥑 Committed by Kitware Robot

Merge topic 'min-and-max-operator-tests'

45c92a05 added missing MinAndMax BinaryOperator tests, updated formatting
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Kenneth Moreland's avatarKenneth Moreland <kmorel@sandia.gov>
Merge-request: !1662
parents 75bf9d36 45c92a05
......@@ -17,54 +17,111 @@ namespace
//general pair test
template <typename T>
void BinaryOperatorTest(){
void BinaryOperatorTest()
{
//Not using TestValue method as it causes roll-over to occur with
//uint8 and int8 leading to unexpected comparisons.
//test Sum
{ vtkm::Sum sum;
T result;
{
vtkm::Sum sum;
T result;
result = sum(vtkm::TypeTraits<T>::ZeroInitialization(), T(1));
VTKM_TEST_ASSERT(result == T(1), "Sum wrong.");
result = sum(vtkm::TypeTraits<T>::ZeroInitialization(), T(1));
VTKM_TEST_ASSERT(result == T(1), "Sum wrong.");
result = sum(T(1), T(1));
VTKM_TEST_ASSERT(result == T(2), "Sum wrong.");
}
result = sum(T(1), T(1));
VTKM_TEST_ASSERT(result == T(2), "Sum wrong.");
}
//test Product
{
vtkm::Product product;
T result;
//test Product
{
vtkm::Product product;
T result;
result = product(vtkm::TypeTraits<T>::ZeroInitialization(), T(1));
VTKM_TEST_ASSERT(result == vtkm::TypeTraits<T>::ZeroInitialization(), "Product wrong.");
result = product(vtkm::TypeTraits<T>::ZeroInitialization(), T(1));
VTKM_TEST_ASSERT(result == vtkm::TypeTraits<T>::ZeroInitialization(), "Product wrong.");
result = product(T(1), T(1));
VTKM_TEST_ASSERT(result == T(1), "Product wrong.");
result = product(T(1), T(1));
VTKM_TEST_ASSERT(result == T(1), "Product wrong.");
result = product(T(2), T(3));
VTKM_TEST_ASSERT(result == T(6), "Product wrong.");
}
result = product(T(2), T(3));
VTKM_TEST_ASSERT(result == T(6), "Product wrong.");
}
//test Maximum
{
vtkm::Maximum maximum;
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.");
}
//test Maximum
{
vtkm::Maximum maximum;
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.");
}
//test Minimum
{
vtkm::Minimum minimum;
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.");
}
//test Minimum
{
vtkm::Minimum minimum;
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.");
}
//test MinAndMax
{
vtkm::MinAndMax<T> min_and_max;
vtkm::Vec<T, 2> result;
// Test1: basic param
{
result = min_and_max(T(1));
VTKM_TEST_ASSERT(test_equal(result, vtkm::Vec<T, 2>(T(1), T(1))), "Test1 MinAndMax wrong");
}
// Test2: basic param
{
result = min_and_max(vtkm::TypeTraits<T>::ZeroInitialization(), T(1));
VTKM_TEST_ASSERT(
test_equal(result, vtkm::Vec<T, 2>(vtkm::TypeTraits<T>::ZeroInitialization(), T(1))),
"Test2 MinAndMax wrong");
result = min_and_max(T(2), T(1));
VTKM_TEST_ASSERT(test_equal(result, vtkm::Vec<T, 2>(T(1), T(2))), "Test2 MinAndMax wrong");
}
// Test3: 1st param vector, 2nd param basic
{
result = min_and_max(vtkm::Vec<T, 2>(3, 5), T(7));
VTKM_TEST_ASSERT(test_equal(result, vtkm::Vec<T, 2>(T(3), T(7))), "Test3 MinAndMax Wrong");
result = min_and_max(vtkm::Vec<T, 2>(3, 5), T(2));
VTKM_TEST_ASSERT(test_equal(result, vtkm::Vec<T, 2>(T(2), T(5))), "Test3 MinAndMax Wrong");
}
// Test4: 1st param basic, 2nd param vector
{
result = min_and_max(T(7), vtkm::Vec<T, 2>(3, 5));
VTKM_TEST_ASSERT(test_equal(result, vtkm::Vec<T, 2>(T(3), T(7))), "Test4 MinAndMax Wrong");
result = min_and_max(T(2), vtkm::Vec<T, 2>(3, 5));
VTKM_TEST_ASSERT(test_equal(result, vtkm::Vec<T, 2>(T(2), T(5))), "Test4 MinAndMax Wrong");
}
// Test5: 2 vector param
{
result = min_and_max(vtkm::Vec<T, 2>(2, 4), vtkm::Vec<T, 2>(3, 5));
VTKM_TEST_ASSERT(test_equal(result, vtkm::Vec<T, 2>(T(2), T(5))), "Test5 MinAndMax Wrong");
result = min_and_max(vtkm::Vec<T, 2>(2, 7), vtkm::Vec<T, 2>(3, 5));
VTKM_TEST_ASSERT(test_equal(result, vtkm::Vec<T, 2>(T(2), T(7))), "Test5 MinAndMax Wrong");
result = min_and_max(vtkm::Vec<T, 2>(4, 4), vtkm::Vec<T, 2>(1, 8));
VTKM_TEST_ASSERT(test_equal(result, vtkm::Vec<T, 2>(T(1), T(8))), "Test5 MinAndMax Wrong");
result = min_and_max(vtkm::Vec<T, 2>(4, 4), vtkm::Vec<T, 2>(3, 3));
VTKM_TEST_ASSERT(test_equal(result, vtkm::Vec<T, 2>(T(3), T(4))), "Test5 MinAndMax Wrong");
}
}
}
;
struct BinaryOperatorTestFunctor
{
......
......@@ -17,45 +17,43 @@ namespace
//general pair test
template <typename T>
void BinaryPredicateTest(){
void BinaryPredicateTest()
{
//Not using TestValue method as it causes roll-over to occur with
//uint8 and int8 leading to unexpected comparisons.
//test Equal
{ vtkm::Equal is_equal;
VTKM_TEST_ASSERT(is_equal(vtkm::TypeTraits<T>::ZeroInitialization(),
vtkm::TypeTraits<T>::ZeroInitialization()),
"Equal wrong.");
VTKM_TEST_ASSERT(is_equal(T(1), T(2)) == false, "Equal wrong.");
}
//test NotEqual
{
vtkm::NotEqual not_equal;
VTKM_TEST_ASSERT(not_equal(vtkm::TypeTraits<T>::ZeroInitialization(), T(1)), "NotEqual wrong.");
{
vtkm::Equal is_equal;
VTKM_TEST_ASSERT(is_equal(vtkm::TypeTraits<T>::ZeroInitialization(),
vtkm::TypeTraits<T>::ZeroInitialization()),
"Equal wrong.");
VTKM_TEST_ASSERT(is_equal(T(1), T(2)) == false, "Equal wrong.");
}
VTKM_TEST_ASSERT(not_equal(T(1), T(1)) == false, "NotEqual wrong.");
}
//test NotEqual
{
vtkm::NotEqual not_equal;
VTKM_TEST_ASSERT(not_equal(vtkm::TypeTraits<T>::ZeroInitialization(), T(1)), "NotEqual wrong.");
VTKM_TEST_ASSERT(not_equal(T(1), T(1)) == false, "NotEqual wrong.");
}
//test SortLess
{
vtkm::SortLess sort_less;
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.");
}
//test SortLess
{
vtkm::SortLess sort_less;
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.");
}
//test SortGreater
{
vtkm::SortGreater sort_greater;
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.");
}
//test SortGreater
{
vtkm::SortGreater sort_greater;
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.");
}
}
;
struct BinaryPredicateTestFunctor
{
......
......@@ -16,22 +16,24 @@ namespace
{
template <typename T>
void UnaryPredicateTest(){ //test IsZeroInitialized
{ vtkm::IsZeroInitialized is_default;
VTKM_TEST_ASSERT(is_default(vtkm::TypeTraits<T>::ZeroInitialization()) == true,
"IsZeroInitialized wrong.");
VTKM_TEST_ASSERT(is_default(TestValue(1, T())) == false, "IsZeroInitialized wrong.");
}
//test NotZeroInitialized
void UnaryPredicateTest()
{
vtkm::NotZeroInitialized not_default;
VTKM_TEST_ASSERT(not_default(vtkm::TypeTraits<T>::ZeroInitialization()) == false,
"NotZeroInitialized wrong.");
VTKM_TEST_ASSERT(not_default(TestValue(1, T())) == true, "NotZeroInitialized wrong.");
}
//test IsZeroInitialized
{
vtkm::IsZeroInitialized is_default;
VTKM_TEST_ASSERT(is_default(vtkm::TypeTraits<T>::ZeroInitialization()) == true,
"IsZeroInitialized wrong.");
VTKM_TEST_ASSERT(is_default(TestValue(1, T())) == false, "IsZeroInitialized wrong.");
}
//test NotZeroInitialized
{
vtkm::NotZeroInitialized not_default;
VTKM_TEST_ASSERT(not_default(vtkm::TypeTraits<T>::ZeroInitialization()) == false,
"NotZeroInitialized wrong.");
VTKM_TEST_ASSERT(not_default(TestValue(1, T())) == true, "NotZeroInitialized wrong.");
}
}
;
struct UnaryPredicateTestFunctor
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment