| 20 | #include "fl/stl/int.h" |
| 21 | |
| 22 | FL_TEST_FILE(FL_FILEPATH) { |
| 23 | |
| 24 | using namespace fl; |
| 25 | |
| 26 | FL_TEST_CASE("Empty map properties") { |
| 27 | fl::unordered_map<int, int> m; |
| 28 | FL_REQUIRE_EQ(m.size(), 0u); |
| 29 | FL_REQUIRE(!m.find_value(42)); |
| 30 | // begin()==end() on empty |
| 31 | FL_REQUIRE(m.begin() == m.end()); |
| 32 | } |
| 33 | |
| 34 | FL_TEST_CASE("Single insert, lookup & operator[]") { |
| 35 | fl::unordered_map<int, int> m; |
| 36 | m.insert(10, 20); |
| 37 | FL_REQUIRE_EQ(m.size(), 1u); |
| 38 | auto *v = m.find_value(10); |
| 39 | FL_REQUIRE(v); |
| 40 | FL_REQUIRE_EQ(*v, 20); |
| 41 | |
| 42 | // operator[] default-construct & assignment |
| 43 | fl::unordered_map<int, fl::string> ms; |
| 44 | auto &ref = ms[5]; |
| 45 | FL_REQUIRE(ref.empty()); // default-constructed |
| 46 | FL_REQUIRE_EQ(ms.size(), 1u); |
| 47 | ref = "hello"; |
| 48 | FL_REQUIRE_EQ(*ms.find_value(5), "hello"); |
| 49 | |
| 50 | // operator[] overwrite existing |
| 51 | ms[5] = "world"; |
| 52 | FL_REQUIRE_EQ(ms.size(), 1u); |
| 53 | FL_REQUIRE_EQ(*ms.find_value(5), "world"); |
| 54 | } |
| 55 | |
| 56 | FL_TEST_CASE("Insert duplicate key overwrites without growing") { |
| 57 | fl::unordered_map<int, fl::string> m; |
| 58 | m.insert(1, "foo"); |
| 59 | FL_REQUIRE_EQ(m.size(), 1u); |
| 60 | FL_REQUIRE_EQ(*m.find_value(1), "foo"); |
| 61 | |
| 62 | m.insert(1, "bar"); |
| 63 | FL_REQUIRE_EQ(m.size(), 1u); |
| 64 | FL_REQUIRE_EQ(*m.find_value(1), "bar"); |
| 65 | } |
| 66 | |
| 67 | FL_TEST_CASE("Multiple distinct inserts & lookups") { |
| 68 | fl::unordered_map<char, int> m; |
| 69 | int count = 0; |
| 70 | for (char c = 'a'; c < 'a' + 10; ++c) { |
| 71 | FL_MESSAGE("insert " << count++); |
| 72 | m.insert(c, c - 'a'); |
| 73 | } |
| 74 | FL_REQUIRE_EQ(m.size(), 10u); |
| 75 | for (char c = 'a'; c < 'a' + 10; ++c) { |
| 76 | auto *v = m.find_value(c); |
| 77 | FL_REQUIRE(v); |
| 78 | FL_REQUIRE_EQ(*v, static_cast<int>(c - 'a')); |
| 79 | } |
nothing calls this directly
no test coverage detected