gt22

Untitled

May 7th, 2020
1,594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include "linq.hpp"
  2. #include "doctest.h"
  3. #include <vector>
  4. #include <set>
  5. #include <iterator>
  6.  
  7. using linq::from;
  8.  
  9. TEST_CASE("from_to_vector set") {
  10.  
  11.     std::set<bool> v = {true, false, true};
  12.     std::vector<bool> u = from(v.begin(), v.end()).to_vector();
  13.     bool valid = u == std::vector<bool>{false, true} || u == std::vector<bool>{false, true};
  14.     CHECK(valid);
  15. }
  16.  
  17. TEST_CASE("from_copy_to vector->set") {
  18.     std::vector<int> v = {1, 2, 2, 3, 3, 4, 5, 6};
  19.     std::set<int> s;
  20.     from(v.begin(), v.end()).copy_to(std::inserter(s, s.begin()));
  21.     CHECK(s == std::set<int>{1, 2, 3, 4, 5, 6});
  22. }
  23.  
  24. TEST_CASE("complex computation") {
  25.     std::vector<int> v = {1, 2, 2, 3, 3, 4, 5, 6};
  26.     std::vector<int> u = from(v.begin(), v.end())
  27.             .select([](int x){ return x + 2; })
  28.             .where([](int x){ return x % 2 == 0; })
  29.             .where_neq(4)
  30.             .until([](int x){ return x >= 7; })
  31.             .select([](int x){ return x / 2; })
  32.             .to_vector();
  33.     CHECK(u == std::vector<int>{3});
  34. }
Advertisement
Add Comment
Please, Sign In to add comment