Skip to content

Commit

Permalink
Make minor adjustments in unit tests
Browse files Browse the repository at this point in the history
* Add missing headers
* Update copyright comments
* Make formatting and naming more consistent
  • Loading branch information
zhekemist committed Aug 18, 2024
1 parent 15b4be5 commit e0178e3
Show file tree
Hide file tree
Showing 62 changed files with 388 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// is smaller than the range of the searched elements.

#include <hpx/algorithm.hpp>
#include <hpx/execution.hpp>
#include <hpx/executors/execution_policy.hpp>
#include <hpx/init.hpp>
#include <hpx/modules/testing.hpp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// is empty.

#include <hpx/algorithm.hpp>
#include <hpx/executors/execution_policy.hpp>
#include <hpx/init.hpp>
#include <hpx/modules/testing.hpp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// proceed as usual and not just return the first iterators of both ranges.

#include <hpx/algorithm.hpp>
#include <hpx/executors/execution_policy.hpp>
#include <hpx/init.hpp>
#include <hpx/modules/testing.hpp>

Expand All @@ -27,8 +28,8 @@ void mismatch_differently_size_ranges_test()

auto expected = std::mismatch(a.begin(), a.end(), b.begin(), b.end());

//HPX_TEST((a.begin() + 2) == result.first);
//HPX_TEST((b.begin() + 2) == result.second);
HPX_TEST((a.begin() + 2) == result.first);
HPX_TEST((b.begin() + 2) == result.second);
HPX_TEST(result == expected);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// past-the-end iterator of the second range.

#include <hpx/algorithm.hpp>
#include <hpx/executors/execution_policy.hpp>
#include <hpx/init.hpp>
#include <hpx/modules/testing.hpp>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Copyright (c) 2015 Daniel Bourgeois
// Copyright (c) 2022 Hartmut Kaiser
// Copyright (c) 2024 Tobias Wukovitsch
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#pragma once

#include <hpx/config.hpp>
#include <hpx/algorithm.hpp>
#include <hpx/config.hpp>
#include <hpx/execution.hpp>
#include <hpx/modules/testing.hpp>
#include <hpx/numeric.hpp>
Expand Down Expand Up @@ -87,37 +88,46 @@ void test_adjacent_difference_sender(Policy l, ExPolicy&& policy)

auto exec = ex::explicit_scheduler_executor(scheduler_t(l));

auto result =
tt::sync_wait(ex::just(std::begin(c), std::end(c), std::begin(d)) |
hpx::adjacent_difference(policy.on(exec)));
{
auto snd_result =
tt::sync_wait(ex::just(std::begin(c), std::end(c), std::begin(d)) |
hpx::adjacent_difference(policy.on(exec)));
auto result = hpx::get<0>(*snd_result);

std::adjacent_difference(std::begin(c), std::end(c), std::begin(d_ans));
std::adjacent_difference(std::begin(c), std::end(c), std::begin(d_ans));

HPX_TEST(std::equal(std::begin(d), std::end(d), std::begin(d_ans),
[](auto lhs, auto rhs) { return lhs == rhs; }));
HPX_TEST(std::end(d) == hpx::get<0>(*result));
HPX_TEST(std::equal(std::begin(d), std::end(d), std::begin(d_ans),
[](auto lhs, auto rhs) { return lhs == rhs; }));
HPX_TEST(std::end(d) == result);
}

// 1st edge case: first == last
result =
tt::sync_wait(ex::just(std::begin(c), std::begin(c), std::begin(d)) |
hpx::adjacent_difference(policy.on(exec)));
{
// edge case: empty range
auto snd_result =
tt::sync_wait(ex::just(std::begin(c), std::begin(c), std::begin(d)) |
hpx::adjacent_difference(policy.on(exec)));
auto result = hpx::get<0>(*snd_result);

std::adjacent_difference(std::begin(c), std::begin(c), std::begin(d_ans));
std::adjacent_difference(std::begin(c), std::begin(c), std::begin(d_ans));

HPX_TEST(std::begin(d) == hpx::get<0>(*result));
HPX_TEST(std::equal(std::begin(d), std::end(d), std::begin(d_ans),
[](auto lhs, auto rhs) { return lhs == rhs; }));
HPX_TEST(std::begin(d) == result);
HPX_TEST(std::equal(std::begin(d), std::end(d), std::begin(d_ans),
[](auto lhs, auto rhs) { return lhs == rhs; }));
}

