all_test.cxx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/algorithm.h"
  9. #include "stream_test.h"
  10. using testing::Eq;
  11. using testing::Ne;
  12. TEST(AllView, IteratesOverNonConst) {
  13. std::vector<int> input{1, 2, 3, 4, 5};
  14. auto view = views::all(input);
  15. EXPECT_FALSE(view.empty());
  16. EXPECT_THAT(view.size(), input.size());
  17. EXPECT_THAT(view, RangesEq(input));
  18. }
  19. TEST(AllView, IteratesOverConst) {
  20. std::vector<int> const input{1, 2, 3, 4, 5};
  21. auto view = views::all(input);
  22. EXPECT_FALSE(view.empty());
  23. EXPECT_THAT(view.size(), input.size());
  24. EXPECT_THAT(view, RangesEq(input));
  25. }
  26. TEST(AllView, TakesOwnershipOfRvalue) {
  27. std::vector<int> input{1, 2, 3, 4, 5};
  28. auto * address = &input;
  29. auto view = views::all(static_cast<std::vector<int> &&>(input));
  30. EXPECT_TRUE(input.empty());
  31. EXPECT_THAT(&view.base(), Ne(address));
  32. }
  33. TEST(AllView, IteratesOverRvalue) {
  34. auto view = views::all(std::vector{1, 2, 3, 4, 5});
  35. EXPECT_FALSE(view.empty());
  36. EXPECT_THAT(view.size(), 5);
  37. EXPECT_THAT(view, RangesEq(std::vector{1, 2, 3, 4, 5}));
  38. }