Created
January 17, 2023 03:13
-
-
Save Shaun289/bb6b5c0a13fa24a8d47c9d8963f621e6 to your computer and use it in GitHub Desktop.
C++ Functional : filter copy_if
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <numeric> | |
#include <gtest/gtest.h> | |
TEST(test_copy_if, TestOdd) | |
{ | |
std::vector<int> v1(10); | |
std::vector<int> v2(5); | |
std::iota(v1.begin(), v1.end(), 0); | |
std::copy_if(v1.begin(), v1.end(), v2.begin(), [] (int x) { | |
return x % 2 != 0; | |
}); | |
std::vector<int> result{1,3,5,7,9}; | |
EXPECT_EQ(v2, result); | |
} | |
int main(int argc, char* argv[]) | |
{ | |
::testing::InitGoogleTest(&argc, argv); | |
return RUN_ALL_TESTS(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment