From 5f12ed9f259a825efc7c2354230932712273fab6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 23 Mar 2025 15:25:03 +0000 Subject: Use otherObjects where possible for find --- test/test-collection.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/test-collection.cpp b/test/test-collection.cpp index 13df95c..7fadcf9 100644 --- a/test/test-collection.cpp +++ b/test/test-collection.cpp @@ -47,6 +47,8 @@ BOOST_AUTO_TEST_CASE(empty) BOOST_REQUIRE(!apply(&Base::add)); const auto i = applyOne(&Base::add); BOOST_CHECK_EQUAL(i, end()); + BOOST_CHECK(!find()); + BOOST_CHECK(!find()); } BOOST_AUTO_TEST_CASE(a_base) @@ -58,16 +60,20 @@ BOOST_AUTO_TEST_CASE(a_base) BOOST_CHECK_EQUAL(b->total, 1); const auto i = applyOne(&Base::add); BOOST_CHECK_EQUAL(i, end()); + BOOST_CHECK_EQUAL(b.get(), find()); + BOOST_CHECK(!find()); } BOOST_AUTO_TEST_CASE(emplace_others) { - emplace(std::make_shared()); + auto b = emplace(std::make_shared()); BOOST_CHECK_EQUAL(objects.size(), 1); BOOST_CHECK(std::get>(otherObjects).empty()); - emplace(std::make_shared()); + auto s = emplace(std::make_shared()); BOOST_CHECK_EQUAL(objects.size(), 2); BOOST_CHECK_EQUAL(std::get>(otherObjects).size(), 1); + BOOST_CHECK_EQUAL(b.get(), find()); + BOOST_CHECK_EQUAL(s.get(), find()); } BOOST_AUTO_TEST_CASE(a_rbase) @@ -107,6 +113,25 @@ BOOST_AUTO_TEST_CASE(rbegin_rend) BOOST_CHECK_EQUAL(2, std::distance(rbegin(), rend())); } +BOOST_AUTO_TEST_CASE(createCreate) +{ + auto b = findOrCreate(); + BOOST_CHECK(b); + auto b2 = findOrCreate(); + BOOST_CHECK_EQUAL(b, b2); + auto s = findOrCreate(); + BOOST_CHECK_NE(s, b); + auto s2 = findOrCreate(); + BOOST_CHECK_EQUAL(s, s2); +} + +BOOST_AUTO_TEST_CASE(createCreateSub) +{ + auto s = findOrCreate(); + auto b = findOrCreate(); + BOOST_CHECK_EQUAL(s, b); +} + BOOST_AUTO_TEST_SUITE_END() using TestUniqueCollection = UniqueCollection; -- cgit v1.2.3