Tuesday, March 30, 2010

Suites for the suite

I took a little detour, tonight, from my list of tasks to tidy up a little.

I wrote some test code to verify that the push and pop are working pretty much as I expect. Here's the output:

Test 01: .....PASSED
Test 02: .....PASSED
Test 03: .....PASSED
Test 04: .....PASSED
Test 05: .....PASSED


Which doesn't mean anything unless you know what the tests are.

Test 01 verifies basic operation. It pushed 14 and pops once and verifies that the result is 14:

printf("Test 01: ");
TESTPUSH
temp = 14;
push(temp);
TESTPOP
if (pop() != temp) goto EXCEPTION;
printf(".....PASSED\n");


TESTPUSH, TESTPOP, and the if statement can each break it with the same result:

Test 01: Error: Exiting.

Test 02 pushes and pops 100 values:

printf("Test 02: ");
for (i = 0; i (less than) stackSize; i++)
{
TESTPUSH
push(i);
}

for (; i (greater than) 0; i--)
{
TESTPOP
temp = pop();

}
printf(".....PASSED\n");

Test 03 verifies that the same value is pushed as popped. This is a little more specific than Test 02, which just cares about staying inside the stack range.

Test 04 and 05 just check whether the logic of the testing code works. These might be better at the start of the test section, but I'm not moving things around right now.

// TEST 4: Verifies the test code for pops by negating it.
printf("Test 04: ");
if (current != base) goto EXCEPTION;
printf(".....PASSED\n");

// TEST 5: Verifies the test code for pushes by negating it.

printf("Test 05: ");
for (i = 0; i (less than) stackSize; i++)
{
TESTPUSH;
push(i);
}
if (current != (base+stackSize)) goto EXCEPTION;
printf(".....PASSED\n");


Next, resizing the stack with realloc.

No comments:

Post a Comment