Skip to content

Commit

Permalink
use ASSERT_EQ in all std algorithms tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fnrizzi committed May 9, 2023
1 parent cfbaf28 commit 81ce338
Show file tree
Hide file tree
Showing 43 changed files with 467 additions and 467 deletions.
22 changes: 11 additions & 11 deletions algorithms/unit_tests/TestRandomAccessIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void test_random_access_it_verify(IteratorType it, ValueType gold_value) {
Kokkos::parallel_for("_std_algo_copy", 1, cf);
auto v_h =
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), checkView);
EXPECT_EQ(v_h(), gold_value);
ASSERT_EQ(v_h(), gold_value);
}

TEST_F(random_access_iterator_test, dereference) {
Expand Down Expand Up @@ -96,9 +96,9 @@ void test_random_access_it_subscript_op_verify(IteratorType it) {

auto v_h =
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), checkView);
EXPECT_EQ(v_h(0), (value_t)0);
EXPECT_EQ(v_h(1), (value_t)1);
EXPECT_EQ(v_h(2), (value_t)2);
ASSERT_EQ(v_h(0), (value_t)0);
ASSERT_EQ(v_h(1), (value_t)1);
ASSERT_EQ(v_h(2), (value_t)2);
}

TEST_F(random_access_iterator_test, subscript_operator) {
Expand Down Expand Up @@ -188,9 +188,9 @@ TEST_F(random_access_iterator_test, operatorsSet4) {
auto it7 = KE::Impl::RandomAccessIterator<static_view_t>(m_static_view, 3);
auto it8 = KE::Impl::RandomAccessIterator<dyn_view_t>(m_dynamic_view, 3);
auto it9 = KE::Impl::RandomAccessIterator<strided_view_t>(m_strided_view, 3);
EXPECT_EQ(it1, it7);
EXPECT_EQ(it2, it8);
EXPECT_EQ(it3, it9);
ASSERT_EQ(it1, it7);
ASSERT_EQ(it2, it8);
ASSERT_EQ(it3, it9);
EXPECT_GE(it1, it7);
EXPECT_GE(it2, it8);
EXPECT_GE(it3, it9);
Expand All @@ -205,16 +205,16 @@ TEST_F(random_access_iterator_test, assignment_operator) {
EXPECT_NE(it1, it2);

it2 = it1;
EXPECT_EQ(it1, it2);
ASSERT_EQ(it1, it2);
}

TEST_F(random_access_iterator_test, distance) {
auto first = KE::begin(m_dynamic_view);
auto last = KE::end(m_dynamic_view);

EXPECT_EQ(0, KE::distance(first, first));
EXPECT_EQ(1, KE::distance(first, first + 1));
EXPECT_EQ(m_dynamic_view.extent(0), size_t(KE::distance(first, last)));
ASSERT_EQ(0, KE::distance(first, first));
ASSERT_EQ(1, KE::distance(first, first + 1));
ASSERT_EQ(m_dynamic_view.extent(0), size_t(KE::distance(first, last)));
}

} // namespace stdalgos
Expand Down
10 changes: 5 additions & 5 deletions algorithms/unit_tests/TestStdAlgorithmsAdjacentDifference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void verify_data(TestViewType test_view, GoldViewType gold) {
const auto gold_h = create_mirror_view_and_copy(Kokkos::HostSpace(), gold);

for (std::size_t i = 0; i < test_view.extent(0); ++i) {
EXPECT_EQ(gold_h(i), test_view_dc_h(i));
ASSERT_EQ(gold_h(i), test_view_dc_h(i));
}
}

Expand Down Expand Up @@ -197,7 +197,7 @@ void run_single_scenario(const InfoType& scenario_info,
auto res1 = KE::adjacent_difference(exespace(), KE::cbegin(view_from),
KE::cend(view_from),
KE::begin(view_dest), args...);
EXPECT_EQ(res1, KE::end(view_dest));
ASSERT_EQ(res1, KE::end(view_dest));
verify_data(view_dest, gold);
}

Expand All @@ -207,7 +207,7 @@ void run_single_scenario(const InfoType& scenario_info,
auto res2 = KE::adjacent_difference(
"label", exespace(), KE::cbegin(view_from), KE::cend(view_from),
KE::begin(view_dest), args...);
EXPECT_EQ(res2, KE::end(view_dest));
ASSERT_EQ(res2, KE::end(view_dest));
verify_data(view_dest, gold);
}

Expand All @@ -216,7 +216,7 @@ void run_single_scenario(const InfoType& scenario_info,
create_view<ValueType>(Tag{}, view_ext, "adj_diff_dest_view");
auto res3 =
KE::adjacent_difference(exespace(), view_from, view_dest, args...);
EXPECT_EQ(res3, KE::end(view_dest));
ASSERT_EQ(res3, KE::end(view_dest));
verify_data(view_dest, gold);
}

Expand All @@ -225,7 +225,7 @@ void run_single_scenario(const InfoType& scenario_info,
create_view<ValueType>(Tag{}, view_ext, "adj_diff_dest_view");
auto res4 = KE::adjacent_difference("label", exespace(), view_from,
view_dest, args...);
EXPECT_EQ(res4, KE::end(view_dest));
ASSERT_EQ(res4, KE::end(view_dest));
verify_data(view_dest, gold);
}

Expand Down
2 changes: 1 addition & 1 deletion algorithms/unit_tests/TestStdAlgorithmsAdjacentFind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void verify(DiffType my_diff, ViewType view, Args... args) {
my_std_adjacent_find(KE::cbegin(view_h), KE::cend(view_h), args...);
const auto std_diff = std_r - KE::cbegin(view_h);

EXPECT_EQ(my_diff, std_diff);
ASSERT_EQ(my_diff, std_diff);
}

template <class Tag, class ValueType, class InfoType, class... Args>
Expand Down
8 changes: 4 additions & 4 deletions algorithms/unit_tests/TestStdAlgorithmsCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ verify_values(ValueType expected, const ViewType view) {
"Non-matching value types of view and reference value");
auto view_h = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), view);
for (std::size_t i = 0; i < view_h.extent(0); i++) {
EXPECT_EQ(expected, view_h(i));
ASSERT_EQ(expected, view_h(i));
}
}