// 2nd edge case: first + 1 == last
result =
tt::sync_wait(ex::just(std::begin(c), ++std::begin(c), std::begin(d)) |
hpx::adjacent_difference(policy.on(exec)));
{
// edge case: range of size one
auto snd_result =
tt::sync_wait(ex::just(std::begin(c), ++std::begin(c), std::begin(d)) |
hpx::adjacent_difference(policy.on(exec)));
auto result = hpx::get<0>(*snd_result);

std::adjacent_difference(std::begin(c), ++std::begin(c), std::begin(d_ans));
std::adjacent_difference(std::begin(c), ++std::begin(c), std::begin(d_ans));

HPX_TEST(std::equal(std::begin(d), std::end(d), std::begin(d_ans),
[](auto lhs, auto rhs) { return lhs == rhs; }));
HPX_TEST(++std::begin(d) == hpx::get<0>(*result));
HPX_TEST(std::equal(std::begin(d), std::end(d), std::begin(d_ans),
[](auto lhs, auto rhs) { return lhs == rhs; }));
HPX_TEST(++std::begin(d) == result);
}
}
#endif

Expand Down
30 changes: 19 additions & 11 deletions libs/core/algorithms/tests/unit/algorithms/adjacentfind_tests.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2014 Grant Mercer
// Copyright (c) 2024 Tobias Wukovitsch
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -8,6 +9,7 @@

#include <hpx/config.hpp>
#include <hpx/algorithm.hpp>
#include <hpx/execution.hpp>
#include <hpx/init.hpp>
#include <hpx/modules/testing.hpp>

Expand Down Expand Up @@ -79,21 +81,27 @@ void test_adjacent_find_sender(

auto exec = ex::explicit_scheduler_executor(scheduler_t(ln_policy));

auto snd_result =
tt::sync_wait(ex::just(iterator(std::begin(c)), iterator(std::end(c))) |
hpx::adjacent_find(ex_policy.on(exec)));
{
auto snd_result =
tt::sync_wait(ex::just(iterator(std::begin(c)), iterator(std::end(c))) |
hpx::adjacent_find(ex_policy.on(exec)));

iterator index = hpx::get<0>(*snd_result);
base_iterator test_index = std::begin(c) + random_pos;
iterator index = hpx::get<0>(*snd_result);
base_iterator test_index = std::begin(c) + random_pos;

HPX_TEST(index == iterator(test_index));
HPX_TEST(index == iterator(test_index));
}

// edge case: first == last
snd_result = tt::sync_wait(
ex::just(iterator(std::begin(c)), iterator(std::begin(c))) |
hpx::adjacent_find(ex_policy.on(exec)));
{
// edge case: empty range

auto snd_result = tt::sync_wait(
ex::just(iterator(std::begin(c)), iterator(std::begin(c))) |
hpx::adjacent_find(ex_policy.on(exec)));
auto result = hpx::get<0>(*snd_result);

HPX_TEST(iterator(std::begin(c)) == hpx::get<0>(*snd_result));
HPX_TEST(iterator(std::begin(c)) == result);
}
}
#endif

Expand Down
7 changes: 4 additions & 3 deletions libs/core/algorithms/tests/unit/algorithms/all_of_tests.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2014-2020 Hartmut Kaiser
// Copyright (c) 2024 Tobias Wukovitsch
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -7,6 +8,7 @@
#pragma once

#include <hpx/config.hpp>
#include <hpx/execution.hpp>
#include <hpx/modules/testing.hpp>
#include <hpx/parallel/algorithms/all_any_none.hpp>
#include <hpx/parallel/container_algorithms/all_any_none.hpp>
Expand Down Expand Up @@ -82,18 +84,17 @@ void test_all_of_sender(LnPolicy ln_policy, ExPolicy&& ex_policy, IteratorTag)
namespace tt = hpx::this_thread::experimental;
using scheduler_t = ex::thread_pool_policy_scheduler<LnPolicy>;

auto exec = ex::explicit_scheduler_executor(scheduler_t(ln_policy));

