From a25fd7affedb36772c4648761586dbfd97fb0656 Mon Sep 17 00:00:00 2001 From: Sylvain Joube Date: Sun, 2 Jun 2024 16:45:21 +0200 Subject: [PATCH] Tests 2, 4D: binary_search --- test/algorithm/algos/binary_search/2d.cpp | 479 ++++++++++ test/algorithm/algos/binary_search/4d.cpp | 1022 +++++++++------------ 2 files changed, 913 insertions(+), 588 deletions(-) create mode 100644 test/algorithm/algos/binary_search/2d.cpp diff --git a/test/algorithm/algos/binary_search/2d.cpp b/test/algorithm/algos/binary_search/2d.cpp new file mode 100644 index 00000000..5dbce904 --- /dev/null +++ b/test/algorithm/algos/binary_search/2d.cpp @@ -0,0 +1,479 @@ +//================================================================================================== +/* + KIWAKU - Containers Well Made + Copyright : KIWAKU Contributors & Maintainers + SPDX-License-Identifier: BSL-1.0 +*/ +//================================================================================================== +#include +#include +#include +#include "test.hpp" +#include +#include + +// binary_search + +// Only tests 2D tables/views +// TODO: at some point, make algorithms work for nD + +TTS_CASE("Check for kwk::lower_bound(In, value) 2D") +{ + const std::size_t d0 = 8; + const std::size_t d1 = 12; + const std::size_t input_size = d0 * d1; + std::array input; + for (std::size_t i = 0; i < input_size; ++i) { input[i] = i; } + auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1)}; + + // Valid values + { + int search = -2984612; + std::array expected{0, 0}; + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), expected); + auto std_res = std::lower_bound(input.begin(), input.end(), search); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), std_pos); + } + { + int search = 0; + std::array expected{0, 0}; + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), expected); + auto std_res = std::lower_bound(input.begin(), input.end(), search); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), std_pos); + } + { + int search = -1; + std::array expected{0, 0}; + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), expected); + auto std_res = std::lower_bound(input.begin(), input.end(), search); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), std_pos); + } + { + int search = 10; + std::array expected = lindex_to_pos_arr(d1, 10); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), expected); + auto std_res = std::lower_bound(input.begin(), input.end(), search); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), std_pos); + } + { + int search = input_size-1; + // {d0-1, d1-1} = lindex_to_pos_arr(d1, input_size-1); + std::array expected{d0-1, d1-1}; + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), expected); + auto std_res = std::lower_bound(input.begin(), input.end(), search); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), std_pos); + } + // Invalid values + { + int search = input_size; + TTS_EQUAL(kwk::lower_bound(view, search), std::nullopt); + TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search), input.end()); + } + { + int search = input_size + 784565; + TTS_EQUAL(kwk::lower_bound(view, search), std::nullopt); + TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search), input.end()); + } +}; + +TTS_CASE("Check for kwk::lower_bound(In, value, func) 2D with function") +{ + const std::size_t d0 = 8; + const std::size_t d1 = 12; + const std::size_t input_size = d0 * d1; + std::array input; + for (std::size_t i = 0; i < input_size; ++i) { input[i] = (i - 10) * 2; } + auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1)}; + auto func = [](auto const& input_, auto const& element_) { return input_ < (element_ - 10) * 2; }; + + // Valid values + { + /*Compare values*/ + int search = -2984612; + std::array expected{0, 0}; + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), expected); + /*Compare with std implementation: compare found indexes*/ + auto std_res = std::lower_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), std_pos); + } + { + /*Compare values*/ + int search = -1; + std::array expected{0, 0}; + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), expected); + /*Compare with std implementation: compare found indexes*/ + auto std_res = std::lower_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), std_pos); + } + { + /*Compare values*/ + int search = 0; + std::array expected{0, 0}; + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), expected); + /*Compare with std implementation: compare found indexes*/ + auto std_res = std::lower_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), std_pos); + } + { + /*Compare values*/ + int search = 9; + std::array expected = lindex_to_pos_arr(d1, 9); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), expected); + /*Compare with std implementation: compare found indexes*/ + auto std_res = std::lower_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), std_pos); + } + { + /*Compare values*/ + int search = input_size-1; + std::array expected{d0-1, d1-1}; + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), expected); + /*Compare with std implementation: compare found indexes*/ + auto std_res = std::lower_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), std_pos); + } + + // Erroneous values + { + int search = input_size; + TTS_EQUAL(kwk::lower_bound(view, search, func), std::nullopt); + TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search, func), input.end()); + } + { + int search = input_size + 784565; + TTS_EQUAL(kwk::lower_bound(view, search, func), std::nullopt); + TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search, func), input.end()); + } +}; + + +TTS_CASE("Check for kwk::upper_bound(In, value) 2D") +{ + const std::size_t d0 = 8; + const std::size_t d1 = 12; + const std::size_t input_size = d0 * d1; + std::array input; + for (std::size_t i = 0; i < input_size; ++i) { input[i] = i; } + auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1)}; + + // upper_bound returns the index of the first element above the specified value + { + int search = -78495; + std::array expected{0, 0}; + /*Compare values*/ + TTS_ALL_EQUAL(*kwk::upper_bound(view, search), expected); + /*Compare with std implementation*/ + auto std_res = std::upper_bound(input.begin(), input.end(), search); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::upper_bound(view, search), std_pos); + } + { + int search = -1; + std::array expected{0, 0}; + /*Compare values*/ + TTS_ALL_EQUAL(*kwk::upper_bound(view, search), expected); + /*Compare with std implementation*/ + auto std_res = std::upper_bound(input.begin(), input.end(), search); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::upper_bound(view, search), std_pos); + } + { + int search = 0; + std::array expected{0, 1}; + /*Compare values*/ + TTS_ALL_EQUAL(*kwk::upper_bound(view, search), expected); + /*Compare with std implementation*/ + auto std_res = std::upper_bound(input.begin(), input.end(), search); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::upper_bound(view, search), std_pos); + } + { + int search = input_size-2; + std::array expected{d0-1, d1-1}; + /*Compare values*/ + TTS_ALL_EQUAL(*kwk::upper_bound(view, search), expected); + /*Compare with std implementation*/ + auto std_res = std::upper_bound(input.begin(), input.end(), search); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::upper_bound(view, search), std_pos); + } + + // Erroneous values + { + int search = input_size-1; + TTS_EQUAL(kwk::upper_bound(view, search), std::nullopt); + TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search), input.end()); + } + { + int search = input_size; + TTS_EQUAL(kwk::upper_bound(view, search), std::nullopt); + TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search), input.end()); + } + { + int search = input_size + 784565; + TTS_EQUAL(kwk::upper_bound(view, search), std::nullopt); + TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search), input.end()); + } +}; + + +TTS_CASE("Check for kwk::upper_bound(In, value) 2D with function") +{ + const std::size_t d0 = 8; + const std::size_t d1 = 12; + const std::size_t input_size = d0 * d1; + std::array input; + for (std::size_t i = 0; i < input_size; ++i) { input[i] = i * 3 - 20; } + auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1)}; + auto func = [](auto const& search_, auto const& element_) { return search_ * 3 - 20 < element_; }; + + // upper_bound returns the index of the first element above the specified value + { + int search = -78495; + std::array expected{0, 0}; + /*Compare values*/ + TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), expected); + /*Compare with std implementation*/ + auto std_res = std::upper_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), std_pos); + } + { + int search = -1; + std::array expected{0, 0}; + /*Compare values*/ + TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), expected); + /*Compare with std implementation*/ + auto std_res = std::upper_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), std_pos); + } + { + int search = 0; + std::array expected{0, 1}; + /*Compare values*/ + TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), expected); + /*Compare with std implementation*/ + auto std_res = std::upper_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), std_pos); + } + { + int search = input_size-2; + std::array expected{d0-1, d1-1}; + /*Compare values*/ + TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), expected); + /*Compare with std implementation*/ + auto std_res = std::upper_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1); + TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), std_pos); + } + + // Erroneous values + { + int search = input_size-1; + TTS_EQUAL(kwk::upper_bound(view, search, func), std::nullopt); + TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search, func), input.end()); + } + { + int search = input_size; + TTS_EQUAL(kwk::upper_bound(view, search, func), std::nullopt); + TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search, func), input.end()); + } + { + int search = input_size + 784565; + TTS_EQUAL(kwk::upper_bound(view, search, func), std::nullopt); + TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search, func), input.end()); + } +}; + + +TTS_CASE("Check for kwk::binary_search(In, value) 2D") +{ + const std::size_t d0 = 8; + const std::size_t d1 = 12; + const std::size_t input_size = d0 * d1; + std::array input; + for (std::size_t i = 0; i < input_size; ++i) { input[i] = i * 3; } + auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1)}; + + // Ensures that the return value is expected + { + bool expected = false; + int search = -895; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = false; + int search = -1; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = true; + int search = 0; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = false; + int search = 18 * 3 - 1; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = true; + int search = 18 * 3; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = false; + int search = 18 * 3 + 1; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = false; + int search = 18 * 3 + 2; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = true; + int search = (input_size-1) * 3; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = false; + int search = (input_size) * 3; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = false; + int search = (input_size + 2000) * 3; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = false; + int search = (input_size + 2000) * 3 + 1; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } +}; + +TTS_CASE("Check for kwk::binary_search(In, value) 2D with function") +{ + const std::size_t d0 = 8; + const std::size_t d1 = 12; + const std::size_t input_size = d0 * d1; + std::array input; + for (std::size_t i = 0; i < input_size; ++i) { input[i] = i * 3; } // * 3 - 20 + auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1)}; + + auto func = [](auto const& search_, auto const& element_) { return search_ < element_; }; + + // Ensures that the return value is expected + { + bool expected = false; + int search = -895; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = false; + int search = -1; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = true; + int search = 0; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = false; + int search = 18 * 3 - 1; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = true; + int search = 18 * 3; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = false; + int search = 18 * 3 + 1; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = false; + int search = 18 * 3 + 2; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = true; + int search = (input_size-1) * 3; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = false; + int search = (input_size) * 3; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = false; + int search = (input_size + 2000) * 3; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = false; + int search = (input_size + 2000) * 3 + 1; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } +}; diff --git a/test/algorithm/algos/binary_search/4d.cpp b/test/algorithm/algos/binary_search/4d.cpp index 3a290b4d..48739657 100644 --- a/test/algorithm/algos/binary_search/4d.cpp +++ b/test/algorithm/algos/binary_search/4d.cpp @@ -29,617 +29,463 @@ TTS_CASE("Check for kwk::lower_bound(In, value) 4D") auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1, d2, d3)}; // Valid values - // { - // int search = -2984612; - // std::array expected{0, 0, 0, 0}; - // TTS_ALL_EQUAL(*kwk::lower_bound(view, search), expected); - // TTS_EQUAL ((*kwk::lower_bound(view, search))[0] - // , std::distance(std::lower_bound(input.begin(), input.end(), search), input.begin()) - // ); - // } - // { - // int search = 0; - // std::array expected{0, 0, 0, 0}; - // TTS_ALL_EQUAL(*kwk::lower_bound(view, search), expected); - // TTS_EQUAL ((*kwk::lower_bound(view, search))[0] - // , std::distance(std::lower_bound(input.begin(), input.end(), search), input.begin()) - // ); - // } - // { - // int search = -1; - // std::array expected{0, 0, 0, 0}; - // TTS_ALL_EQUAL(*kwk::lower_bound(view, search), expected); - // TTS_EQUAL ((*kwk::lower_bound(view, search))[0] - // , std::distance(std::lower_bound(input.begin(), input.end(), search), input.begin()) - // ); - // } - // { - // int search = 10; - // std::array expected = lindex_to_pos_arr(d1, d2, d3, 10); - // TTS_ALL_EQUAL(*kwk::lower_bound(view, search), expected); - // TTS_EQUAL ((*kwk::lower_bound(view, search))[0] - // , std::distance(input.begin(), std::lower_bound(input.begin(), input.end(), search)) - // ); - // } + { + int search = -2984612; + std::array expected{0, 0, 0, 0}; + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), expected); + auto std_res = std::lower_bound(input.begin(), input.end(), search); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), std_pos); + } + { + int search = 0; + std::array expected{0, 0, 0, 0}; + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), expected); + auto std_res = std::lower_bound(input.begin(), input.end(), search); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), std_pos); + } + { + int search = -1; + std::array expected{0, 0, 0, 0}; + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), expected); + auto std_res = std::lower_bound(input.begin(), input.end(), search); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), std_pos); + } + { + int search = 10; + std::array expected = lindex_to_pos_arr(d1, d2, d3, 10); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), expected); + auto std_res = std::lower_bound(input.begin(), input.end(), search); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search), std_pos); + } { int search = input_size-1; - // = lindex_to_pos_arr(d1, d2, d3, input_size-1); + // {d0-1, d1-1, d2-1, d3-1} = lindex_to_pos_arr(d1, d2, d3, input_size-1); std::array expected{d0-1, d1-1, d2-1, d3-1}; TTS_ALL_EQUAL(*kwk::lower_bound(view, search), expected); - auto std_res = std::lower_bound(input.begin(), input.end(), search); - auto std_pos = std_res_to_pos4D(std_res, input.begin(), d1, d2, d3); - // auto dist = static_cast(std::distance(input.begin(), std_res)); - // std::array std_expected = lindex_to_pos_arr(d1, d2, d3, dist); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); TTS_ALL_EQUAL(*kwk::lower_bound(view, search), std_pos); } // Invalid values - // { - // int search = 20; - // TTS_EQUAL(kwk::lower_bound(view, search), std::nullopt); - // TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search), input.end()); - // } - // { - // int search = 78456465; - // TTS_EQUAL(kwk::lower_bound(view, search), std::nullopt); - // TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search), input.end()); - // } + { + int search = input_size; + TTS_EQUAL(kwk::lower_bound(view, search), std::nullopt); + TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search), input.end()); + } + { + int search = input_size + 784565; + TTS_EQUAL(kwk::lower_bound(view, search), std::nullopt); + TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search), input.end()); + } }; -// TTS_CASE("Check for kwk::lower_bound(In, value, func) 4D with function") -// { -// const std::size_t input_size = d0 * d1 * d2 * d3; -// std::array input; -// for (std::size_t i = 0; i < input_size; ++i) { input[i] = (i - 10) * 2; } -// auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1, d2, d3)}; -// auto func = [](auto const& input_, auto const& element_) { return input_ < (element_ - 10) * 2; }; - -// // Valid values -// { -// /*Compare values*/ -// int search = -2984612; -// std::array expected{0, 0, 0, 0}; -// std::array r{expected}; -// TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), r); -// /*Compare with std implementation: compare found indexes*/ -// TTS_EQUAL ( (*kwk::lower_bound(view, search, func))[0] -// , (std::lower_bound(input.begin(), input.end(), search, func) - input.begin()) -// ); -// } -// { -// /*Compare values*/ -// int search = -1; -// std::array expected{0, 0, 0, 0}; -// std::array r{expected}; -// TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), r); -// /*Compare with std implementation: compare found indexes*/ -// TTS_EQUAL ( (*kwk::lower_bound(view, search, func))[0] -// , (std::lower_bound(input.begin(), input.end(), search, func) - input.begin()) -// ); -// } -// { -// /*Compare values*/ -// int search = 0; -// std::array expected{0, 0, 0, 0}; -// std::array r{expected}; -// TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), r); -// /*Compare with std implementation: compare found indexes*/ -// TTS_EQUAL ( (*kwk::lower_bound(view, search, func))[0] -// , (std::lower_bound(input.begin(), input.end(), search, func) - input.begin()) -// ); -// } -// { -// /*Compare values*/ -// int search = 9; -// std::array expected{9}; -// std::array r{expected}; -// TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), r); -// /*Compare with std implementation: compare found indexes*/ -// TTS_EQUAL ( (*kwk::lower_bound(view, search, func))[0] -// , (std::lower_bound(input.begin(), input.end(), search, func) - input.begin()) -// ); -// } -// { -// /*Compare values*/ -// int search = 19; -// std::array expected{19}; -// std::array r{expected}; -// TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), r); -// /*Compare with std implementation: compare found indexes*/ -// TTS_EQUAL ( (*kwk::lower_bound(view, search, func))[0] -// , (std::lower_bound(input.begin(), input.end(), search, func) - input.begin()) -// ); -// } - -// // Erroneous values -// { -// int search = 20; -// TTS_EQUAL(kwk::lower_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search, func), input.end()); -// } -// { -// int search = 78456465; -// TTS_EQUAL(kwk::lower_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search, func), input.end()); -// } -// }; - -// TTS_CASE("Check for kwk::lower_bound 4D: size 0") -// { -// std::vector input; // will not work for an std::array of size 0 -// const std::size_t input_size = 0; -// auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1, d2, d3)}; -// auto func = [](auto const& input_, auto const& element_) { return input_ < (element_ - 10) * 2; }; - -// // Every value should lead to an invalid result -// { -// int search = -2984612; -// // Checks that kwk::lower_bound returns an erroneous value -// TTS_EQUAL(kwk::lower_bound(view, search), std::nullopt); -// // Checks whether we shound really expect an erroneous value (std:: being our source of truth) -// TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search), input.end()); -// } -// { -// int search = -1; -// TTS_EQUAL(kwk::lower_bound(view, search), std::nullopt); -// TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search), input.end()); -// } -// { -// int search = 0; -// TTS_EQUAL(kwk::lower_bound(view, search), std::nullopt); -// TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search), input.end()); -// } -// { -// int search = 19; -// TTS_EQUAL(kwk::lower_bound(view, search), std::nullopt); -// TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search), input.end()); -// } -// { -// int search = 20; -// TTS_EQUAL(kwk::lower_bound(view, search), std::nullopt); -// TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search), input.end()); -// } -// { -// int search = 78456465; -// TTS_EQUAL(kwk::lower_bound(view, search), std::nullopt); -// TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search), input.end()); -// } - -// // With function -// { -// int search = -2984612; -// TTS_EQUAL(kwk::lower_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search, func), input.end()); -// } -// { -// int search = -1; -// TTS_EQUAL(kwk::lower_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search, func), input.end()); -// } -// { -// int search = 0; -// TTS_EQUAL(kwk::lower_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search, func), input.end()); -// } -// { -// int search = 19; -// TTS_EQUAL(kwk::lower_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search, func), input.end()); -// } -// { -// int search = 20; -// TTS_EQUAL(kwk::lower_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search, func), input.end()); -// } -// { -// int search = 78456465; -// TTS_EQUAL(kwk::lower_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search, func), input.end()); -// } -// }; - - -// TTS_CASE("Check for kwk::upper_bound(In, value) 4D") -// { -// const std::size_t input_size = d0 * d1 * d2 * d3; -// std::array input; -// for (std::size_t i = 0; i < input_size; ++i) { input[i] = i; } -// auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1, d2, d3)}; +TTS_CASE("Check for kwk::lower_bound(In, value, func) 4D with function") +{ + const std::size_t d0 = 8; + const std::size_t d1 = 12; + const std::size_t d2 = 6; + const std::size_t d3 = 14; + const std::size_t input_size = d0 * d1 * d2 * d3; + std::array input; + for (std::size_t i = 0; i < input_size; ++i) { input[i] = (i - 10) * 2; } + auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1, d2, d3)}; + auto func = [](auto const& input_, auto const& element_) { return input_ < (element_ - 10) * 2; }; -// // upper_bound returns the index of the first element above the specified value -// { -// int search = -78495; -// std::array expected{0;} -// /*Compare values*/ -// std::array r{expected}; -// TTS_ALL_EQUAL(*kwk::upper_bound(view, search), r); -// /*Compare with std implementation*/ -// TTS_EQUAL ( (*kwk::upper_bound(view, search))[0] -// , (std::upper_bound(input.begin(), input.end(), search) - input.begin()) -// ); -// } -// { -// int search = -1; -// std::array expected{0;} -// /*Compare values*/ -// std::array r{expected}; -// TTS_ALL_EQUAL(*kwk::upper_bound(view, search), r); -// /*Compare with std implementation*/ -// TTS_EQUAL ( (*kwk::upper_bound(view, search))[0] -// , (std::upper_bound(input.begin(), input.end(), search) - input.begin()) -// ); -// } -// { -// int search = 0; -// std::array expected{1;} -// /*Compare values*/ -// std::array r{expected}; -// TTS_ALL_EQUAL(*kwk::upper_bound(view, search), r); -// /*Compare with std implementation*/ -// TTS_EQUAL ( (*kwk::upper_bound(view, search))[0] -// , (std::upper_bound(input.begin(), input.end(), search) - input.begin()) -// ); -// } -// { -// int search = 18; -// std::array expected{19;} -// /*Compare values*/ -// std::array r{expected}; -// TTS_ALL_EQUAL(*kwk::upper_bound(view, search), r); -// /*Compare with std implementation*/ -// TTS_EQUAL ( (*kwk::upper_bound(view, search))[0] -// , (std::upper_bound(input.begin(), input.end(), search) - input.begin()) -// ); -// } + // Valid values + { + /*Compare values*/ + int search = -2984612; + std::array expected{0, 0, 0, 0}; + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), expected); + /*Compare with std implementation: compare found indexes*/ + auto std_res = std::lower_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), std_pos); + } + { + /*Compare values*/ + int search = -1; + std::array expected{0, 0, 0, 0}; + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), expected); + /*Compare with std implementation: compare found indexes*/ + auto std_res = std::lower_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), std_pos); + } + { + /*Compare values*/ + int search = 0; + std::array expected{0, 0, 0, 0}; + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), expected); + /*Compare with std implementation: compare found indexes*/ + auto std_res = std::lower_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), std_pos); + } + { + /*Compare values*/ + int search = 9; + std::array expected = lindex_to_pos_arr(d1, d2, d3, 9); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), expected); + /*Compare with std implementation: compare found indexes*/ + auto std_res = std::lower_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), std_pos); + } + { + /*Compare values*/ + int search = input_size-1; + std::array expected{d0-1, d1-1, d2-1, d3-1}; + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), expected); + /*Compare with std implementation: compare found indexes*/ + auto std_res = std::lower_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); + TTS_ALL_EQUAL(*kwk::lower_bound(view, search, func), std_pos); + } -// // Erroneous values -// { -// int search = 19; -// TTS_EQUAL(kwk::upper_bound(view, search), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search), input.end()); -// } -// { -// int search = 20; -// TTS_EQUAL(kwk::upper_bound(view, search), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search), input.end()); -// } -// { -// int search = 78456465; -// TTS_EQUAL(kwk::upper_bound(view, search), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search), input.end()); -// } -// }; + // Erroneous values + { + int search = input_size; + TTS_EQUAL(kwk::lower_bound(view, search, func), std::nullopt); + TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search, func), input.end()); + } + { + int search = input_size + 784565; + TTS_EQUAL(kwk::lower_bound(view, search, func), std::nullopt); + TTS_EQUAL(std::lower_bound(input.begin(), input.end(), search, func), input.end()); + } +}; -// TTS_CASE("Check for kwk::upper_bound(In, value) 4D with function") -// { -// const std::size_t input_size = d0 * d1 * d2 * d3; -// std::array input; -// for (std::size_t i = 0; i < input_size; ++i) { input[i] = i * 3 - 20; } -// auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1, d2, d3)}; -// auto func = [](auto const& search_, auto const& element_) { return search_ * 3 - 20 < element_; }; +TTS_CASE("Check for kwk::upper_bound(In, value) 4D") +{ + const std::size_t d0 = 8; + const std::size_t d1 = 12; + const std::size_t d2 = 6; + const std::size_t d3 = 14; + const std::size_t input_size = d0 * d1 * d2 * d3; + std::array input; + for (std::size_t i = 0; i < input_size; ++i) { input[i] = i; } + auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1, d2, d3)}; -// // upper_bound returns the index of the first element above the specified value -// { -// int search = -78495; -// std::array expected{0;} -// /*Compare values*/ -// std::array r{expected}; -// TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), r); -// /*Compare with std implementation*/ -// TTS_EQUAL ( (*kwk::upper_bound(view, search, func))[0] -// , (std::upper_bound(input.begin(), input.end(), search, func) - input.begin()) -// ); -// } -// { -// int search = -1; -// std::array expected{0;} -// /*Compare values*/ -// std::array r{expected}; -// TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), r); -// /*Compare with std implementation*/ -// TTS_EQUAL ( (*kwk::upper_bound(view, search, func))[0] -// , (std::upper_bound(input.begin(), input.end(), search, func) - input.begin()) -// ); -// } -// { -// int search = 0; -// std::array expected{1;} -// /*Compare values*/ -// std::array r{expected}; -// TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), r); -// /*Compare with std implementation*/ -// TTS_EQUAL ( (*kwk::upper_bound(view, search, func))[0] -// , (std::upper_bound(input.begin(), input.end(), search, func) - input.begin()) -// ); -// } -// { -// int search = 18; -// std::array expected{19;} -// /*Compare values*/ -// std::array r{expected}; -// TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), r); -// /*Compare with std implementation*/ -// TTS_EQUAL ( (*kwk::upper_bound(view, search, func))[0] -// , (std::upper_bound(input.begin(), input.end(), search, func) - input.begin()) -// ); -// } + // upper_bound returns the index of the first element above the specified value + { + int search = -78495; + std::array expected{0, 0, 0, 0}; + /*Compare values*/ + TTS_ALL_EQUAL(*kwk::upper_bound(view, search), expected); + /*Compare with std implementation*/ + auto std_res = std::upper_bound(input.begin(), input.end(), search); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); + TTS_ALL_EQUAL(*kwk::upper_bound(view, search), std_pos); + } + { + int search = -1; + std::array expected{0, 0, 0, 0}; + /*Compare values*/ + TTS_ALL_EQUAL(*kwk::upper_bound(view, search), expected); + /*Compare with std implementation*/ + auto std_res = std::upper_bound(input.begin(), input.end(), search); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); + TTS_ALL_EQUAL(*kwk::upper_bound(view, search), std_pos); + } + { + int search = 0; + std::array expected{0, 0, 0, 1}; + /*Compare values*/ + TTS_ALL_EQUAL(*kwk::upper_bound(view, search), expected); + /*Compare with std implementation*/ + auto std_res = std::upper_bound(input.begin(), input.end(), search); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); + TTS_ALL_EQUAL(*kwk::upper_bound(view, search), std_pos); + } + { + int search = input_size-2; + std::array expected{d0-1, d1-1, d2-1, d3-1}; + /*Compare values*/ + TTS_ALL_EQUAL(*kwk::upper_bound(view, search), expected); + /*Compare with std implementation*/ + auto std_res = std::upper_bound(input.begin(), input.end(), search); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); + TTS_ALL_EQUAL(*kwk::upper_bound(view, search), std_pos); + } -// // Erroneous values -// { -// int search = 19; -// TTS_EQUAL(kwk::upper_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search, func), input.end()); -// } -// { -// int search = 20; -// TTS_EQUAL(kwk::upper_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search, func), input.end()); -// } -// { -// int search = 78456465; -// TTS_EQUAL(kwk::upper_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search, func), input.end()); -// } -// }; + // Erroneous values + { + int search = input_size-1; + TTS_EQUAL(kwk::upper_bound(view, search), std::nullopt); + TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search), input.end()); + } + { + int search = input_size; + TTS_EQUAL(kwk::upper_bound(view, search), std::nullopt); + TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search), input.end()); + } + { + int search = input_size + 784565; + TTS_EQUAL(kwk::upper_bound(view, search), std::nullopt); + TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search), input.end()); + } +}; -// TTS_CASE("Check for kwk::upper_bound 4D: size = 0") -// { -// const std::size_t input_size = 0; -// std::vector input; // will not work for an std::array of size 0 -// for (std::size_t i = 0; i < input_size; ++i) { input[i] = i * 3 - 20; } -// auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1, d2, d3)}; -// auto func = [](auto const& search_, auto const& element_) { return search_ * 3 - 20 < element_; }; -// // Erroneous values -// { -// int search = -78495; -// TTS_EQUAL(kwk::upper_bound(view, search), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search), input.end()); -// } -// { -// int search = -1; -// TTS_EQUAL(kwk::upper_bound(view, search), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search), input.end()); -// } -// { -// int search = 0; -// TTS_EQUAL(kwk::upper_bound(view, search), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search), input.end()); -// } -// { -// int search = 18; -// TTS_EQUAL(kwk::upper_bound(view, search), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search), input.end()); -// } -// { -// int search = 19; -// TTS_EQUAL(kwk::upper_bound(view, search), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search), input.end()); -// } -// { -// int search = 20; -// TTS_EQUAL(kwk::upper_bound(view, search), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search), input.end()); -// } -// { -// int search = 78456465; -// TTS_EQUAL(kwk::upper_bound(view, search), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search), input.end()); -// } +TTS_CASE("Check for kwk::upper_bound(In, value) 4D with function") +{ + const std::size_t d0 = 8; + const std::size_t d1 = 12; + const std::size_t d2 = 6; + const std::size_t d3 = 14; + const std::size_t input_size = d0 * d1 * d2 * d3; + std::array input; + for (std::size_t i = 0; i < input_size; ++i) { input[i] = i * 3 - 20; } + auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1, d2, d3)}; + auto func = [](auto const& search_, auto const& element_) { return search_ * 3 - 20 < element_; }; -// // Erroneous values, with function -// { -// int search = -78495; -// TTS_EQUAL(kwk::upper_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search, func), input.end()); -// } -// { -// int search = -1; -// TTS_EQUAL(kwk::upper_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search, func), input.end()); -// } -// { -// int search = 0; -// TTS_EQUAL(kwk::upper_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search, func), input.end()); -// } -// { -// int search = 18; -// TTS_EQUAL(kwk::upper_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search, func), input.end()); -// } -// { -// int search = 19; -// TTS_EQUAL(kwk::upper_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search, func), input.end()); -// } -// { -// int search = 20; -// TTS_EQUAL(kwk::upper_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search, func), input.end()); -// } -// { -// int search = 78456465; -// TTS_EQUAL(kwk::upper_bound(view, search, func), std::nullopt); -// TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search, func), input.end()); -// } -// }; + // upper_bound returns the index of the first element above the specified value + { + int search = -78495; + std::array expected{0, 0, 0, 0}; + /*Compare values*/ + TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), expected); + /*Compare with std implementation*/ + auto std_res = std::upper_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); + TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), std_pos); + } + { + int search = -1; + std::array expected{0, 0, 0, 0}; + /*Compare values*/ + TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), expected); + /*Compare with std implementation*/ + auto std_res = std::upper_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); + TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), std_pos); + } + { + int search = 0; + std::array expected{0, 0, 0, 1}; + /*Compare values*/ + TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), expected); + /*Compare with std implementation*/ + auto std_res = std::upper_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); + TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), std_pos); + } + { + int search = input_size-2; + std::array expected{d0-1, d1-1, d2-1, d3-1}; + /*Compare values*/ + TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), expected); + /*Compare with std implementation*/ + auto std_res = std::upper_bound(input.begin(), input.end(), search, func); + auto std_pos = std_res_to_pos(std_res, input.begin(), d1, d2, d3); + TTS_ALL_EQUAL(*kwk::upper_bound(view, search, func), std_pos); + } -// TTS_CASE("Check for kwk::binary_search(In, value) 4D") -// { -// const std::size_t input_size = d0 * d1 * d2 * d3; -// std::array input; -// for (std::size_t i = 0; i < input_size; ++i) { input[i] = i * 3; } -// auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1, d2, d3)}; + // Erroneous values + { + int search = input_size-1; + TTS_EQUAL(kwk::upper_bound(view, search, func), std::nullopt); + TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search, func), input.end()); + } + { + int search = input_size; + TTS_EQUAL(kwk::upper_bound(view, search, func), std::nullopt); + TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search, func), input.end()); + } + { + int search = input_size + 784565; + TTS_EQUAL(kwk::upper_bound(view, search, func), std::nullopt); + TTS_EQUAL(std::upper_bound(input.begin(), input.end(), search, func), input.end()); + } +}; -// // Ensures that the return value is expected -// { -// bool expected = false; -// int search = -895; -// bool truth = kwk::binary_search(view, search); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search)); -// } -// { -// bool expected = false; -// int search = -1; -// bool truth = kwk::binary_search(view, search); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search)); -// } -// { -// bool expected = true; -// int search = 0; -// bool truth = kwk::binary_search(view, search); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search)); -// } -// { -// bool expected = false; -// int search = 18*3-1; -// bool truth = kwk::binary_search(view, search); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search)); -// } -// { -// bool expected = true; -// int search = 18*3; -// bool truth = kwk::binary_search(view, search); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search)); -// } -// { -// bool expected = false; -// int search = 18*3+1; -// bool truth = kwk::binary_search(view, search); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search)); -// } -// { -// bool expected = false; -// int search = 18*3+2; -// bool truth = kwk::binary_search(view, search); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search)); -// } -// { -// bool expected = true; -// int search = 19*3; -// bool truth = kwk::binary_search(view, search); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search)); -// } -// { -// bool expected = false; -// int search = 20*3; -// bool truth = kwk::binary_search(view, search); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search)); -// } -// { -// bool expected = false; -// int search = 2000*3; -// bool truth = kwk::binary_search(view, search); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search)); -// } -// { -// bool expected = false; -// int search = 2000*3+1; -// bool truth = kwk::binary_search(view, search); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search)); -// } -// }; -// TTS_CASE("Check for kwk::binary_search(In, value) 4D with function v1") -// { -// const std::size_t input_size = d0 * d1 * d2 * d3; -// std::array input; -// for (std::size_t i = 0; i < input_size; ++i) { input[i] = i * 3; } // * 3 - 20 -// auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1, d2, d3)}; +TTS_CASE("Check for kwk::binary_search(In, value) 4D") +{ + const std::size_t d0 = 8; + const std::size_t d1 = 12; + const std::size_t d2 = 6; + const std::size_t d3 = 14; + const std::size_t input_size = d0 * d1 * d2 * d3; + std::array input; + for (std::size_t i = 0; i < input_size; ++i) { input[i] = i * 3; } + auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1, d2, d3)}; -// auto func = [](auto const& search_, auto const& element_) { return search_ < element_; }; + // Ensures that the return value is expected + { + bool expected = false; + int search = -895; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = false; + int search = -1; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = true; + int search = 0; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = false; + int search = 18 * 3 - 1; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = true; + int search = 18 * 3; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = false; + int search = 18 * 3 + 1; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = false; + int search = 18 * 3 + 2; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = true; + int search = (input_size-1) * 3; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = false; + int search = (input_size) * 3; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = false; + int search = (input_size + 2000) * 3; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } + { + bool expected = false; + int search = (input_size + 2000) * 3 + 1; + bool found = kwk::binary_search(view, search); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search)); + } +}; +TTS_CASE("Check for kwk::binary_search(In, value) 4D with function") +{ + const std::size_t d0 = 8; + const std::size_t d1 = 12; + const std::size_t d2 = 6; + const std::size_t d3 = 14; + const std::size_t input_size = d0 * d1 * d2 * d3; + std::array input; + for (std::size_t i = 0; i < input_size; ++i) { input[i] = i * 3; } // * 3 - 20 + auto view = kwk::view{kwk::source = input, kwk::of_size(d0, d1, d2, d3)}; + auto func = [](auto const& search_, auto const& element_) { return search_ < element_; }; -// // Ensures that the return value is expected -// { -// bool expected = false; -// int search = -895; -// bool truth = kwk::binary_search(view, search, func); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search, func)); -// } -// { -// bool expected = false; -// int search = -1; -// bool truth = kwk::binary_search(view, search, func); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search, func)); -// } -// { -// bool expected = true; -// int search = 0; -// bool truth = kwk::binary_search(view, search, func); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search, func)); -// } -// { -// bool expected = false; -// int search = 18*3-1; -// bool truth = kwk::binary_search(view, search, func); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search, func)); -// } -// { -// bool expected = true; -// int search = 18*3; -// bool truth = kwk::binary_search(view, search, func); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search, func)); -// } -// { -// bool expected = false; -// int search = 18*3+1; -// bool truth = kwk::binary_search(view, search, func); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search, func)); -// } -// { -// bool expected = false; -// int search = 18*3+2; -// bool truth = kwk::binary_search(view, search, func); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search, func)); -// } -// { -// bool expected = true; -// int search = 19*3; -// bool truth = kwk::binary_search(view, search, func); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search, func)); -// } -// { -// bool expected = false; -// int search = 20*3; -// bool truth = kwk::binary_search(view, search, func); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search, func)); -// } -// { -// bool expected = false; -// int search = 2000*3; -// bool truth = kwk::binary_search(view, search, func); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search, func)); -// } -// { -// bool expected = false; -// int search = 2000*3+1; -// bool truth = kwk::binary_search(view, search, func); -// TTS_EQUAL(truth, expected); // Ensures that we did not make a mistake with the expected value -// TTS_EQUAL(truth, std::binary_search(input.begin(), input.end(), search, func)); -// } -// }; + // Ensures that the return value is expected + { + bool expected = false; + int search = -895; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = false; + int search = -1; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = true; + int search = 0; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = false; + int search = 18 * 3 - 1; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = true; + int search = 18 * 3; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = false; + int search = 18 * 3 + 1; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = false; + int search = 18 * 3 + 2; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = true; + int search = (input_size-1) * 3; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = false; + int search = (input_size) * 3; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = false; + int search = (input_size + 2000) * 3; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } + { + bool expected = false; + int search = (input_size + 2000) * 3 + 1; + bool found = kwk::binary_search(view, search, func); + TTS_EQUAL(found, expected); // Ensures that we did not make a mistake with the expected value + TTS_EQUAL(found, std::binary_search(input.begin(), input.end(), search, func)); + } +};