| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- //
- // to_container_test.cxx
- // stream-test
- //
- // Created by Sam Jaffe on 4/5/23.
- //
- #include "stream/to_container.h"
- #include "stream_helpers.h"
- #include "stream_matchers.h"
- using testing::ElementsAre;
- using testing::Pair;
- using testing::StaticAssertTypeEq;
- TEST(ToContainer, ConvertsToSet) {
- std::vector<int> const input{0, 1, 2, 1, 2};
- auto output = input | ranges::to_set();
- StaticAssertTypeEq<decltype(output), std::set<int>>();
- EXPECT_THAT(output, ElementsAre(0, 1, 2));
- }
- TEST(ToContainer, ConvertsToVector) {
- std::set<int> const input{0, 1, 2};
- auto output = input | ranges::to_vector();
- StaticAssertTypeEq<decltype(output), std::vector<int>>();
- EXPECT_THAT(output, ElementsAre(0, 1, 2));
- }
- TEST(ToContainer, CanConvertPairContainerToAssoc) {
- std::vector<std::pair<int, std::string>> const input{{0, "hello"},
- {1, "goodbye"}};
- auto output = input | ranges::to_map();
- StaticAssertTypeEq<decltype(output), std::map<int, std::string>>();
- EXPECT_THAT(output, ElementsAre(Pair(0, "hello"), Pair(1, "goodbye")));
- }
- TEST(ToContainer, CanConvertAssocToPairContainer) {
- std::map<int, std::string> const input{{0, "hello"}, {1, "goodbye"}};
- auto output = input | ranges::to_vector();
- StaticAssertTypeEq<decltype(output),
- std::vector<std::pair<int const, std::string>>>();
- EXPECT_THAT(output, ElementsAre(Pair(0, "hello"), Pair(1, "goodbye")));
- }
|