join_test.cxx 781 B

12345678910111213141516171819202122232425262728293031
  1. //
  2. // join_test.cxx
  3. // stream-test
  4. //
  5. // Created by Sam Jaffe on 4/5/23.
  6. //
  7. #include "stream/view/join.h"
  8. #include "stream/view/transform.h"
  9. #include "stream_helpers.h"
  10. #include "stream_matchers.h"
  11. TEST(JoinView, CanJoinCollectionOfCollections) {
  12. std::vector<std::vector<int>> const input{{1, 2, 3}, {2, 3, 4}, {3, 4, 5}};
  13. EXPECT_THAT(input | views::join(),
  14. RangesEq(std::vector{1, 2, 3, 2, 3, 4, 3, 4, 5}));
  15. }
  16. TEST(JoinView, CanJoinTemporaryCollections) {
  17. std::vector<int> const input{1, 2, 3};
  18. auto const range = input | views::transform([](int i) {
  19. return std::vector{i, i + 1, i + 2};
  20. }) |
  21. views::join();
  22. EXPECT_THAT(range, RangesEq(std::vector{1, 2, 3, 2, 3, 4, 3, 4, 5}));
  23. }