Commit ce936ae6 by FritzFlorian

Add test for for_each and for_each_range.

parent 7581ccfa
......@@ -14,7 +14,7 @@ class matrix {
}
void multiply(const matrix<T, SIZE> &a, const matrix<T, SIZE> &b) {
pls::algorithm::for_each_range(0, SIZE, [&](int i) {
pls::for_each_range(0, SIZE, [&](int i) {
this->multiply_column(i, a, b);
});
}
......
......@@ -24,6 +24,7 @@ using internal::scheduling::task;
using algorithm::invoke;
using algorithm::for_each;
using algorithm::for_each_range;
using algorithm::scan;
}
......
add_executable(tests
main.cpp
data_structures_test.cpp
scheduling_tests.cpp)
scheduling_tests.cpp
algorithm_test.cpp)
target_link_libraries(tests catch2 pls)
#include <catch.hpp>
#include <array>
#include <pls/pls.h>
using namespace pls;
TEST_CASE("for_each functions correctly", "[algorithms/for_each.h]") {
malloc_scheduler_memory my_scheduler_memory{8, 2 << 12};
scheduler my_scheduler{&my_scheduler_memory, 2};
my_scheduler.perform_work([]() {
constexpr int SIZE = 1000;
std::array<int, SIZE> result_array{};
result_array.fill(0);
SECTION("integer ranges are processed exactly once") {
pls::for_each_range(0, SIZE, [&result_array](int i) {
result_array[i]++;
});
bool all_equal = true;
for (int i = 0; i < SIZE; i++) {
all_equal &= result_array[i] == 1;
}
REQUIRE (all_equal);
}
SECTION("iterators are processed exactly once") {
std::array<int, SIZE> iterator_array{};
for (int i = 0; i < SIZE; i++) {
iterator_array[i] = i;
}
pls::for_each(iterator_array.begin(), iterator_array.end(), [&result_array](int i) {
result_array[i]++;
});
bool all_equal = true;
for (int i = 0; i < SIZE; i++) {
all_equal &= result_array[i] == 1;
}
REQUIRE (all_equal);
}
});
}
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 sign in to comment