Skip to content

Commit

Permalink
Adding test for count_if
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed May 20, 2024
1 parent 537dd77 commit 01855e9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/tools/std20/algorithm/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_cpp_test( std20.algorithm.count count.test.cpp )
add_cpp_test( std20.algorithm.count_if count_if.test.cpp )
add_cpp_test( std20.algorithm.adjacent_find adjacent_find.test.cpp )
add_cpp_test( std20.algorithm.equal equal.test.cpp )
add_cpp_test( std20.algorithm.find find.test.cpp )
Expand Down
28 changes: 28 additions & 0 deletions src/tools/std20/algorithm/test/count_if.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// include Catch2
#include <catch2/catch_test_macros.hpp>

// what we are testing
#include "tools/std20/algorithm.hpp"

// other includes

// convenience typedefs
using namespace njoy::tools;

SCENARIO( "adjacent_find" ) {

int a[] = { 1, 2, 3, 3, 4, 5 };

std::vector< int > va = { 1, 2, 3, 3, 4, 5 };

auto compare = [] ( auto&& value ) { return value % 2 == 0; };

CHECK( 2 == std20::count_if( std20::ranges::begin( a ), std20::ranges::end( a ), compare ) );

CHECK( 2 == std20::count_if( std20::ranges::begin( va ), std20::ranges::end( va ), compare ) );

CHECK( 2 == std20::count_if( a, compare ) );

CHECK( 2 == std20::count_if( va, compare ) );

} // SCENARIO

0 comments on commit 01855e9

Please sign in to comment.