• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

graphty-org / graphty-element / 15988747166

01 Jul 2025 03:01AM UTC coverage: 78.121% (+4.3%) from 73.786%
15988747166

push

github

apowers313
test: fix test types and mocks

319 of 434 branches covered (73.5%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 1 file covered. (100.0%)

202 existing lines in 8 files now uncovered.

2284 of 2898 relevant lines covered (78.81%)

886.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.56
/src/algorithms/Algorithm.ts
1
import {set as deepSet} from "lodash";
2✔
2

3
import {AdHocData} from "../config";
4
import {Edge} from "../Edge";
5
import {Graph} from "../Graph";
6

7
type AlgorithmClass = new (g: Graph) => Algorithm;
8
const algorithmRegistry = new Map<string, AlgorithmClass>();
2✔
9

10
// algorithmResults layout:
11
// {
12
//     node: {
13
//         id: {
14
//             namespace: {
15
//                 algorithm: {
16
//                     result: unknown
17
//                 }
18
//             }
19
//         }
20
//     },
21
//     edge: {
22
//         id: {
23
//             namespace: {
24
//                 algorithm: {
25
//                     result: unknown
26
//                 }
27
//             }
28
//         }
29
//     },
30
//     graph: {
31
//         namespace: {
32
//             algorithm: {
33
//                 result: unknown
34
//             }
35
//         }
36
//     }
37
// }
38

39
export abstract class Algorithm {
2✔
40
    static type: string;
41
    static namespace: string;
42
    protected graph: Graph;
43

44
    constructor(g: Graph) {
2✔
45
        this.graph = g;
3✔
46
    }
3✔
47

48
    get type(): string {
2✔
49
        return (this.constructor as typeof Algorithm).type;
924✔
50
    }
924✔
51

52
    get namespace(): string {
2✔
53
        return (this.constructor as typeof Algorithm).namespace;
924✔
54
    }
924✔
55

56
    get results(): AdHocData {
2✔
UNCOV
57
        const algorithmResults = {} as AdHocData;
×
UNCOV
58
        for (const n of this.graph.nodes.values()) {
×
UNCOV
59
            deepSet(algorithmResults, `node.${n.id}`, n.algorithmResults);
×
UNCOV
60
        }
×
61

62
        // TODO: edge and graph
63

UNCOV
64
        return algorithmResults;
×
65
        // return structuredClone(algorithmResults) as AdHocData;
UNCOV
66
    }
×
67

68
    abstract run(g: Graph): Promise<void>;
69

70
    #createPath(resultName: string): string[] {
2✔
71
        const ret: string[] = [];
924✔
72

73
        ret.push("algorithmResults");
924✔
74
        ret.push(this.namespace);
924✔
75
        ret.push(this.type);
924✔
76
        ret.push(resultName);
924✔
77

78
        return ret;
924✔
79
    }
924✔
80

81
    addNodeResult(nodeId: number | string, resultName: string, result: unknown): void {
2✔
82
        const p = this.#createPath(resultName);
924✔
83
        const n = this.graph.nodes.get(nodeId);
924✔
84
        if (!n) {
924!
85
            throw new Error(`couldn't find nodeId '${nodeId}' while trying to run algorithm '${this.type}'`);
×
86
        }
×
87

88
        deepSet(n, p, result);
924✔
89
        // XXX: THIS IS WHERE I LEFT OFF
90
        // replace algorithmResults with graph.nodes; set result on each node.algorithmResult
91
    }
924✔
92

93
    addEdgeResult(e: Edge, result: unknown): void {
2✔
UNCOV
94
        console.log("adding edge result", e, result);
×
UNCOV
95
    }
×
96

97
    addGraphResult(g: Graph, result: unknown): void {
2✔
98
        console.log("adding graph result", g, result);
×
99
    }
×
100

101
    static register<T extends AlgorithmClass>(cls: T): T {
2✔
102
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
103
        const t: string = (cls as any).type;
8✔
104
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
        const ns: string = (cls as any).namespace;
8✔
106
        algorithmRegistry.set(`${ns}:${t}`, cls);
8✔
107
        return cls;
8✔
108
    }
8✔
109

110
    static get(g: Graph, namespace: string, type: string): Algorithm | null {
2✔
111
        const SourceClass = algorithmRegistry.get(`${namespace}:${type}`);
1✔
112
        if (SourceClass) {
1✔
113
            return new SourceClass(g);
1✔
114
        }
1!
115

UNCOV
116
        return null;
×
117
    }
1✔
118
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc