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

Information
Class: test_heap_c
Assembly: src.backend.tests.unit
File(s): ./src/backend/tests/unit/test_heap.c
Line coverage
100%
Covered lines: 71
Uncovered lines: 0
Coverable lines: 71
Total lines: 121
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 2/18/2026 - 10:50:55 PM Line coverage: 100% (71/71) Branch coverage: 52.1% (24/46) Total lines: 121 2/18/2026 - 10:50:55 PM Line coverage: 100% (71/71) Branch coverage: 52.1% (24/46) Total lines: 121

File(s)

./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);
 17
 118    Task t1 = {1, 10, 1000};
 119    Task t2 = {2, 50, 1001}; // Highest priority
 120    Task t3 = {3, 30, 1002};
 21
 122    assert(insertHeap(&h, t1) == true);
 123    assert(insertHeap(&h, t2) == true);
 124    assert(insertHeap(&h, t3) == true);
 125    assert(getHeapSize(&h) == 3);
 26
 27    Task out;
 28    // Should get t2 (priority 50)
 129    assert(extractMax(&h, &out) == true);
 130    assert(out.id == 2);
 31
 32    // Should get t3 (priority 30)
 133    assert(extractMax(&h, &out) == true);
 134    assert(out.id == 3);
 35
 36    // Should get t1 (priority 10)
 137    assert(extractMax(&h, &out) == true);
 138    assert(out.id == 1);
 39
 40    // Empty extract
 141    assert(extractMax(&h, &out) == false);
 142    printf("[PASS] test_heap_insert_extract\n");
 143}
 44
 145void test_heap_priority_updates() {
 46    Heap h;
 147    initHeap(&h);
 48
 149    Task t1 = {1, 10, 1000};
 150    Task t2 = {2, 20, 1001};
 151    Task t3 = {3, 30, 1002};
 52
 153    insertHeap(&h, t1);
 154    insertHeap(&h, t2);
 155    insertHeap(&h, t3);
 56
 57    // Root is t3 (30). Update t1 (10) -> 40.
 158    assert(updatePriority(&h, 1, 40) == true);
 59    Task out;
 160    extractMax(&h, &out);
 161    assert(out.id == 1); // t1 moved to top
 62
 63    // Now root is t3 (30). Update t3 (30) -> 5.
 164    assert(updatePriority(&h, 3, 5) == true);
 165    extractMax(&h, &out);
 166    assert(out.id == 2); // t2 (20) moved to top
 67
 68    // Update non-existent
 169    assert(updatePriority(&h, 999, 100) == false);
 70
 171    printf("[PASS] test_heap_priority_updates\n");
 172}
 73
 174void test_heap_tie_breaker() {
 75    Heap h;
 176    initHeap(&h);
 77
 78    // Same priority, t1 is older (smaller timestamp)
 179    Task t1 = {1, 50, 1000};
 180    Task t2 = {2, 50, 2000};
 81
 182    insertHeap(&h, t2);
 183    insertHeap(&h, t1); // Order shouldn't matter for insert
 84
 85    Task out;
 186    extractMax(&h, &out);
 187    assert(out.id == 1); // Older wins tie-break (smaller timestamp)
 88
 189    extractMax(&h, &out);
 190    assert(out.id == 2);
 91
 192    printf("[PASS] test_heap_tie_breaker\n");
 193}
 94
 195void test_heap_edge_cases() {
 96    Heap h;
 197    initHeap(&h);
 98
 99    // Fill heap
 101100    for (int i = 0; i < MAX_HEAP_SIZE; i++) {
 100101        Task t = {i, 10, 1000};
 100102        assert(insertHeap(&h, t) == true);
 103    }
 104
 105    // Try to overflow
 1106    Task over = {999, 99, 999};
 1107    assert(insertHeap(&h, over) == false);
 108
 1109    printf("[PASS] test_heap_edge_cases\n");
 1110}
 111
 1112int main() {
 1113    printf("=== Heap Logic Unit Tests ===\n");
 1114    test_heap_init();
 1115    test_heap_insert_extract();
 1116    test_heap_priority_updates();
 1117    test_heap_tie_breaker();
 1118    test_heap_edge_cases();
 1119    printf("\n✅ All Heap tests passed!\n");
 1120    return 0;
 121}

Methods/Properties