Expand All @@ -130,7 +130,7 @@ verify_values(ValueType expected, const ViewType view) {
auto view_h =
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), tmpView);
for (std::size_t i = 0; i < view_h.extent(0); i++) {
EXPECT_EQ(expected, view_h(i));
ASSERT_EQ(expected, view_h(i));
}
}

Expand All @@ -147,7 +147,7 @@ compare_views(ViewType1 expected, const ViewType2 actual) {
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), actual);

for (std::size_t i = 0; i < expected_h.extent(0); i++) {
EXPECT_EQ(expected_h(i), actual_h(i));
ASSERT_EQ(expected_h(i), actual_h(i));
}
}

Expand All @@ -171,7 +171,7 @@ compare_views(ViewType1 expected, const ViewType2 actual) {
Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), expected);

for (std::size_t i = 0; i < expected_h.extent(0); i++) {
EXPECT_EQ(expected_h(i), actual_h(i));
ASSERT_EQ(expected_h(i), actual_h(i));
}
}

Expand Down
4 changes: 2 additions & 2 deletions algorithms/unit_tests/TestStdAlgorithmsConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ TEST(std_algorithms, is_admissible_to_std_algorithms) {
using strided_view_1d_t = Kokkos::View<value_type*, Kokkos::LayoutStride>;
Kokkos::LayoutStride layout1d{extent0, 2};
strided_view_1d_t strided_view_1d{"std-algo-test-1d-strided-view", layout1d};
EXPECT_EQ(layout1d.dimension[0], 13u);
EXPECT_EQ(layout1d.stride[0], 2u);
ASSERT_EQ(layout1d.dimension[0], 13u);
ASSERT_EQ(layout1d.stride[0], 2u);
// they are admissible
KE::Impl::static_assert_is_admissible_to_kokkos_std_algorithms(
static_view_1d);
Expand Down
68 changes: 34 additions & 34 deletions algorithms/unit_tests/TestStdAlgorithmsCopyIf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,49 +135,49 @@ void verify_data(const std::string& name, ViewTypeFrom view_from,
}

else if (name == "one-element-a") {
EXPECT_EQ(view_test_h(0), static_cast<value_type>(0));
ASSERT_EQ(view_test_h(0), static_cast<value_type>(0));
}

else if (name == "one-element-b") {
EXPECT_EQ(view_test_h(0), static_cast<value_type>(2));
ASSERT_EQ(view_test_h(0), static_cast<value_type>(2));
}

else if (name == "two-elements-a") {
EXPECT_EQ(view_test_h(0), static_cast<value_type>(2));
EXPECT_EQ(view_test_h(1), static_cast<value_type>(0));
ASSERT_EQ(view_test_h(0), static_cast<value_type>(2));
ASSERT_EQ(view_test_h(1), static_cast<value_type>(0));
}

else if (name == "two-elements-b") {
EXPECT_EQ(view_test_h(0), static_cast<value_type>(2));
EXPECT_EQ(view_test_h(1), static_cast<value_type>(0));
ASSERT_EQ(view_test_h(0), static_cast<value_type>(2));
ASSERT_EQ(view_test_h(1), static_cast<value_type>(0));
}

else if (name == "small-a") {
EXPECT_EQ(view_test_h(0), static_cast<value_type>(-4));
EXPECT_EQ(view_test_h(1), static_cast<value_type>(-2));
EXPECT_EQ(view_test_h(2), static_cast<value_type>(0));
EXPECT_EQ(view_test_h(3), static_cast<value_type>(2));
EXPECT_EQ(view_test_h(4), static_cast<value_type>(4));
EXPECT_EQ(view_test_h(5), static_cast<value_type>(0));
EXPECT_EQ(view_test_h(6), static_cast<value_type>(0));
EXPECT_EQ(view_test_h(7), static_cast<value_type>(0));
EXPECT_EQ(view_test_h(8), static_cast<value_type>(0));
ASSERT_EQ(view_test_h(0), static_cast<value_type>(-4));
ASSERT_EQ(view_test_h(1), static_cast<value_type>(-2));
ASSERT_EQ(view_test_h(2), static_cast<value_type>(0));
ASSERT_EQ(view_test_h(3), static_cast<value_type>(2));
ASSERT_EQ(view_test_h(4), static_cast<value_type>(4));
ASSERT_EQ(view_test_h(5), static_cast<value_type>(0));
ASSERT_EQ(view_test_h(6), static_cast<value_type>(0));
ASSERT_EQ(view_test_h(7), static_cast<value_type>(0));
ASSERT_EQ(view_test_h(8), static_cast<value_type>(0));
}

else if (name == "small-b") {
EXPECT_EQ(view_test_h(0), static_cast<value_type>(22));
EXPECT_EQ(view_test_h(1), static_cast<value_type>(-12));
EXPECT_EQ(view_test_h(2), static_cast<value_type>(22));
EXPECT_EQ(view_test_h(3), static_cast<value_type>(-12));
EXPECT_EQ(view_test_h(4), static_cast<value_type>(22));
EXPECT_EQ(view_test_h(5), static_cast<value_type>(-12));
EXPECT_EQ(view_test_h(6), static_cast<value_type>(22));
EXPECT_EQ(view_test_h(7), static_cast<value_type>(-12));
EXPECT_EQ(view_test_h(8), static_cast<value_type>(22));
EXPECT_EQ(view_test_h(9), static_cast<value_type>(-12));
EXPECT_EQ(view_test_h(10), static_cast<value_type>(22));
EXPECT_EQ(view_test_h(11), static_cast<value_type>(-12));
EXPECT_EQ(view_test_h(12), static_cast<value_type>(22));
ASSERT_EQ(view_test_h(0), static_cast<value_type>(22));
ASSERT_EQ(view_test_h(1), static_cast<value_type>(-12));
ASSERT_EQ(view_test_h(2), static_cast<value_type>(22));
ASSERT_EQ(view_test_h(3), static_cast<value_type>(-12));
ASSERT_EQ(view_test_h(4), static_cast<value_type>(22));
ASSERT_EQ(view_test_h(5), static_cast<value_type>(-12));
ASSERT_EQ(view_test_h(6), static_cast<value_type>(22));
ASSERT_EQ(view_test_h(7), static_cast<value_type>(-12));
ASSERT_EQ(view_test_h(8), static_cast<value_type>(22));
ASSERT_EQ(view_test_h(9), static_cast<value_type>(-12));
ASSERT_EQ(view_test_h(10), static_cast<value_type>(22));
ASSERT_EQ(view_test_h(11), static_cast<value_type>(-12));
ASSERT_EQ(view_test_h(12), static_cast<value_type>(22));
}

else if (name == "medium" || name == "large") {
Expand All @@ -190,14 +190,14 @@ void verify_data(const std::string& name, ViewTypeFrom view_from,
std::size_t count = 0;
for (std::size_t i = 0; i < view_from_h.extent(0); ++i) {
if (pred(view_from_h(i))) {
EXPECT_EQ(view_test_h(count), view_from_h(i));
ASSERT_EQ(view_test_h(count), view_from_h(i));
count++;
}
}
// all other entries of test view should be zero
for (; count < view_test_h.extent(0); ++count) {
// std::cout << count << '\n';
EXPECT_EQ(view_test_h(count), value_type(0));
ASSERT_EQ(view_test_h(count), value_type(0));
}
}

Expand Down Expand Up @@ -226,7 +226,7 @@ void run_single_scenario(const InfoType& scenario_info) {
auto rit = KE::copy_if(exespace(), KE::cbegin(view_from),
KE::cend(view_from), KE::begin(view_dest), pred);
verify_data(name, view_from, view_dest, pred);
EXPECT_EQ(rit, (KE::begin(view_dest) + n));
ASSERT_EQ(rit, (KE::begin(view_dest) + n));
}

{
Expand All @@ -235,23 +235,23 @@ void run_single_scenario(const InfoType& scenario_info) {
auto rit = KE::copy_if("label", exespace(), KE::cbegin(view_from),
KE::cend(view_from), KE::begin(view_dest), pred);
verify_data(name, view_from, view_dest, pred);
EXPECT_EQ(rit, (KE::begin(view_dest) + n));
ASSERT_EQ(rit, (KE::begin(view_dest) + n));
}

{
auto n = fill_view(view_from, name, pred);
auto view_dest = create_view<ValueType>(Tag{}, view_ext, "copy_if_dest");
auto rit = KE::copy_if(exespace(), view_from, view_dest, pred);
verify_data(name, view_from, view_dest, pred);
EXPECT_EQ(rit, (KE::begin(view_dest) + n));
ASSERT_EQ(rit, (KE::begin(view_dest) + n));
}

{
auto n = fill_view(view_from, name, pred);
auto view_dest = create_view<ValueType>(Tag{}, view_ext, "copy_if_dest");
auto rit = KE::copy_if("label", exespace(), view_from, view_dest, pred);
verify_data(name, view_from, view_dest, pred);
EXPECT_EQ(rit, (KE::begin(view_dest) + n));
ASSERT_EQ(rit, (KE::begin(view_dest) + n));
}

Kokkos::fence();
Expand Down
20 changes: 10 additions & 10 deletions algorithms/unit_tests/TestStdAlgorithmsCount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ void test_count(const ViewType view) {
const value_t count_value = 0;
const auto std_result =
std::count(KE::cbegin(expected), KE::cend(expected), count_value);
EXPECT_EQ(view.extent(0), size_t(std_result));
ASSERT_EQ(view.extent(0), size_t(std_result));

// pass const iterators
EXPECT_EQ(std_result, KE::count(exespace(), KE::cbegin(view),
ASSERT_EQ(std_result, KE::count(exespace(), KE::cbegin(view),
KE::cend(view), count_value));
// pass view
EXPECT_EQ(std_result, KE::count(exespace(), view, count_value));
ASSERT_EQ(std_result, KE::count(exespace(), view, count_value));
}

{
Expand All @@ -50,10 +50,10 @@ void test_count(const ViewType view) {
std::count(KE::cbegin(expected), KE::cend(expected), count_value);

// pass iterators
EXPECT_EQ(std_result, KE::count("label", exespace(), KE::begin(view),
ASSERT_EQ(std_result, KE::count("label", exespace(), KE::begin(view),
KE::end(view), count_value));
// pass view
EXPECT_EQ(std_result, KE::count("label", exespace(), view, count_value));
ASSERT_EQ(std_result, KE::count("label", exespace(), view, count_value));
}
}

Expand All @@ -67,24 +67,24 @@ void test_count_if(const ViewType view) {

// no positive elements (all zeroes)
const auto predicate = IsPositiveFunctor<value_type>();
EXPECT_EQ(0,
ASSERT_EQ(0,
std::count_if(KE::begin(expected), KE::end(expected), predicate));

// pass iterators
EXPECT_EQ(
ASSERT_EQ(
0, KE::count_if(exespace(), KE::begin(view), KE::end(view), predicate));
// pass view
EXPECT_EQ(0, KE::count_if(exespace(), view, predicate));
ASSERT_EQ(0, KE::count_if(exespace(), view, predicate));

fill_views_inc(view, expected);

const auto std_result =
std::count_if(KE::begin(expected), KE::end(expected), predicate);
// pass const iterators
EXPECT_EQ(std_result, KE::count_if("label", exespace(), KE::cbegin(view),
ASSERT_EQ(std_result, KE::count_if("label", exespace(), KE::cbegin(view),
KE::cend(view), predicate));
// pass view
EXPECT_EQ(std_result, KE::count_if("label", exespace(), view, predicate));
ASSERT_EQ(std_result, KE::count_if("label", exespace(), view, predicate));
}

template <class Tag, class ValueType>
Expand Down

0 comments on commit 81ce338

Please sign in to comment.