From fd02a9896e9f9f49e5a0f4499320d561ff8fb637 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sun, 16 Aug 2026 16:46:36 +0200 Subject: kstd: using testing allocator for flat map tests --- libs/kstd/kstd/flat_map.tests.cpp | 43 ++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'libs/kstd') diff --git a/libs/kstd/kstd/flat_map.tests.cpp b/libs/kstd/kstd/flat_map.tests.cpp index 32dbafb2..5f29fa14 100644 --- a/libs/kstd/kstd/flat_map.tests.cpp +++ b/libs/kstd/kstd/flat_map.tests.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -104,10 +105,24 @@ SCENARIO("Flat Map initialization and construction", "[flat_map]") REQUIRE(map.at(5) == 'f'); } } + } + + GIVEN("An unsorted key container and an unsorted value container using an allocator") + { + auto allocator = kstd::tests::tracking_allocator{nullptr}; + + auto keys = kstd::vector{ + {0, 5, 3, 4, 1, 2}, + allocator + }; + auto values = kstd::vector{ + {0, 50, 30, 40, 10, 20}, + allocator + }; WHEN("constructing using the containers and an allocator") { - auto map = kstd::flat_map{keys, values, kstd::allocator{}}; + auto map = kstd::flat_map{keys, values, allocator}; THEN("the flat map has size 6") { @@ -116,18 +131,18 @@ SCENARIO("Flat Map initialization and construction", "[flat_map]") THEN("the flat map contains all pairs in order") { - REQUIRE(map.at(0) == 'a'); - REQUIRE(map.at(1) == 'b'); - REQUIRE(map.at(2) == 'c'); - REQUIRE(map.at(3) == 'd'); - REQUIRE(map.at(4) == 'e'); - REQUIRE(map.at(5) == 'f'); + REQUIRE(map.at(0) == 0); + REQUIRE(map.at(1) == 10); + REQUIRE(map.at(2) == 20); + REQUIRE(map.at(3) == 30); + REQUIRE(map.at(4) == 40); + REQUIRE(map.at(5) == 50); } } WHEN("constructing using the containers and an allocator and a comparator") { - auto map = kstd::flat_map{keys, values, std::less<>{}, kstd::allocator{}}; + auto map = kstd::flat_map{keys, values, std::less<>{}, allocator}; THEN("the flat map has size 6") { @@ -136,12 +151,12 @@ SCENARIO("Flat Map initialization and construction", "[flat_map]") THEN("the flat map contains all pairs in order") { - REQUIRE(map.at(0) == 'a'); - REQUIRE(map.at(1) == 'b'); - REQUIRE(map.at(2) == 'c'); - REQUIRE(map.at(3) == 'd'); - REQUIRE(map.at(4) == 'e'); - REQUIRE(map.at(5) == 'f'); + REQUIRE(map.at(0) == 0); + REQUIRE(map.at(1) == 10); + REQUIRE(map.at(2) == 20); + REQUIRE(map.at(3) == 30); + REQUIRE(map.at(4) == 40); + REQUIRE(map.at(5) == 50); } } } -- cgit v1.2.3