| 52 | } |
| 53 | |
| 54 | void execute() override |
| 55 | { |
| 56 | TEST_CASE("HashMap<String, String>") |
| 57 | { |
| 58 | auto startMem = MallocCount::getCurrent(); |
| 59 | |
| 60 | HashMap<String, String> map; |
| 61 | map["a"] = "value(a)"; |
| 62 | map["b"] = "value(b)"; |
| 63 | map["c"] = "value(c)"; |
| 64 | map["d"] = "value(d)"; |
| 65 | |
| 66 | Serial << "Heap " << MallocCount::getCurrent() - startMem << endl; |
| 67 | |
| 68 | print(map); |
| 69 | |
| 70 | for(auto e : map) { |
| 71 | REQUIRE(e->startsWith("value")); |
| 72 | } |
| 73 | |
| 74 | for(auto e : map) { |
| 75 | *e += ": gobbed"; |
| 76 | } |
| 77 | for(auto e : map) { |
| 78 | REQUIRE(e->endsWith("gobbed")); |
| 79 | } |
| 80 | |
| 81 | REQUIRE_EQ(map["b"], "value(b): gobbed"); |
| 82 | |
| 83 | print(map); |
| 84 | } |
| 85 | |
| 86 | TEST_CASE("HashMap<MimeType, size_t>") |
| 87 | { |
| 88 | using TestMap = HashMap<MimeType, uint16_t>; |
| 89 | TestMap map; |
| 90 | fillMap(map); |
| 91 | print(map); |
| 92 | |
| 93 | Serial.println(); |
| 94 | |
| 95 | using Func = Delegate<void(TestMap & map)>; |
| 96 | auto time = [](const String& description, const Func& function) { |
| 97 | Serial << description << " ..." << endl; |
| 98 | TestMap map; |
| 99 | fillMap(map); |
| 100 | CpuCycleTimer timer; |
| 101 | function(map); |
| 102 | auto elapsed = timer.elapsedTime(); |
| 103 | print(map); |
| 104 | Serial << "... took " << elapsed.toString() << endl << endl; |
| 105 | }; |
| 106 | |
| 107 | time("sort by key String", [](auto& map) { |
| 108 | map.sort([](const auto& e1, const auto& e2) { return toString(e1.key()) < toString(e2.key()); }); |
| 109 | }); |
| 110 | |
| 111 | time("Sort by key numerically", |
nothing calls this directly
no test coverage detected