< Summary - Backend C Tests - Coverage Report

Information
Class: test_heap_c
Assembly: src.backend.tests.unit
File(s): C:\Users\yagiz\Desktop\Project\smart-maintenance-suite\src\backend\tests\unit\test_heap.c
Line coverage
100%
Covered lines: 71
Uncovered lines: 0
Coverable lines: 71
Total lines: 103
Line coverage: 100%
Branch coverage
52%
Covered branches: 24
Total branches: 46
Branch coverage: 52.1%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
test_heap_init50%00100%
test_heap_insert_extract50%00100%
test_heap_priority_updates50%00100%
test_heap_tie_breaker50%00100%
test_heap_edge_cases66.67%00100%
main100%00100%

File(s)

C:\Users\yagiz\Desktop\Project\smart-maintenance-suite\src\backend\tests\unit\test_heap.c

#LineLine coverage
 1#include <stdio.h>
 2#include <assert.h>
 3#include <stdbool.h>
 4#include "../../core/data_structures/heap.h"
 5
 16void test_heap_init() {
 7  Heap h;
 18  initHeap(&h);
 19  assert(h.count == 0);
 110  assert(getHeapSize(&h) == 0);
 111  printf("[PASS] test_heap_init\n");
 112}
 13
 114void test_heap_insert_extract() {
 15  Heap h;
 116  initHeap(&h);
 117  Task t1 = {1, 10, 1000};
 118  Task t2 = {2, 50, 1001}; // Highest priority
 119  Task t3 = {3, 30, 1002};
 120  assert(insertHeap(&h, t1) == true);
 121  assert(insertHeap(&h, t2) == true);
 122  assert(insertHeap(&h, t3) == true);
 123  assert(getHeapSize(&h) == 3);
 24  Task out;
 25  // Should get t2 (priority 50)
 126  assert(extractMax(&h, &out) == true);
 127  assert(out.id == 2);
 28  // Should get t3 (priority 30)
 129  assert(extractMax(&h, &out) == true);
 130  assert(out.id == 3);
 31  // Should get t1 (priority 10)
 132  assert(extractMax(&h, &out) == true);
 133  assert(out.id == 1);
 34  // Empty extract
 135  assert(extractMax(&h, &out) == false);
 136  printf("[PASS] test_heap_insert_extract\n");
 137}
 38
 139void test_heap_priority_updates() {
 40  Heap h;
 141  initHeap(&h);
 142  Task t1 = {1, 10, 1000};
 143  Task t2 = {2, 20, 1001};
 144  Task t3 = {3, 30, 1002};
 145  insertHeap(&h, t1);
 146  insertHeap(&h, t2);
 147  insertHeap(&h, t3);
 48  // Root is t3 (30). Update t1 (10) -> 40.
 149  assert(updatePriority(&h, 1, 40) == true);
 50  Task out;
 151  extractMax(&h, &out);
 152  assert(out.id == 1); // t1 moved to top
 53  // Now root is t3 (30). Update t3 (30) -> 5.
 154  assert(updatePriority(&h, 3, 5) == true);
 155  extractMax(&h, &out);
 156  assert(out.id == 2); // t2 (20) moved to top
 57  // Update non-existent
 158  assert(updatePriority(&h, 999, 100) == false);
 159  printf("[PASS] test_heap_priority_updates\n");
 160}
 61
 162void test_heap_tie_breaker() {
 63  Heap h;
 164  initHeap(&h);
 65  // Same priority, t1 is older (smaller timestamp)
 166  Task t1 = {1, 50, 1000};
 167  Task t2 = {2, 50, 2000};
 168  insertHeap(&h, t2);
 169  insertHeap(&h, t1); // Order shouldn't matter for insert
 70  Task out;
 171  extractMax(&h, &out);
 172  assert(out.id == 1); // Older wins tie-break (smaller timestamp)
 173  extractMax(&h, &out);
 174  assert(out.id == 2);
 175  printf("[PASS] test_heap_tie_breaker\n");
 176}
 77
 178void test_heap_edge_cases() {
 79  Heap h;
 180  initHeap(&h);
 81
 82  // Fill heap
 10183  for (int i = 0; i < MAX_HEAP_SIZE; i++) {
 10084    Task t = {i, 10, 1000};
 10085    assert(insertHeap(&h, t) == true);
 86  }
 87
 88  // Try to overflow
 189  Task over = {999, 99, 999};
 190  assert(insertHeap(&h, over) == false);
 191  printf("[PASS] test_heap_edge_cases\n");
 192}
 93
 194int main() {
 195  printf("=== Heap Logic Unit Tests ===\n");
 196  test_heap_init();
 197  test_heap_insert_extract();
 198  test_heap_priority_updates();
 199  test_heap_tie_breaker();
 1100  test_heap_edge_cases();
 1101  printf("\n✅ All Heap tests passed!\n");
 1102  return 0;
 103}