|
@@ -10,30 +10,30 @@ static void testAdd(Test& test) {
|
|
IntList list;
|
|
IntList list;
|
|
list.add(5);
|
|
list.add(5);
|
|
|
|
|
|
- test.checkEqual(5, list[0], "list contains added value");
|
|
|
|
- test.checkEqual(1, list.getLength(), "list sizes is increased by add");
|
|
|
|
|
|
+ test.checkEqual(5, list[0], "contains added value");
|
|
|
|
+ test.checkEqual(1, list.getLength(), "sizes is increased by add");
|
|
}
|
|
}
|
|
|
|
|
|
static void testMultipleAdd(Test& test) {
|
|
static void testMultipleAdd(Test& test) {
|
|
IntList list;
|
|
IntList list;
|
|
list.add(4).add(3).add(2);
|
|
list.add(4).add(3).add(2);
|
|
- test.checkEqual(4, list[0], "list contains added value");
|
|
|
|
- test.checkEqual(3, list[1], "list contains added value");
|
|
|
|
- test.checkEqual(2, list[2], "list contains added value");
|
|
|
|
- test.checkEqual(3, list.getLength(), "list sizes is increased by add");
|
|
|
|
|
|
+ test.checkEqual(4, list[0], "contains added value");
|
|
|
|
+ test.checkEqual(3, list[1], "contains added value");
|
|
|
|
+ test.checkEqual(2, list[2], "contains added value");
|
|
|
|
+ test.checkEqual(3, list.getLength(), "sizes is increased by add");
|
|
}
|
|
}
|
|
|
|
|
|
static void testAddReplace(Test& test) {
|
|
static void testAddReplace(Test& test) {
|
|
IntList list;
|
|
IntList list;
|
|
list.add(5);
|
|
list.add(5);
|
|
list[0] = 3;
|
|
list[0] = 3;
|
|
- test.checkEqual(3, list[0], "list value is overwritten");
|
|
|
|
|
|
+ test.checkEqual(3, list[0], "value is overwritten");
|
|
}
|
|
}
|
|
|
|
|
|
static void testClear(Test& test) {
|
|
static void testClear(Test& test) {
|
|
IntList list;
|
|
IntList list;
|
|
list.add(5).add(4).clear();
|
|
list.add(5).add(4).clear();
|
|
- test.checkEqual(0, list.getLength(), "list length is 0 after clear");
|
|
|
|
|
|
+ test.checkEqual(0, list.getLength(), "length is 0 after clear");
|
|
}
|
|
}
|
|
|
|
|
|
static void testOverflow(Test& test) {
|
|
static void testOverflow(Test& test) {
|
|
@@ -42,9 +42,9 @@ static void testOverflow(Test& test) {
|
|
list.add(i);
|
|
list.add(i);
|
|
}
|
|
}
|
|
for(int i = 0; i < list.getLength(); i++) {
|
|
for(int i = 0; i < list.getLength(); i++) {
|
|
- test.checkEqual(i, list[i], "list still contains values after overflow");
|
|
|
|
|
|
+ test.checkEqual(i, list[i], "still contains values after overflow");
|
|
}
|
|
}
|
|
- test.checkEqual(true, true, "list survives overflow");
|
|
|
|
|
|
+ test.checkEqual(true, true, "survives overflow");
|
|
}
|
|
}
|
|
|
|
|
|
static void testCopy(Test& test) {
|
|
static void testCopy(Test& test) {
|
|
@@ -52,9 +52,9 @@ static void testCopy(Test& test) {
|
|
list.add(1).add(2).add(3);
|
|
list.add(1).add(2).add(3);
|
|
|
|
|
|
IntList copy(list);
|
|
IntList copy(list);
|
|
- test.checkEqual(list.getLength(), copy.getLength(), "list copy has same length");
|
|
|
|
|
|
+ test.checkEqual(list.getLength(), copy.getLength(), "copy 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], "list copy has same values");
|
|
|
|
|
|
+ test.checkEqual(list[i], copy[i], "copy has same values");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -64,9 +64,9 @@ static void testCopyAssignment(Test& test) {
|
|
|
|
|
|
IntList copy;
|
|
IntList copy;
|
|
copy = list;
|
|
copy = list;
|
|
- test.checkEqual(list.getLength(), copy.getLength(), "list 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], "list copy assignment has same values");
|
|
|
|
|
|
+ test.checkEqual(list[i], copy[i], "copy assignment has same values");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -75,11 +75,11 @@ static void testMove(Test& test) {
|
|
list.add(1).add(2).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 list has length 0");
|
|
|
|
- test.checkEqual(3, move.getLength(), "moved list passes length");
|
|
|
|
- test.checkEqual(1, move[0], "moved list passes values");
|
|
|
|
- test.checkEqual(2, move[1], "moved list passes values");
|
|
|
|
- test.checkEqual(3, move[2], "moved list passes values");
|
|
|
|
|
|
+ test.checkEqual(0, list.getLength(), "moved has length 0");
|
|
|
|
+ test.checkEqual(3, move.getLength(), "moved passes length");
|
|
|
|
+ test.checkEqual(1, move[0], "moved passes values");
|
|
|
|
+ test.checkEqual(2, move[1], "moved passes values");
|
|
|
|
+ test.checkEqual(3, move[2], "moved passes values");
|
|
}
|
|
}
|
|
|
|
|
|
static void testMoveAssignment(Test& test) {
|
|
static void testMoveAssignment(Test& test) {
|
|
@@ -88,28 +88,42 @@ static void testMoveAssignment(Test& test) {
|
|
|
|
|
|
IntList move;
|
|
IntList move;
|
|
move = std::move(list);
|
|
move = std::move(list);
|
|
- test.checkEqual(0, list.getLength(), "assignment moved list has length 0");
|
|
|
|
- test.checkEqual(3, move.getLength(), "assignment moved list passes length");
|
|
|
|
- test.checkEqual(1, move[0], "assignment moved list passes values");
|
|
|
|
- test.checkEqual(2, move[1], "assignment moved list passes values");
|
|
|
|
- test.checkEqual(3, move[2], "assignment moved list passes values");
|
|
|
|
|
|
+ test.checkEqual(0, list.getLength(), "assignment moved has length 0");
|
|
|
|
+ test.checkEqual(3, move.getLength(), "assignment moved passes length");
|
|
|
|
+ test.checkEqual(1, move[0], "assignment moved passes values");
|
|
|
|
+ test.checkEqual(2, move[1], "assignment moved passes values");
|
|
|
|
+ test.checkEqual(3, move[2], "assignment moved passes values");
|
|
}
|
|
}
|
|
|
|
|
|
static void testToString1(Test& test) {
|
|
static void testToString1(Test& test) {
|
|
IntList list;
|
|
IntList list;
|
|
list.add(1).add(243).add(-423);
|
|
list.add(1).add(243).add(-423);
|
|
- test.checkEqual(String("[1, 243, -423]"), String(list), "list to string 1");
|
|
|
|
|
|
+ test.checkEqual(String("[1, 243, -423]"), String(list), "to string 1");
|
|
}
|
|
}
|
|
|
|
|
|
static void testToString2(Test& test) {
|
|
static void testToString2(Test& test) {
|
|
IntList list;
|
|
IntList list;
|
|
list.add(1);
|
|
list.add(1);
|
|
- test.checkEqual(String("[1]"), String(list), "list to string 2");
|
|
|
|
|
|
+ test.checkEqual(String("[1]"), String(list), "to string 2");
|
|
}
|
|
}
|
|
|
|
|
|
static void testToString3(Test& test) {
|
|
static void testToString3(Test& test) {
|
|
IntList list;
|
|
IntList list;
|
|
- test.checkEqual(String("[]"), String(list), "list to string 3");
|
|
|
|
|
|
+ test.checkEqual(String("[]"), String(list), "to string 3");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void testRemove(Test& test) {
|
|
|
|
+ IntList list;
|
|
|
|
+ list.add(4).add(3).add(2);
|
|
|
|
+ list.remove(0);
|
|
|
|
+ test.checkEqual(2, list[0], "remove 1");
|
|
|
|
+ test.checkEqual(3, list[1], "remove 2");
|
|
|
|
+ test.checkEqual(2, list.getLength(), "remove 3");
|
|
|
|
+ list.remove(1);
|
|
|
|
+ test.checkEqual(2, list[0], "remove 4");
|
|
|
|
+ test.checkEqual(1, list.getLength(), "remove 5");
|
|
|
|
+ list.remove(0);
|
|
|
|
+ test.checkEqual(0, list.getLength(), "remove 6");
|
|
}
|
|
}
|
|
|
|
|
|
void ListTests::test() {
|
|
void ListTests::test() {
|
|
@@ -126,5 +140,6 @@ void ListTests::test() {
|
|
testToString1(test);
|
|
testToString1(test);
|
|
testToString2(test);
|
|
testToString2(test);
|
|
testToString3(test);
|
|
testToString3(test);
|
|
|
|
+ testRemove(test);
|
|
test.finalize();
|
|
test.finalize();
|
|
}
|
|
}
|