From 38547fe8ef1595726706ee3ecc7d33aaf352fbf7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 29 Jun 2024 17:55:32 +0100 Subject: Implement partition on InstanceVertices --- test/test-instancing.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test/test-instancing.cpp') diff --git a/test/test-instancing.cpp b/test/test-instancing.cpp index c1860a4..37f32c8 100644 --- a/test/test-instancing.cpp +++ b/test/test-instancing.cpp @@ -174,4 +174,34 @@ BOOST_DATA_TEST_CASE(shuffle_random, boost::unit_test::data::xrange(0, 10), x) } } +BOOST_AUTO_TEST_CASE(partition_by, *boost::unit_test::timeout(1)) +{ + std::mt19937 gen(std::random_device {}()); + std::uniform_int_distribution dist(0, 100000); + static constexpr auto N = 1000; + reserve(N); + std::vector instances; + instances.reserve(N); + // At least one of each + instances.push_back(acquire(1)); + instances.push_back(acquire(3)); + while (instances.size() < N) { + instances.push_back(acquire(dist(gen))); + } + const std::vector values(instances.begin(), instances.end()); + BOOST_REQUIRE_EQUAL(size(), N); + + const auto pred = [](auto x) { + return (x % 3) == 0; + }; + auto matchedEnd = partition(pred); + // The underlying data is partitioned... + BOOST_REQUIRE(std::is_partitioned(mkcspan().cbegin(), mkcspan().cend(), pred)); + // The external view of the data is unchanged... + BOOST_CHECK_EQUAL_COLLECTIONS(values.cbegin(), values.cend(), instances.cbegin(), instances.cend()); + // The partition point is right... + BOOST_CHECK(!pred(*matchedEnd)); + BOOST_CHECK(pred(*--matchedEnd)); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3