MCPcopy Create free account
hub / github.com/FastLED/FastLED / FL_TEST_FILE

Function FL_TEST_FILE

tests/fl/stl/unordered_map.cpp:22–1687  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20#include "fl/stl/int.h"
21
22FL_TEST_FILE(FL_FILEPATH) {
23
24using namespace fl;
25
26FL_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
34FL_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
56FL_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
67FL_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 }

Callers

nothing calls this directly

Calls 15

find_valueMethod · 0.80
key_eqMethod · 0.80
insert_or_assignMethod · 0.80
try_emplaceMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
insertMethod · 0.45
emptyMethod · 0.45
eraseMethod · 0.45
removeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected