| 73 | |
| 74 | template<typename Container, auto Maker = nullptr, typename... Args> |
| 75 | void DoTest(Args ...args) |
| 76 | { |
| 77 | auto Make = [](int value){ |
| 78 | if constexpr (!bool(Maker)) |
| 79 | return Component(value, Ignore{}); |
| 80 | else |
| 81 | return Maker(value); |
| 82 | }; |
| 83 | |
| 84 | using ComponentType = decltype(Make(0)); |
| 85 | |
| 86 | // CompositeBase passes constructor arguments to its Component |
| 87 | Container container{ args... }; |
| 88 | REQUIRE(0 == container); |
| 89 | REQUIRE(container.empty()); |
| 90 | |
| 91 | constexpr int N = 4; |
| 92 | |
| 93 | // Values for comparison |
| 94 | vector<int> values(N); |
| 95 | iota(values.begin(), values.end(), 1); |
| 96 | |
| 97 | // Make some components |
| 98 | vector<ComponentType> components; |
| 99 | // Not yet equal |
| 100 | REQUIRE(!compareSequences(values, components)); |
| 101 | |
| 102 | for (size_t ii = 1; ii <= N; ++ii) |
| 103 | components.push_back(Make(ii)); |
| 104 | |
| 105 | // Equal values so far |
| 106 | if (!bool(Maker)) |
| 107 | REQUIRE(compareSequences(values, components)); |
| 108 | |
| 109 | // Composite works with push_back and back_inserter |
| 110 | move(components.begin(), components.end(), back_inserter(container)); |
| 111 | REQUIRE(!container.empty()); |
| 112 | REQUIRE(compareSequences(values, container)); |
| 113 | |
| 114 | // Break equality of sequences |
| 115 | values.push_back(N + 1); |
| 116 | REQUIRE(!compareSequences(values, container)); |
| 117 | |
| 118 | // Restore equality (and note, Component can take more arguments) |
| 119 | container.push_back(Make(N + 1)); |
| 120 | REQUIRE(compareSequences(values, container)); |
| 121 | } |
| 122 | |
| 123 | TEST_CASE("Composite::Base") |
| 124 | { |