|
@@ -1,9 +1,11 @@
|
|
|
#include "tests/HashMapTests.h"
|
|
|
#include "tests/Test.h"
|
|
|
#include "utils/HashMap.h"
|
|
|
+#include "utils/StringBuffer.h"
|
|
|
|
|
|
constexpr int MAP_MIN_CAPACITY = 5;
|
|
|
typedef HashMap<int, int, MAP_MIN_CAPACITY> IntMap;
|
|
|
+typedef StringBuffer<50> String;
|
|
|
|
|
|
static void testAdd(Test& test) {
|
|
|
IntMap map;
|
|
@@ -95,6 +97,31 @@ static void testEmplace(Test& test) {
|
|
|
test.checkEqual(true, r5, "emplacing returns correct value 5");
|
|
|
}
|
|
|
|
|
|
+static void testToString1(Test& test) {
|
|
|
+ IntMap map;
|
|
|
+ map.add(1, 3);
|
|
|
+ map.add(2, 4);
|
|
|
+ map.add(3, 5);
|
|
|
+ String s;
|
|
|
+ s.append(map);
|
|
|
+ test.checkEqual(String("[1 = 3, 2 = 4, 3 = 5]"), s, "to string 1");
|
|
|
+}
|
|
|
+
|
|
|
+static void testToString2(Test& test) {
|
|
|
+ IntMap map;
|
|
|
+ map.add(1, 3);
|
|
|
+ String s;
|
|
|
+ s.append(map);
|
|
|
+ test.checkEqual(String("[1 = 3]"), s, "to string 2");
|
|
|
+}
|
|
|
+
|
|
|
+static void testToString3(Test& test) {
|
|
|
+ IntMap map;
|
|
|
+ String s;
|
|
|
+ s.append(map);
|
|
|
+ test.checkEqual(String("[]"), s, "to string 3");
|
|
|
+}
|
|
|
+
|
|
|
void HashMapTests::test() {
|
|
|
Test test("HashMap");
|
|
|
testAdd(test);
|
|
@@ -104,5 +131,8 @@ void HashMapTests::test() {
|
|
|
testClear(test);
|
|
|
testOverflow(test);
|
|
|
testEmplace(test);
|
|
|
+ testToString1(test);
|
|
|
+ testToString2(test);
|
|
|
+ testToString3(test);
|
|
|
test.finalize();
|
|
|
}
|