int iseq[] = {0, 23, 10007};
for (int i : iseq)
{
std::vector<int> c = test::fill_all_any_none<int>(10007, i); //-V106

auto exec = ex::explicit_scheduler_executor(scheduler_t(ln_policy));

auto snd_result = tt::sync_wait(
ex::just(iterator(std::begin(c)), iterator(std::end(c)),
[](auto v) { return v != 0; }) |
hpx::all_of(ex_policy.on(exec)));

bool result = hpx::get<0>(*snd_result);

// verify values
Expand Down
9 changes: 5 additions & 4 deletions libs/core/algorithms/tests/unit/algorithms/any_of_tests.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Copyright (c) 2014-2020 Hartmut Kaiser
// Copyright (c) 2024 Tobias Wukovitsch
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#pragma once

#include <hpx/config.hpp>
#include <hpx/algorithm.hpp>
#include <hpx/config.hpp>
#include <hpx/execution.hpp>
#include <hpx/init.hpp>
#include <hpx/modules/testing.hpp>
#include <hpx/type_support/identity.hpp>
Expand Down Expand Up @@ -83,18 +85,17 @@ void test_any_of_sender(LnPolicy ln_policy, ExPolicy&& ex_policy, IteratorTag)

using scheduler_t = ex::thread_pool_policy_scheduler<LnPolicy>;

auto exec = ex::explicit_scheduler_executor(scheduler_t(ln_policy));

int iseq[] = {0, 23, 10007};
for (int i : iseq)
{
std::vector<int> c = test::fill_all_any_none<int>(10007, i); //-V106

auto exec = ex::explicit_scheduler_executor(scheduler_t(ln_policy));

auto snd_result = tt::sync_wait(
ex::just(iterator(std::begin(c)), iterator(std::end(c)),
[](auto v) { return v != 0; }) |
hpx::any_of(ex_policy.on(exec)));

bool result = hpx::get<0>(*snd_result);

// verify values
Expand Down
2 changes: 2 additions & 0 deletions libs/core/algorithms/tests/unit/algorithms/copy_tests.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2021 Srinivas Yadav
// Copyright (c) 2014 Grant Mercer
// Copyright (c) 2024 Tobias Wukovitsch
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -8,6 +9,7 @@
#pragma once

#include <hpx/config.hpp>
#include <hpx/execution.hpp>
#include <hpx/modules/testing.hpp>
#include <hpx/parallel/algorithms/copy.hpp>

Expand Down
1 change: 1 addition & 0 deletions libs/core/algorithms/tests/unit/algorithms/copyn_tests.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2021 Srinivas Yadav
// Copyright (c) 2014 Grant Mercer
// Copyright (c) 2024 Tobias Wukovitsch
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down
2 changes: 2 additions & 0 deletions libs/core/algorithms/tests/unit/algorithms/count_tests.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2014-2016 Hartmut Kaiser
// Copyright (c) 2024 Tobias Wukovitsch
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -7,6 +8,7 @@
#pragma once

#include <hpx/config.hpp>
#include <hpx/execution.hpp>
#include <hpx/modules/testing.hpp>
#include <hpx/parallel/algorithms/count.hpp>

Expand Down
2 changes: 2 additions & 0 deletions libs/core/algorithms/tests/unit/algorithms/countif_tests.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2014-2016 Hartmut Kaiser
// Copyright (c) 2024 Tobias Wukovitsch
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -7,6 +8,7 @@
#pragma once

#include <hpx/config.hpp>
#include <hpx/execution.hpp>
#include <hpx/modules/testing.hpp>
#include <hpx/parallel/algorithms/count.hpp>

Expand Down
4 changes: 3 additions & 1 deletion libs/core/algorithms/tests/unit/algorithms/destroy_tests.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Copyright (c) 2014-2020 Hartmut Kaiser
// Copyright (c) 2024 Tobias Wukovitsch
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#pragma once

#include <hpx/config.hpp>

#include <hpx/algorithm.hpp>
#include <hpx/config.hpp>
#include <hpx/execution.hpp>
#include <hpx/memory.hpp>
#include <hpx/modules/testing.hpp>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Copyright (c) 2014-2020 Hartmut Kaiser
// Copyright (c) 2024 Tobias Wukovitsch
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <hpx/algorithm.hpp>
#include <hpx/execution.hpp>
#include <hpx/init.hpp>
#include <hpx/memory.hpp>
#include <hpx/modules/testing.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <hpx/algorithm.hpp>
#include <hpx/execution.hpp>
#include <hpx/init.hpp>
#include <hpx/modules/testing.hpp>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2014-2020 Hartmut Kaiser
// Copyright (c) 2024 Tobias Wukovitsch
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2014-2020 Hartmut Kaiser
// Copyright (c) 2024 Tobias Wukovitsch
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -7,6 +8,7 @@
#pragma once

#include <hpx/config.hpp>
#include <hpx/execution.hpp>
#include <hpx/modules/testing.hpp>
#include <hpx/parallel/algorithms/equal.hpp>

Expand Down
2 changes: 2 additions & 0 deletions libs/core/algorithms/tests/unit/algorithms/equal_tests.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) 2014-2020 Hartmut Kaiser
// Copyright (c) 2024 Tobias Wukovitsch
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -7,6 +8,7 @@
#pragma once

#include <hpx/config.hpp>
#include <hpx/execution.hpp>
#include <hpx/modules/testing.hpp>
#include <hpx/parallel/algorithms/equal.hpp>

Expand Down
2 changes: 2 additions & 0 deletions libs/core/algorithms/tests/unit/algorithms/fill_tests.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2014 Grant Mercer
// Copyright (c) 2017-2020 Hartmut Kaiser
// Copyright (c) 2021 Srinivas Yadav
// Copyright (c) 2024 Tobias Wukovitsch
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -9,6 +10,7 @@
#pragma once

#include <hpx/config.hpp>
#include <hpx/execution.hpp>
#include <hpx/modules/testing.hpp>
#include <hpx/parallel/algorithms/fill.hpp>

Expand Down
Loading

0 comments on commit e0178e3

Please sign in to comment.