|
@@ -3,7 +3,7 @@
|
|
#include "utils/List.h"
|
|
#include "utils/List.h"
|
|
#include "utils/StringBuffer.h"
|
|
#include "utils/StringBuffer.h"
|
|
|
|
|
|
-typedef List<int, 20> IntList;
|
|
|
|
|
|
+typedef List<int> IntList;
|
|
typedef StringBuffer<50> String;
|
|
typedef StringBuffer<50> String;
|
|
|
|
|
|
static void testAdd(Test& test) {
|
|
static void testAdd(Test& test) {
|
|
@@ -16,9 +16,7 @@ static void testAdd(Test& test) {
|
|
|
|
|
|
static void testMultipleAdd(Test& test) {
|
|
static void testMultipleAdd(Test& test) {
|
|
IntList list;
|
|
IntList list;
|
|
- list.add(4);
|
|
|
|
- list.add(3);
|
|
|
|
- list.add(2);
|
|
|
|
|
|
+ list.add(4).add(3).add(2);
|
|
test.checkEqual(4, list[0], "contains added value 1");
|
|
test.checkEqual(4, list[0], "contains added value 1");
|
|
test.checkEqual(3, list[1], "contains added value 2");
|
|
test.checkEqual(3, list[1], "contains added value 2");
|
|
test.checkEqual(2, list[2], "contains added value 3");
|
|
test.checkEqual(2, list[2], "contains added value 3");
|
|
@@ -34,31 +32,25 @@ static void testAddReplace(Test& test) {
|
|
|
|
|
|
static void testClear(Test& test) {
|
|
static void testClear(Test& test) {
|
|
IntList list;
|
|
IntList list;
|
|
- list.add(5);
|
|
|
|
- list.add(4);
|
|
|
|
|
|
+ list.add(5).add(4);
|
|
list.clear();
|
|
list.clear();
|
|
test.checkEqual(0, list.getLength(), "length is 0 after clear");
|
|
test.checkEqual(0, list.getLength(), "length is 0 after clear");
|
|
}
|
|
}
|
|
|
|
|
|
-static void testOverflow(Test& test) {
|
|
|
|
|
|
+static void testBigAdd(Test& test) {
|
|
IntList list;
|
|
IntList list;
|
|
- for(int i = 0; i < 20; i++) {
|
|
|
|
- test.checkEqual(false, list.add(i), "add returns false without overflow");
|
|
|
|
- }
|
|
|
|
for(int i = 0; i < 1000000; i++) {
|
|
for(int i = 0; i < 1000000; i++) {
|
|
- test.checkEqual(true, list.add(i), "add returns true with overflow");
|
|
|
|
|
|
+ list.add(i);
|
|
}
|
|
}
|
|
for(int i = 0; i < list.getLength(); i++) {
|
|
for(int i = 0; i < list.getLength(); i++) {
|
|
- test.checkEqual(i, list[i], "still contains values after overflow");
|
|
|
|
|
|
+ test.checkEqual(i, list[i], "big add");
|
|
}
|
|
}
|
|
- test.checkEqual(true, true, "survives overflow");
|
|
|
|
|
|
+ test.checkEqual(1000000, list.getLength(), "big add length");
|
|
}
|
|
}
|
|
|
|
|
|
static void testCopy(Test& test) {
|
|
static void testCopy(Test& test) {
|
|
IntList list;
|
|
IntList list;
|
|
- list.add(1);
|
|
|
|
- list.add(2);
|
|
|
|
- list.add(3);
|
|
|
|
|
|
+ list.add(1).add(2).add(3);
|
|
|
|
|
|
IntList copy(list);
|
|
IntList copy(list);
|
|
test.checkEqual(list.getLength(), copy.getLength(), "copy has same length");
|
|
test.checkEqual(list.getLength(), copy.getLength(), "copy has same length");
|
|
@@ -69,13 +61,12 @@ static void testCopy(Test& test) {
|
|
|
|
|
|
static void testCopyAssignment(Test& test) {
|
|
static void testCopyAssignment(Test& test) {
|
|
IntList list;
|
|
IntList list;
|
|
- list.add(1);
|
|
|
|
- list.add(2);
|
|
|
|
- list.add(3);
|
|
|
|
|
|
+ list.add(1).add(2).add(3);
|
|
|
|
|
|
IntList copy;
|
|
IntList copy;
|
|
copy = list;
|
|
copy = list;
|
|
- test.checkEqual(list.getLength(), copy.getLength(), "copy assignment has same length");
|
|
|
|
|
|
+ test.checkEqual(list.getLength(), copy.getLength(),
|
|
|
|
+ "copy assignment has same length");
|
|
for(int i = 0; i < copy.getLength() && i < list.getLength(); i++) {
|
|
for(int i = 0; i < copy.getLength() && i < list.getLength(); i++) {
|
|
test.checkEqual(list[i], copy[i], "copy assignment has same values");
|
|
test.checkEqual(list[i], copy[i], "copy assignment has same values");
|
|
}
|
|
}
|
|
@@ -83,9 +74,7 @@ static void testCopyAssignment(Test& test) {
|
|
|
|
|
|
static void testMove(Test& test) {
|
|
static void testMove(Test& test) {
|
|
IntList list;
|
|
IntList list;
|
|
- list.add(1);
|
|
|
|
- list.add(2);
|
|
|
|
- list.add(3);
|
|
|
|
|
|
+ list.add(1).add(2).add(3);
|
|
|
|
|
|
IntList move(std::move(list));
|
|
IntList move(std::move(list));
|
|
test.checkEqual(0, list.getLength(), "moved has length 0");
|
|
test.checkEqual(0, list.getLength(), "moved has length 0");
|
|
@@ -97,9 +86,7 @@ static void testMove(Test& test) {
|
|
|
|
|
|
static void testMoveAssignment(Test& test) {
|
|
static void testMoveAssignment(Test& test) {
|
|
IntList list;
|
|
IntList list;
|
|
- list.add(1);
|
|
|
|
- list.add(2);
|
|
|
|
- list.add(3);
|
|
|
|
|
|
+ list.add(1).add(2).add(3);
|
|
|
|
|
|
IntList move;
|
|
IntList move;
|
|
move = std::move(list);
|
|
move = std::move(list);
|
|
@@ -112,9 +99,7 @@ static void testMoveAssignment(Test& test) {
|
|
|
|
|
|
static void testToString1(Test& test) {
|
|
static void testToString1(Test& test) {
|
|
IntList list;
|
|
IntList list;
|
|
- list.add(1);
|
|
|
|
- list.add(243);
|
|
|
|
- list.add(-423);
|
|
|
|
|
|
+ list.add(1).add(243).add(-423);
|
|
test.checkEqual(String("[1, 243, -423]"), String(list), "to string 1");
|
|
test.checkEqual(String("[1, 243, -423]"), String(list), "to string 1");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -131,9 +116,7 @@ static void testToString3(Test& test) {
|
|
|
|
|
|
static void testRemove(Test& test) {
|
|
static void testRemove(Test& test) {
|
|
IntList list;
|
|
IntList list;
|
|
- list.add(4);
|
|
|
|
- list.add(3);
|
|
|
|
- list.add(2);
|
|
|
|
|
|
+ list.add(4).add(3).add(2);
|
|
list.remove(0);
|
|
list.remove(0);
|
|
test.checkEqual(2, list[0], "remove 1");
|
|
test.checkEqual(2, list[0], "remove 1");
|
|
test.checkEqual(3, list[1], "remove 2");
|
|
test.checkEqual(3, list[1], "remove 2");
|
|
@@ -145,20 +128,13 @@ static void testRemove(Test& test) {
|
|
test.checkEqual(0, list.getLength(), "remove 6");
|
|
test.checkEqual(0, list.getLength(), "remove 6");
|
|
}
|
|
}
|
|
|
|
|
|
-static void testRemoveIsSafe(Test& test) {
|
|
|
|
- IntList list;
|
|
|
|
- for(int i = -500000; i < 500000; i++) {
|
|
|
|
- test.checkEqual(true, list.remove(i), "removing from empty list is safe");
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
void ListTests::test() {
|
|
void ListTests::test() {
|
|
Test test("List");
|
|
Test test("List");
|
|
testAdd(test);
|
|
testAdd(test);
|
|
testMultipleAdd(test);
|
|
testMultipleAdd(test);
|
|
testAddReplace(test);
|
|
testAddReplace(test);
|
|
testClear(test);
|
|
testClear(test);
|
|
- testOverflow(test);
|
|
|
|
|
|
+ testBigAdd(test);
|
|
testCopy(test);
|
|
testCopy(test);
|
|
testCopyAssignment(test);
|
|
testCopyAssignment(test);
|
|
testMove(test);
|
|
testMove(test);
|
|
@@ -167,6 +143,5 @@ void ListTests::test() {
|
|
testToString2(test);
|
|
testToString2(test);
|
|
testToString3(test);
|
|
testToString3(test);
|
|
testRemove(test);
|
|
testRemove(test);
|
|
- testRemoveIsSafe(test);
|
|
|
|
test.finalize();
|
|
test.finalize();
|
|
}
|
|
}
|