| | | 1 | | #include <stdio.h> |
| | | 2 | | #include <assert.h> |
| | | 3 | | #include "../../core/data_structures/stack.h" |
| | | 4 | | |
| | 1 | 5 | | void test_stack_init() { |
| | | 6 | | Stack s; |
| | 1 | 7 | | initStack(&s); |
| | 1 | 8 | | assert(s.top == 0); |
| | 1 | 9 | | assert(s.count == 0); |
| | 1 | 10 | | printf("Stack Init Test Passed\n"); |
| | 1 | 11 | | } |
| | | 12 | | |
| | 1 | 13 | | void test_stack_push_pop() { |
| | | 14 | | Stack s; |
| | 1 | 15 | | initStack(&s); |
| | 1 | 16 | | Operation op1 = {1, 101, OP_FAULT_ENTRY, 0.0, "2025-01-01"}; |
| | 1 | 17 | | Operation op2 = {2, 102, OP_PART_REPLACEMENT, 1.0, "2025-01-02"}; |
| | 1 | 18 | | push(&s, op1); |
| | 1 | 19 | | assert(getUndoCount(&s) == 1); |
| | 1 | 20 | | push(&s, op2); |
| | 1 | 21 | | assert(getUndoCount(&s) == 2); |
| | | 22 | | Operation out; |
| | 1 | 23 | | assert(pop(&s, &out) == true); |
| | 1 | 24 | | assert(out.operation_id == 2); |
| | 1 | 25 | | assert(getUndoCount(&s) == 1); |
| | 1 | 26 | | assert(pop(&s, &out) == true); |
| | 1 | 27 | | assert(out.operation_id == 1); |
| | 1 | 28 | | assert(getUndoCount(&s) == 0); |
| | 1 | 29 | | assert(pop(&s, &out) == false); |
| | 1 | 30 | | printf("Stack Push/Pop Test Passed\n"); |
| | 1 | 31 | | } |
| | | 32 | | |
| | 1 | 33 | | void run_stack_tests() { |
| | 1 | 34 | | printf("Running Stack Tests...\n"); |
| | 1 | 35 | | test_stack_init(); |
| | 1 | 36 | | test_stack_push_pop(); |
| | 1 | 37 | | printf("All Stack Tests Passed!\n"); |
| | 1 | 38 | | } |
| | | 39 | | |
| | 1 | 40 | | int main() { |
| | 1 | 41 | | run_stack_tests(); |
| | 1 | 42 | | return 0; |
| | | 43 | | } |