diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-08-16 16:46:36 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-08-16 16:46:36 +0200 |
| commit | fd02a9896e9f9f49e5a0f4499320d561ff8fb637 (patch) | |
| tree | 5020865ebfd05ddb585c7057b65518fbc32e5b48 | |
| parent | 0725c50ee74f3028ea13e70f60a59db4d8a5e988 (diff) | |
| download | kernel-fd02a9896e9f9f49e5a0f4499320d561ff8fb637.tar.xz kernel-fd02a9896e9f9f49e5a0f4499320d561ff8fb637.zip | |
kstd: using testing allocator for flat map tests
| -rw-r--r-- | libs/kstd/kstd/flat_map.tests.cpp | 43 |
1 files changed, 29 insertions, 14 deletions
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 <kstd/allocator.hpp> #include <kstd/test_support/os_panic.hpp> +#include <kstd/test_support/test_types.hpp> #include <kstd/vector.hpp> #include <catch2/catch_test_macros.hpp> @@ -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<int>{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<int>{}}; + 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<int>{}}; + 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); } } } |
