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

Information
Class: graph_c
Assembly: src.backend.core.data_structures
File(s): ./src/backend/core/data_structures/graph.c
Line coverage
65%
Covered lines: 36
Uncovered lines: 19
Coverable lines: 55
Total lines: 105
Line coverage: 65.4%
Branch coverage
50%
Covered branches: 16
Total branches: 32
Branch coverage: 50%
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: 65.4% (36/55) Branch coverage: 50% (16/32) Total lines: 105 2/18/2026 - 10:50:55 PM Line coverage: 65.4% (36/55) Branch coverage: 50% (16/32) Total lines: 105

File(s)

./src/backend/core/data_structures/graph.c

#LineLine coverage
 1/* This file is a template for graph.c. Content will be filled by yagiz on 2025-12-29. */
 2#include <stdio.h>
 3#include "graph.h"
 4
 25void initGraph(Graph *g) {
 26  g->count = 0;
 7
 8  // Initialize Matrix with 0s
 2029  for(int i = 0; i < MAX_MACHINES; i++) {
 20010    g->machineIds[i] = 0;
 11
 2020012    for(int j = 0; j < MAX_MACHINES; j++) {
 2000013      g->adjMatrix[i][j] = 0;
 14    }
 15  }
 216}
 17
 18// Helper to find internal index from Machine ID
 1319static int getIndex(Graph *g, int machine_id) {
 2120  for(int i = 0; i < g->count; i++) {
 1821    if(g->machineIds[i] == machine_id) {
 1022      return i;
 23    }
 24  }
 25
 326  return -1;
 27}
 28
 329bool addMachineNode(Graph *g, int machine_id) {
 330  if(g->count >= MAX_MACHINES) {
 031    printf("ERROR: Graph is full! Cannot add Machine %d\n", machine_id);
 032    return false;
 33  }
 34
 35  // Check duplicate
 336  if(getIndex(g, machine_id) != -1) {
 37    // Already exists
 038    return false;
 39  }
 40
 341  g->machineIds[g->count] = machine_id;
 342  g->count++;
 343  return true;
 44}
 45
 146bool addDependency(Graph *g, int from_id, int to_id) {
 147  int u = getIndex(g, from_id);
 148  int v = getIndex(g, to_id);
 49
 150  if(u == -1 || v == -1) {
 051    printf("ERROR: Machine IDs not found in graph.\n");
 052    return false;
 53  }
 54
 55  // Directed Edge: u depends on v
 156  g->adjMatrix[u][v] = 1;
 57  // If user wants bidirectional (mutual), they call this function twice reversed.
 58  // Or we could enable this logic here if explicitly requested.
 159  printf("Dependency Added: Machine %d -> Depends on -> Machine %d\n", from_id, to_id);
 160  return true;
 61}
 62
 163bool removeDependency(Graph *g, int from_id, int to_id) {
 164  int u = getIndex(g, from_id);
 165  int v = getIndex(g, to_id);
 66
 167  if(u == -1 || v == -1) {
 068    return false;
 69  }
 70
 171  g->adjMatrix[u][v] = 0;
 172  return true;
 73}
 74
 375bool hasDependency(Graph *g, int from_id, int to_id) {
 376  int u = getIndex(g, from_id);
 377  int v = getIndex(g, to_id);
 78
 379  if(u == -1 || v == -1) return false;
 80
 381  return (g->adjMatrix[u][v] == 1);
 82}
 83
 084void printDependencies(Graph *g, int machine_id) {
 085  int u = getIndex(g, machine_id);
 86
 087  if(u == -1) {
 088    printf("Machine %d not found.\n", machine_id);
 089    return;
 90  }
 91
 092  printf("Machine %d depends on:\n", machine_id);
 093  bool found = false;
 94
 095  for(int v = 0; v < g->count; v++) {
 096    if(g->adjMatrix[u][v] == 1) {
 097      printf(" - Machine %d\n", g->machineIds[v]);
 098      found = true;
 99    }
 100  }
 101
 0102  if(!found) {
 0103    printf(" - (No Dependencies, Independent Machine)\n");
 104  }
 105}

Methods/Properties