mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-02-20 10:58:40 +01:00
For 2025.5.22 release (#181)
Co-authored-by: Patrick <patrick.sieberer@psi.ch> Co-authored-by: JulianHeymes <julian.heymes@psi.ch> Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch> Co-authored-by: Xiangyu Xie <45243914+xiangyuxie@users.noreply.github.com> Co-authored-by: xiangyu.xie <xiangyu.xie@psi.ch> Co-authored-by: AliceMazzoleni99 <alice.mazzoleni@psi.ch> Co-authored-by: Mazzoleni Alice Francesca <mazzol_a@pc17378.psi.ch> Co-authored-by: siebsi <sieb.patr@gmail.com>
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <aare/algorithm.hpp>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("Find the closed index in a 1D array", "[algorithm]") {
|
||||
aare::NDArray<double, 1> arr({5});
|
||||
@@ -17,7 +16,7 @@ TEST_CASE("Find the closed index in a 1D array", "[algorithm]") {
|
||||
REQUIRE(aare::nearest_index(arr, -1.0) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Passing integers to nearest_index works", "[algorithm]"){
|
||||
TEST_CASE("Passing integers to nearest_index works", "[algorithm]") {
|
||||
aare::NDArray<int, 1> arr({5});
|
||||
for (ssize_t i = 0; i < arr.size(); i++) {
|
||||
arr[i] = i;
|
||||
@@ -30,8 +29,7 @@ TEST_CASE("Passing integers to nearest_index works", "[algorithm]"){
|
||||
REQUIRE(aare::nearest_index(arr, -1) == 0);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("nearest_index works with std::vector", "[algorithm]"){
|
||||
TEST_CASE("nearest_index works with std::vector", "[algorithm]") {
|
||||
std::vector<double> vec = {0, 1, 2, 3, 4};
|
||||
REQUIRE(aare::nearest_index(vec, 2.123) == 2);
|
||||
REQUIRE(aare::nearest_index(vec, 2.66) == 3);
|
||||
@@ -40,7 +38,7 @@ TEST_CASE("nearest_index works with std::vector", "[algorithm]"){
|
||||
REQUIRE(aare::nearest_index(vec, -10.0) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("nearest index works with std::array", "[algorithm]"){
|
||||
TEST_CASE("nearest index works with std::array", "[algorithm]") {
|
||||
std::array<double, 5> arr = {0, 1, 2, 3, 4};
|
||||
REQUIRE(aare::nearest_index(arr, 2.123) == 2);
|
||||
REQUIRE(aare::nearest_index(arr, 2.501) == 3);
|
||||
@@ -49,18 +47,20 @@ TEST_CASE("nearest index works with std::array", "[algorithm]"){
|
||||
REQUIRE(aare::nearest_index(arr, -10.0) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("nearest index when there is no different uses the first element", "[algorithm]"){
|
||||
TEST_CASE("nearest index when there is no different uses the first element",
|
||||
"[algorithm]") {
|
||||
std::vector<int> vec = {5, 5, 5, 5, 5};
|
||||
REQUIRE(aare::nearest_index(vec, 5) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("nearest index when there is no different uses the first element also when all smaller", "[algorithm]"){
|
||||
TEST_CASE("nearest index when there is no different uses the first element "
|
||||
"also when all smaller",
|
||||
"[algorithm]") {
|
||||
std::vector<int> vec = {5, 5, 5, 5, 5};
|
||||
REQUIRE(aare::nearest_index(vec, 10) == 0);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("last smaller", "[algorithm]"){
|
||||
TEST_CASE("last smaller", "[algorithm]") {
|
||||
aare::NDArray<double, 1> arr({5});
|
||||
for (ssize_t i = 0; i < arr.size(); i++) {
|
||||
arr[i] = i;
|
||||
@@ -72,17 +72,17 @@ TEST_CASE("last smaller", "[algorithm]"){
|
||||
REQUIRE(aare::last_smaller(arr, 253.) == 4);
|
||||
}
|
||||
|
||||
TEST_CASE("returns last bin strictly smaller", "[algorithm]"){
|
||||
TEST_CASE("returns last bin strictly smaller", "[algorithm]") {
|
||||
aare::NDArray<double, 1> arr({5});
|
||||
for (ssize_t i = 0; i < arr.size(); i++) {
|
||||
arr[i] = i;
|
||||
}
|
||||
// arr 0, 1, 2, 3, 4
|
||||
REQUIRE(aare::last_smaller(arr, 2.0) == 1);
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("last_smaller with all elements smaller returns last element", "[algorithm]"){
|
||||
TEST_CASE("last_smaller with all elements smaller returns last element",
|
||||
"[algorithm]") {
|
||||
aare::NDArray<double, 1> arr({5});
|
||||
for (ssize_t i = 0; i < arr.size(); i++) {
|
||||
arr[i] = i;
|
||||
@@ -91,7 +91,8 @@ TEST_CASE("last_smaller with all elements smaller returns last element", "[algor
|
||||
REQUIRE(aare::last_smaller(arr, 50.) == 4);
|
||||
}
|
||||
|
||||
TEST_CASE("last_smaller with all elements bigger returns first element", "[algorithm]"){
|
||||
TEST_CASE("last_smaller with all elements bigger returns first element",
|
||||
"[algorithm]") {
|
||||
aare::NDArray<double, 1> arr({5});
|
||||
for (ssize_t i = 0; i < arr.size(); i++) {
|
||||
arr[i] = i;
|
||||
@@ -100,38 +101,41 @@ TEST_CASE("last_smaller with all elements bigger returns first element", "[algor
|
||||
REQUIRE(aare::last_smaller(arr, -50.) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("last smaller with all elements equal returns the first element", "[algorithm]"){
|
||||
std::vector<int> vec = {5,5,5,5,5,5,5};
|
||||
TEST_CASE("last smaller with all elements equal returns the first element",
|
||||
"[algorithm]") {
|
||||
std::vector<int> vec = {5, 5, 5, 5, 5, 5, 5};
|
||||
REQUIRE(aare::last_smaller(vec, 5) == 0);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("first_lager with vector", "[algorithm]"){
|
||||
TEST_CASE("first_lager with vector", "[algorithm]") {
|
||||
std::vector<double> vec = {0, 1, 2, 3, 4};
|
||||
REQUIRE(aare::first_larger(vec, 2.5) == 3);
|
||||
}
|
||||
|
||||
TEST_CASE("first_lager with all elements smaller returns last element", "[algorithm]"){
|
||||
TEST_CASE("first_lager with all elements smaller returns last element",
|
||||
"[algorithm]") {
|
||||
std::vector<double> vec = {0, 1, 2, 3, 4};
|
||||
REQUIRE(aare::first_larger(vec, 50.) == 4);
|
||||
}
|
||||
|
||||
TEST_CASE("first_lager with all elements bigger returns first element", "[algorithm]"){
|
||||
TEST_CASE("first_lager with all elements bigger returns first element",
|
||||
"[algorithm]") {
|
||||
std::vector<double> vec = {0, 1, 2, 3, 4};
|
||||
REQUIRE(aare::first_larger(vec, -50.) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("first_lager with all elements the same as the check returns last", "[algorithm]"){
|
||||
TEST_CASE("first_lager with all elements the same as the check returns last",
|
||||
"[algorithm]") {
|
||||
std::vector<int> vec = {14, 14, 14, 14, 14};
|
||||
REQUIRE(aare::first_larger(vec, 14) == 4);
|
||||
}
|
||||
|
||||
TEST_CASE("first larger with the same element", "[algorithm]"){
|
||||
std::vector<int> vec = {7,8,9,10,11};
|
||||
TEST_CASE("first larger with the same element", "[algorithm]") {
|
||||
std::vector<int> vec = {7, 8, 9, 10, 11};
|
||||
REQUIRE(aare::first_larger(vec, 9) == 3);
|
||||
}
|
||||
|
||||
TEST_CASE("cumsum works", "[algorithm]"){
|
||||
TEST_CASE("cumsum works", "[algorithm]") {
|
||||
std::vector<double> vec = {0, 1, 2, 3, 4};
|
||||
auto result = aare::cumsum(vec);
|
||||
REQUIRE(result.size() == vec.size());
|
||||
@@ -141,12 +145,12 @@ TEST_CASE("cumsum works", "[algorithm]"){
|
||||
REQUIRE(result[3] == 6);
|
||||
REQUIRE(result[4] == 10);
|
||||
}
|
||||
TEST_CASE("cumsum works with empty vector", "[algorithm]"){
|
||||
TEST_CASE("cumsum works with empty vector", "[algorithm]") {
|
||||
std::vector<double> vec = {};
|
||||
auto result = aare::cumsum(vec);
|
||||
REQUIRE(result.size() == 0);
|
||||
}
|
||||
TEST_CASE("cumsum works with negative numbers", "[algorithm]"){
|
||||
TEST_CASE("cumsum works with negative numbers", "[algorithm]") {
|
||||
std::vector<double> vec = {0, -1, -2, -3, -4};
|
||||
auto result = aare::cumsum(vec);
|
||||
REQUIRE(result.size() == vec.size());
|
||||
@@ -157,3 +161,35 @@ TEST_CASE("cumsum works with negative numbers", "[algorithm]"){
|
||||
REQUIRE(result[4] == -10);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("cumsum on an empty vector", "[algorithm]") {
|
||||
std::vector<double> vec = {};
|
||||
auto result = aare::cumsum(vec);
|
||||
REQUIRE(result.size() == 0);
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("All equal on an empty vector is false", "[algorithm]") {
|
||||
std::vector<int> vec = {};
|
||||
REQUIRE(aare::all_equal(vec) == false);
|
||||
}
|
||||
|
||||
TEST_CASE("All equal on a vector with 1 element is true", "[algorithm]") {
|
||||
std::vector<int> vec = {1};
|
||||
REQUIRE(aare::all_equal(vec) == true);
|
||||
}
|
||||
|
||||
TEST_CASE("All equal on a vector with 2 elements is true", "[algorithm]") {
|
||||
std::vector<int> vec = {1, 1};
|
||||
REQUIRE(aare::all_equal(vec) == true);
|
||||
}
|
||||
|
||||
TEST_CASE("All equal on a vector with two different elements is false", "[algorithm]") {
|
||||
std::vector<int> vec = {1, 2};
|
||||
REQUIRE(aare::all_equal(vec) == false);
|
||||
}
|
||||
|
||||
TEST_CASE("Last element is different", "[algorithm]") {
|
||||
std::vector<int> vec = {1, 1, 1, 1, 2};
|
||||
REQUIRE(aare::all_equal(vec) == false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user