all_test.cxx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //
  2. // all_test.cxx
  3. // stream-test
  4. //
  5. // Created by Sam Jaffe on 4/2/23.
  6. //
  7. #include "stream/view/all.h"
  8. #include "stream_helpers.h"
  9. #include "stream_matchers.h"
  10. using testing::Ne;
  11. TEST(AllView, IteratesOverNonConst) {
  12. std::vector<int> input{1, 2, 3, 4, 5};
  13. auto view = views::all(input);
  14. EXPECT_FALSE(view.empty());
  15. EXPECT_THAT(view.size(), input.size());
  16. EXPECT_THAT(view, RangesEq(input));
  17. }
  18. TEST(AllView, IteratesOverConst) {
  19. std::vector<int> const input{1, 2, 3, 4, 5};
  20. auto view = views::all(input);
  21. EXPECT_FALSE(view.empty());
  22. EXPECT_THAT(view.size(), input.size());
  23. EXPECT_THAT(view, RangesEq(input));
  24. }
  25. TEST(AllView, TakesOwnershipOfRvalue) {
  26. std::vector<int> input{1, 2, 3, 4, 5};
  27. auto * address = &input;
  28. auto view = views::all(static_cast<std::vector<int> &&>(input));
  29. EXPECT_TRUE(input.empty());
  30. EXPECT_THAT(&view.base(), Ne(address));
  31. }
  32. TEST(AllView, IteratesOverRvalue) {
  33. auto view = views::all(std::vector{1, 2, 3, 4, 5});
  34. EXPECT_FALSE(view.empty());
  35. EXPECT_THAT(view.size(), 5);
  36. EXPECT_THAT(view, RangesEq(std::vector{1, 2, 3, 4, 5}));
  37. }