#include "linq.hpp" #include "doctest.h" #include #include #include using linq::from; TEST_CASE("from_to_vector set") { std::set v = {true, false, true}; std::vector u = from(v.begin(), v.end()).to_vector(); bool valid = u == std::vector{false, true} || u == std::vector{false, true}; CHECK(valid); } TEST_CASE("from_copy_to vector->set") { std::vector v = {1, 2, 2, 3, 3, 4, 5, 6}; std::set s; from(v.begin(), v.end()).copy_to(std::inserter(s, s.begin())); CHECK(s == std::set{1, 2, 3, 4, 5, 6}); } TEST_CASE("complex computation") { std::vector v = {1, 2, 2, 3, 3, 4, 5, 6}; std::vector u = from(v.begin(), v.end()) .select([](int x){ return x + 2; }) .where([](int x){ return x % 2 == 0; }) .where_neq(4) .until([](int x){ return x >= 7; }) .select([](int x){ return x / 2; }) .to_vector(); CHECK(u == std::vector{3}); }