Changeset View
Changeset View
Standalone View
Standalone View
src/tests/client/util-test.cpp
| Show All 40 Lines | TEST_CASE("sortedUniqueMerge should behave correctly", "[client][clientutil]") | ||||
| auto exists = [base](auto m) { return std::find(base.begin(), base.end(), m) != base.end(); }; | auto exists = [base](auto m) { return std::find(base.begin(), base.end(), m) != base.end(); }; | ||||
| auto key = [](auto m) { return m.value; }; | auto key = [](auto m) { return m.value; }; | ||||
| auto res = sortedUniqueMerge(base, addon, exists, key); | auto res = sortedUniqueMerge(base, addon, exists, key); | ||||
| REQUIRE( res == immer::flex_vector<Model>{{1, "a"}, {2, "b"}, {50, "foo"}, {70, "c"}, {100, "bar"}, {110, "d"}} ); | REQUIRE( res == immer::flex_vector<Model>{{1, "a"}, {2, "b"}, {50, "foo"}, {70, "c"}, {100, "bar"}, {110, "d"}} ); | ||||
| } | } | ||||
| TEST_CASE("sortedUniqueMerge should auto detect existing items", "[client][clientutil]") | |||||
| { | |||||
| immer::flex_vector<Model> base = {{50, "foo"}, {100, "bar"}}; | |||||
| immer::flex_vector<Model> addon = {{1, "a"}, {2, "b"}, {50, "xxx"}, {70, "c"}, {110, "d"}}; | |||||
| auto exists = [](auto) { return false; }; | |||||
| auto key = [](auto m) { return m.value; }; | |||||
| auto res = sortedUniqueMerge(base, addon, exists, key); | |||||
| REQUIRE( res == immer::flex_vector<Model>{{1, "a"}, {2, "b"}, {50, "foo"}, {70, "c"}, {100, "bar"}, {110, "d"}} ); | |||||
| } | |||||