< Summary - Backend C Tests - Coverage Report (WSL)

Information
Class: bst_c
Assembly: src.backend.core.data_structures
File(s): ./src/backend/core/data_structures/bst.c
Line coverage
76%
Covered lines: 49
Uncovered lines: 15
Coverable lines: 64
Total lines: 113
Line coverage: 76.5%
Branch coverage
83%
Covered branches: 20
Total branches: 24
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 2/18/2026 - 10:50:55 PM Line coverage: 76.5% (49/64) Branch coverage: 83.3% (20/24) Total lines: 113 2/18/2026 - 10:50:55 PM Line coverage: 76.5% (49/64) Branch coverage: 83.3% (20/24) Total lines: 113

File(s)

./src/backend/core/data_structures/bst.c

#LineLine coverage
 1/* This file is a template for bst.c. Content will be filled by yagiz on 2025-12-29. */
 2#include <stdio.h>
 3#include <stdlib.h>
 4#include <string.h>
 5#include "bst.h"
 6
 27void initBST(BST *tree) {
 28  tree->root = NULL;
 29  tree->count = 0;
 210}
 11
 12// Helper: Create a new node
 313static BSTNode *createNode(Machine machine) {
 314  BSTNode *newNode = (BSTNode *)malloc(sizeof(BSTNode));
 15
 316  if (newNode == NULL) {
 017    printf("CRITICAL ERROR: Memory allocation failed!\n");
 018    return NULL;
 19  }
 20
 321  newNode->data = machine;
 322  newNode->left = NULL;
 323  newNode->right = NULL;
 324  return newNode;
 25}
 26
 27// Helper: Recursive Insert
 628static bool insertRecursive(BSTNode **node, Machine machine) {
 29  // 1. Base Case: Found empty spot
 630  if (*node == NULL) {
 331    *node = createNode(machine);
 332    return true;
 33  }
 34
 35  // 2. Recursive Step
 336  if (machine.machine_id < (*node)->data.machine_id) {
 137    return insertRecursive(&(*node)->left, machine);
 238  } else if (machine.machine_id > (*node)->data.machine_id) {
 139    return insertRecursive(&(*node)->right, machine);
 40  } else {
 41    // 3. Duplicate Case
 142    printf("ERROR: Machine ID %d already exists! duplicate rejected.\n", machine.machine_id);
 143    return false;
 44  }
 45}
 46
 447bool insertMachine(BST *tree, Machine machine) {
 448  bool success = insertRecursive(&tree->root, machine);
 49
 450  if (success) {
 351    tree->count++;
 352    printf("Inventory Added: %s (ID: %d)\n", machine.name, machine.machine_id);
 53  }
 54
 455  return success;
 56}
 57
 58// Helper: Recursive Search
 559static Machine *searchRecursive(BSTNode *node, int id) {
 60  // Base Case: Empty or Found
 561  if (node == NULL || node->data.machine_id == id) {
 262    return (node == NULL) ? NULL : &node->data;
 63  }
 64
 65  // Navigation
 366  if (id < node->data.machine_id) {
 067    return searchRecursive(node->left, id);
 68  } else {
 369    return searchRecursive(node->right, id);
 70  }
 71}
 72
 273Machine *searchMachine(BST *tree, int machine_id) {
 274  Machine *result = searchRecursive(tree->root, machine_id);
 75
 276  if (result) {
 177    printf("FOUND: %s in %s\n", result->name, result->location);
 78  } else {
 179    printf("NOT FOUND: Machine ID %d\n", machine_id);
 80  }
 81
 282  return result;
 83}
 84
 85// Helper: In-Order Traversal (L-N-R)
 086static void printRecursive(BSTNode *node) {
 087  if (node != NULL) {
 088    printRecursive(node->left);
 089    printf("[%d] %-20s | Location: %s\n",
 090           node->data.machine_id, node->data.name, node->data.location);
 091    printRecursive(node->right);
 92  }
 093}
 94
 095void printInventory(BST *tree) {
 096  printf("\n--- FACTORY INVENTORY (Sorted by ID) ---\n");
 097  printRecursive(tree->root);
 098  printf("----------------------------------------\n");
 099}
 100
 7101static void destroyRecursive(BSTNode *node) {
 7102  if (node != NULL) {
 3103    destroyRecursive(node->left);
 3104    destroyRecursive(node->right);
 3105    free(node);
 106  }
 7107}
 108
 1109void destroyBST(BST *tree) {
 1110  destroyRecursive(tree->root);
 1111  tree->root = NULL;
 1112  tree->count = 0;
 1113}

Methods/Properties