37 lines
691 B
C
37 lines
691 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "stack.h"
|
|
|
|
int main() {
|
|
printf("===== TEST STACK =====\n");
|
|
|
|
StackNode *s = NULL;
|
|
|
|
// Test push
|
|
int a = 10, b = 20, c = 30;
|
|
s = push(s, &a);
|
|
s = push(s, &b);
|
|
s = push(s, &c);
|
|
|
|
if (*(int*)top(s) != 30) {
|
|
printf("FAIL: top() should return 30\n");
|
|
return 1;
|
|
}
|
|
printf("PASS: push + top\n");
|
|
|
|
// Test pop
|
|
s = pop(s);
|
|
if (*(int*)top(s) != 20) {
|
|
printf("FAIL: pop() should remove 30\n");
|
|
return 1;
|
|
}
|
|
printf("PASS: pop\n");
|
|
|
|
// Clear
|
|
clearStack(s);
|
|
printf("PASS: clearStack (no crash)\n");
|
|
|
|
printf("ALL STACK TESTS PASSED\n");
|
|
return 0;
|
|
}
|