based

Opinionated utility library
git clone git://git.dimitrijedobrota.com/based.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

for_each_test.cpp (968B)


0 #include <array> 1 2 #include <catch2/catch_test_macros.hpp> 3 4 #include "based/algorithm.hpp" 5 6 struct functor 7 { 8 int operator()(int n) { return sum += n; } 9 10 int sum = 0; 11 }; 12 13 TEST_CASE("for_each(empty)", "[algorithm/for_each]") 14 { 15 const std::array<int, 0> arr = {}; 16 const auto func = based::for_each(std::begin(arr), std::end(arr), functor {}); 17 18 REQUIRE(func.sum == 0); 19 } 20 21 TEST_CASE("for_each(one)", "[algorithm/for_each]") 22 { 23 const std::array arr = {1}; 24 const auto func = based::for_each(std::begin(arr), std::end(arr), functor {}); 25 26 REQUIRE(func.sum == 1); 27 } 28 29 TEST_CASE("for_each(two)", "[algorithm/for_each]") 30 { 31 const std::array arr = {1, 2}; 32 const auto func = based::for_each(std::begin(arr), std::end(arr), functor {}); 33 34 REQUIRE(func.sum == 3); 35 } 36 37 TEST_CASE("for_each(three)", "[algorithm/for_each]") 38 { 39 const std::array arr = {1, 2, 3}; 40 const auto func = based::for_each(std::begin(arr), std::end(arr), functor {}); 41 42 REQUIRE(func.sum == 6); 43 }