mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-08 13:40:39 +02:00
added all_equal to algorithm
This commit is contained in:
parent
66204d0b59
commit
cb61ee2fee
@ -107,5 +107,16 @@ std::vector<T> cumsum(const std::vector<T>& vec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Container> bool all_equal(const Container &c) {
|
||||||
|
if (!c.empty() &&
|
||||||
|
std::all_of(begin(c), end(c),
|
||||||
|
[c](const typename Container::value_type &element) {
|
||||||
|
return element == c.front();
|
||||||
|
}))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace aare
|
} // namespace aare
|
@ -1,4 +1,5 @@
|
|||||||
#include "aare/RawFile.hpp"
|
#include "aare/RawFile.hpp"
|
||||||
|
#include "aare/algorithm.hpp"
|
||||||
#include "aare/PixelMap.hpp"
|
#include "aare/PixelMap.hpp"
|
||||||
#include "aare/defs.hpp"
|
#include "aare/defs.hpp"
|
||||||
#include "aare/logger.hpp"
|
#include "aare/logger.hpp"
|
||||||
@ -200,9 +201,7 @@ void RawFile::get_frame_into(size_t frame_index, std::byte *frame_buffer, Detect
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 1. if frame number vector is the same break
|
// 1. if frame number vector is the same break
|
||||||
while (std::adjacent_find(frame_numbers.begin(), frame_numbers.end(),
|
while (!all_equal(frame_numbers)) {
|
||||||
std::not_equal_to<>()) !=
|
|
||||||
frame_numbers.end()) {
|
|
||||||
|
|
||||||
// 2. find the index of the minimum frame number,
|
// 2. find the index of the minimum frame number,
|
||||||
auto min_frame_idx = std::distance(
|
auto min_frame_idx = std::distance(
|
||||||
|
@ -168,3 +168,28 @@ TEST_CASE("cumsum on an empty vector", "[algorithm]") {
|
|||||||
REQUIRE(result.size() == 0);
|
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);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user