| | | 1 | | #include <stdio.h> |
| | | 2 | | #include <string.h> |
| | | 3 | | #include <assert.h> |
| | | 4 | | #include "../../core/data_structures/bst.h" |
| | | 5 | | |
| | 1 | 6 | | void test_bst_init() { |
| | | 7 | | BST tree; |
| | 1 | 8 | | initBST(&tree); |
| | 1 | 9 | | assert(tree.root == NULL); |
| | 1 | 10 | | assert(tree.count == 0); |
| | 1 | 11 | | printf("BST Init Test Passed\n"); |
| | 1 | 12 | | } |
| | | 13 | | |
| | 1 | 14 | | void test_bst_insert_search() { |
| | | 15 | | BST tree; |
| | 1 | 16 | | initBST(&tree); |
| | 1 | 17 | | Machine m1 = {101, "M1", "L1", "2025-01-01", 30}; |
| | 1 | 18 | | Machine m2 = {100, "M2", "L2", "2025-01-02", 30}; |
| | 1 | 19 | | Machine m3 = {102, "M3", "L3", "2025-01-03", 30}; |
| | 1 | 20 | | assert(insertMachine(&tree, m1) == true); |
| | 1 | 21 | | assert(tree.count == 1); |
| | 1 | 22 | | assert(insertMachine(&tree, m2) == true); |
| | 1 | 23 | | assert(tree.count == 2); |
| | 1 | 24 | | assert(insertMachine(&tree, m3) == true); |
| | 1 | 25 | | assert(tree.count == 3); |
| | | 26 | | // Duplicate ID should fail |
| | 1 | 27 | | assert(insertMachine(&tree, m1) == false); |
| | 1 | 28 | | assert(tree.count == 3); |
| | 1 | 29 | | Machine *res = searchMachine(&tree, 102); |
| | 1 | 30 | | assert(res != NULL); |
| | 1 | 31 | | assert(strcmp(res->name, "M3") == 0); |
| | 1 | 32 | | res = searchMachine(&tree, 999); |
| | 1 | 33 | | assert(res == NULL); |
| | 1 | 34 | | destroyBST(&tree); |
| | 1 | 35 | | printf("BST Insert/Search Test Passed\n"); |
| | 1 | 36 | | } |
| | | 37 | | |
| | 1 | 38 | | void run_bst_tests() { |
| | 1 | 39 | | printf("Running BST Tests...\n"); |
| | 1 | 40 | | test_bst_init(); |
| | 1 | 41 | | test_bst_insert_search(); |
| | 1 | 42 | | printf("All BST Tests Passed!\n"); |
| | 1 | 43 | | } |
| | | 44 | | |
| | 1 | 45 | | int main() { |
| | 1 | 46 | | run_bst_tests(); |
| | 1 | 47 | | return 0; |
| | | 48 | | } |