123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #include "tests/HeapArrayTests.h"
- #include "tests/Test.h"
- #include "utils/HeapArray.h"
- #include "utils/StringBuffer.h"
- typedef StringBuffer<50> String;
- static void testToString1(Test& test) {
- HeapArray<int> a(3);
- a[0] = 1;
- a[1] = 243;
- a[2] = -423;
- test.checkEqual(String("[1, 243, -423]"), String(a), "to string 1");
- }
- static void testToString2(Test& test) {
- HeapArray<int> a(1);
- a[0] = 1;
- test.checkEqual(String("[1]"), String(a), "to string 2");
- }
- static void testGrow(Test& test) {
- HeapArray<int> a(3);
- a[0] = 1;
- a[1] = 2;
- a[2] = 3;
- a.grow(2, 20);
- test.checkEqual(5, a.getLength(), "resize length");
- test.checkEqual(1, a[0], "resize copy 1");
- test.checkEqual(2, a[1], "resize copy 2");
- test.checkEqual(3, a[2], "resize copy 3");
- test.checkEqual(20, a[3], "resize copy 4");
- test.checkEqual(20, a[4], "resize copy 5");
- }
- void HeapArrayTests::test() {
- Test test("HeapArray");
- testToString1(test);
- testToString2(test);
- testGrow(test);
- test.finalize();
- }
|