Skip to content

Commit

Permalink
Adding a ranges verfication function to see if all elements are the s…
Browse files Browse the repository at this point in the history
…ame value
  • Loading branch information
whaeck committed Aug 7, 2024
1 parent cb4aed8 commit 9c49ddc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/scion/verification/ranges.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ bool isUnique( const Range& range ) {
return range.end() == std::adjacent_find( range.begin(), range.end() );
}

/** @brief Verify if a range consists of the same element
*
* @param[in] range the range
*/
template < typename Range >
bool isAllSameElement( const Range& range ) {

return range.end() == std::adjacent_find( range.begin(), range.end(),
std::not_equal_to{} );
}

} // math namespace
} // scion namespace
} // njoy namespace
Expand Down
4 changes: 4 additions & 0 deletions src/scion/verification/ranges/test/ranges.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ SCENARIO( "verification ranges" ) {
std::vector< double > unsorted = { 3., 2., 1. };
std::vector< double > unique = { 1., 2., 3. };
std::vector< double > notunique = { 1., 2., 2., 3. };
std::vector< double > same = { 1., 1., 1., 1. };

WHEN( "the verification functions are called" ) {

Expand Down Expand Up @@ -47,6 +48,9 @@ SCENARIO( "verification ranges" ) {
CHECK( true == verification::isUnique( size1 ) );
CHECK( true == verification::isUnique( unique ) );
CHECK( false == verification::isUnique( notunique ) );

CHECK( false == verification::isAllSameElement( unique ) );
CHECK( true == verification::isAllSameElement( same ) );
} // THEN
} // WHEN
} // GIVEN
Expand Down

0 comments on commit 9c49ddc

Please sign in to comment.