瀏覽代碼

test for list remove and stringbuffer unicode append

Kajetan Johannes Hammerle 3 年之前
父節點
當前提交
5d05233981
共有 2 個文件被更改,包括 39 次插入6 次删除
  1. 21 6
      tests/ListTests.cpp
  2. 18 0
      tests/StringBufferTests.cpp

+ 21 - 6
tests/ListTests.cpp

@@ -114,17 +114,31 @@ static void testToString3(Test& test) {
     test.checkEqual(String("[]"), String(list), "to string 3");
 }
 
-static void testRemove(Test& test) {
+static void testRemoveBySwap(Test& test) {
     IntList list;
     list.add(4).add(3).add(2);
     list.removeBySwap(0);
-    test.checkEqual(2, list[0], "remove 1");
-    test.checkEqual(3, list[1], "remove 2");
-    test.checkEqual(2, list.getLength(), "remove 3");
+    test.checkEqual(2, list[0], "remove by swap 1");
+    test.checkEqual(3, list[1], "remove by swap 2");
+    test.checkEqual(2, list.getLength(), "remove by swap 3");
     list.removeBySwap(1);
-    test.checkEqual(2, list[0], "remove 4");
-    test.checkEqual(1, list.getLength(), "remove 5");
+    test.checkEqual(2, list[0], "remove by swap 4");
+    test.checkEqual(1, list.getLength(), "remove by swap 5");
     list.removeBySwap(0);
+    test.checkEqual(0, list.getLength(), "remove by swap 6");
+}
+
+static void testRemove(Test& test) {
+    IntList list;
+    list.add(4).add(3).add(2);
+    list.remove(0);
+    test.checkEqual(3, list[0], "remove 1");
+    test.checkEqual(2, list[1], "remove 2");
+    test.checkEqual(2, list.getLength(), "remove 3");
+    list.remove(1);
+    test.checkEqual(3, list[0], "remove 4");
+    test.checkEqual(1, list.getLength(), "remove 5");
+    list.remove(0);
     test.checkEqual(0, list.getLength(), "remove 6");
 }
 
@@ -142,6 +156,7 @@ void ListTests::test() {
     testToString1(test);
     testToString2(test);
     testToString3(test);
+    testRemoveBySwap(test);
     testRemove(test);
     test.finalize();
 }

+ 18 - 0
tests/StringBufferTests.cpp

@@ -62,6 +62,12 @@ static void testInt(Test& test) {
     test.checkEqual(String("test524-37"), s, "int append");
 }
 
+static void testUnsignedInt(Test& test) {
+    String s("test");
+    s.append(524u).append(4294967295u);
+    test.checkEqual(String("test5244294967295"), s, "unsigned int append");
+}
+
 static void testOverflowConstructor(Test& test) {
     StringBuffer<5> s("12345678");
     test.checkEqual(StringBuffer<5>("1234"), s, "overflow constructor");
@@ -87,6 +93,16 @@ static void testBool(Test& test) {
     test.checkEqual(String("testtruefalsetrue"), s, "bool append");
 }
 
+static void testUnicode(Test& test) {
+    String s("");
+    s.appendUnicode('\u0040')
+        .appendUnicode(L'\u0400')
+        .appendUnicode(L'\u8000')
+        .appendUnicode(L'\U00100000');
+    test.checkEqual(String("\u0040\u0400\u8000\U00100000"), s,
+                    "unicode append");
+}
+
 static void testClear(Test& test) {
     String s("test");
     s.append(1234).clear().append("wusi").append("1234");
@@ -144,10 +160,12 @@ void StringBufferTests::test() {
     testCharacters(test);
     testLength(test);
     testInt(test);
+    testUnsignedInt(test);
     testOverflowConstructor(test);
     testIntOverflow(test);
     testFloat(test);
     testBool(test);
+    testUnicode(test);
     testClear(test);
     testAppendChar(test);
     testHashCode(test);