29b47fb tests: Check amount and size of equivalent inputs:
The previous implementation was indeed hard to understand.
This is basically a permutation check of a subset of fields, and since we have very few elements here (given it's test code), we could either simplify further to:
static bool HaveEquivalentInputs(const SelectionResult& a, const SelectionResult& b)
{
return std::ranges::is_permutation(a.GetInputSet(), b.GetInputSet(), [](auto& x, auto& y) {
return x->txout.nValue == y->txout.nValue && x->input_bytes == y->input_bytes;
});
}
or if you don't find this readable we could extract the common parts that prepare the final comparable objects and compare those directly at the call site:
/** The (amount, input size) pairs of a result's inputs in sorted order, which identify a selection regardless of the prevouts of its inputs. */
static std::vector<std::pair<CAmount, int>> SortedInputs(const SelectionResult& result)
{
std::vector<std::pair<CAmount, int>> inputs;
for (auto& coin : result.GetInputSet()) {
inputs.emplace_back(coin->txout.nValue, coin->input_bytes);
}
std::ranges::sort(inputs);
return inputs;
}
and in the assertion we can have
BOOST_TEST(SortedInputs(*result) == SortedInputs(expected_result));
directly.