@rsconcept/domain 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +55 -0
- package/dist/cctext/index.d.ts +1 -0
- package/dist/cctext/index.js +42 -0
- package/dist/cctext/index.js.map +1 -0
- package/dist/cctext/language-api.d.ts +43 -0
- package/dist/cctext/language-api.js +252 -0
- package/dist/cctext/language-api.js.map +1 -0
- package/dist/cctext/language.d.ts +58 -0
- package/dist/cctext/language.js +44 -0
- package/dist/cctext/language.js.map +1 -0
- package/dist/graph/graph.d.ts +62 -0
- package/dist/graph/graph.js +385 -0
- package/dist/graph/graph.js.map +1 -0
- package/dist/graph/index.d.ts +1 -0
- package/dist/graph/index.js +384 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +5851 -0
- package/dist/index.js.map +1 -0
- package/dist/library/folder-tree.d.ts +32 -0
- package/dist/library/folder-tree.js +136 -0
- package/dist/library/folder-tree.js.map +1 -0
- package/dist/library/index.d.ts +17 -0
- package/dist/library/index.js +2800 -0
- package/dist/library/index.js.map +1 -0
- package/dist/library/library-api.d.ts +6 -0
- package/dist/library/library-api.js +13 -0
- package/dist/library/library-api.js.map +1 -0
- package/dist/library/library.d.ts +56 -0
- package/dist/library/library.js +23 -0
- package/dist/library/library.js.map +1 -0
- package/dist/library/oss-api.d.ts +47 -0
- package/dist/library/oss-api.js +1105 -0
- package/dist/library/oss-api.js.map +1 -0
- package/dist/library/oss-layout-api.d.ts +36 -0
- package/dist/library/oss-layout-api.js +330 -0
- package/dist/library/oss-layout-api.js.map +1 -0
- package/dist/library/oss-layout.d.ts +25 -0
- package/dist/library/oss-layout.js +1 -0
- package/dist/library/oss-layout.js.map +1 -0
- package/dist/library/oss.d.ts +136 -0
- package/dist/library/oss.js +30 -0
- package/dist/library/oss.js.map +1 -0
- package/dist/library/rsengine.d.ts +116 -0
- package/dist/library/rsengine.js +2604 -0
- package/dist/library/rsengine.js.map +1 -0
- package/dist/library/rsform-api.d.ts +74 -0
- package/dist/library/rsform-api.js +879 -0
- package/dist/library/rsform-api.js.map +1 -0
- package/dist/library/rsform.d.ts +206 -0
- package/dist/library/rsform.js +32 -0
- package/dist/library/rsform.js.map +1 -0
- package/dist/library/rsmodel-api.d.ts +43 -0
- package/dist/library/rsmodel-api.js +836 -0
- package/dist/library/rsmodel-api.js.map +1 -0
- package/dist/library/rsmodel.d.ts +52 -0
- package/dist/library/rsmodel.js +25 -0
- package/dist/library/rsmodel.js.map +1 -0
- package/dist/library/structure-planner.d.ts +33 -0
- package/dist/library/structure-planner.js +481 -0
- package/dist/library/structure-planner.js.map +1 -0
- package/dist/parsing/ast.d.ts +49 -0
- package/dist/parsing/ast.js +93 -0
- package/dist/parsing/ast.js.map +1 -0
- package/dist/parsing/index.d.ts +3 -0
- package/dist/parsing/index.js +141 -0
- package/dist/parsing/index.js.map +1 -0
- package/dist/parsing/lezer-tree.d.ts +13 -0
- package/dist/parsing/lezer-tree.js +50 -0
- package/dist/parsing/lezer-tree.js.map +1 -0
- package/dist/rslang/api.d.ts +53 -0
- package/dist/rslang/api.js +846 -0
- package/dist/rslang/api.js.map +1 -0
- package/dist/rslang/ast-annotations.d.ts +18 -0
- package/dist/rslang/ast-annotations.js +56 -0
- package/dist/rslang/ast-annotations.js.map +1 -0
- package/dist/rslang/error.d.ts +85 -0
- package/dist/rslang/error.js +159 -0
- package/dist/rslang/error.js.map +1 -0
- package/dist/rslang/eval/calculator.d.ts +43 -0
- package/dist/rslang/eval/calculator.js +1639 -0
- package/dist/rslang/eval/calculator.js.map +1 -0
- package/dist/rslang/eval/evaluation-cache.d.ts +36 -0
- package/dist/rslang/eval/evaluation-cache.js +310 -0
- package/dist/rslang/eval/evaluation-cache.js.map +1 -0
- package/dist/rslang/eval/evaluator.d.ts +70 -0
- package/dist/rslang/eval/evaluator.js +1514 -0
- package/dist/rslang/eval/evaluator.js.map +1 -0
- package/dist/rslang/eval/value-api.d.ts +48 -0
- package/dist/rslang/eval/value-api.js +490 -0
- package/dist/rslang/eval/value-api.js.map +1 -0
- package/dist/rslang/eval/value.d.ts +36 -0
- package/dist/rslang/eval/value.js +118 -0
- package/dist/rslang/eval/value.js.map +1 -0
- package/dist/rslang/index.d.ts +17 -0
- package/dist/rslang/index.js +4314 -0
- package/dist/rslang/index.js.map +1 -0
- package/dist/rslang/labels.d.ts +16 -0
- package/dist/rslang/labels.js +315 -0
- package/dist/rslang/labels.js.map +1 -0
- package/dist/rslang/parser/expression-generator.d.ts +10 -0
- package/dist/rslang/parser/expression-generator.js +451 -0
- package/dist/rslang/parser/expression-generator.js.map +1 -0
- package/dist/rslang/parser/normalize.d.ts +11 -0
- package/dist/rslang/parser/normalize.js +507 -0
- package/dist/rslang/parser/normalize.js.map +1 -0
- package/dist/rslang/parser/parser.d.ts +5 -0
- package/dist/rslang/parser/parser.js +24 -0
- package/dist/rslang/parser/parser.js.map +1 -0
- package/dist/rslang/parser/parser.terms.d.ts +42 -0
- package/dist/rslang/parser/parser.terms.js +84 -0
- package/dist/rslang/parser/parser.terms.js.map +1 -0
- package/dist/rslang/parser/syntax-errors.d.ts +11 -0
- package/dist/rslang/parser/syntax-errors.js +403 -0
- package/dist/rslang/parser/syntax-errors.js.map +1 -0
- package/dist/rslang/parser/token.d.ts +79 -0
- package/dist/rslang/parser/token.js +95 -0
- package/dist/rslang/parser/token.js.map +1 -0
- package/dist/rslang/semantic/analyzer.d.ts +39 -0
- package/dist/rslang/semantic/analyzer.js +2604 -0
- package/dist/rslang/semantic/analyzer.js.map +1 -0
- package/dist/rslang/semantic/arguments-extractor.d.ts +42 -0
- package/dist/rslang/semantic/arguments-extractor.js +366 -0
- package/dist/rslang/semantic/arguments-extractor.js.map +1 -0
- package/dist/rslang/semantic/type-auditor.d.ts +73 -0
- package/dist/rslang/semantic/type-auditor.js +1570 -0
- package/dist/rslang/semantic/type-auditor.js.map +1 -0
- package/dist/rslang/semantic/typification-api.d.ts +27 -0
- package/dist/rslang/semantic/typification-api.js +320 -0
- package/dist/rslang/semantic/typification-api.js.map +1 -0
- package/dist/rslang/semantic/typification-parser.d.ts +12 -0
- package/dist/rslang/semantic/typification-parser.js +226 -0
- package/dist/rslang/semantic/typification-parser.js.map +1 -0
- package/dist/rslang/semantic/typification.d.ts +119 -0
- package/dist/rslang/semantic/typification.js +74 -0
- package/dist/rslang/semantic/typification.js.map +1 -0
- package/dist/rslang/semantic/value-auditor.d.ts +43 -0
- package/dist/rslang/semantic/value-auditor.js +523 -0
- package/dist/rslang/semantic/value-auditor.js.map +1 -0
- package/dist/rslang/semantic/value-class.d.ts +10 -0
- package/dist/rslang/semantic/value-class.js +9 -0
- package/dist/rslang/semantic/value-class.js.map +1 -0
- package/dist/rslang/typification-graph.d.ts +33 -0
- package/dist/rslang/typification-graph.js +311 -0
- package/dist/rslang/typification-graph.js.map +1 -0
- package/dist/shared/branded.d.ts +7 -0
- package/dist/shared/branded.js +1 -0
- package/dist/shared/branded.js.map +1 -0
- package/dist/shared/hash.d.ts +6 -0
- package/dist/shared/hash.js +18 -0
- package/dist/shared/hash.js.map +1 -0
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/index.js +18 -0
- package/dist/shared/index.js.map +1 -0
- package/package.json +184 -0
- package/src/cctext/index.ts +9 -0
- package/src/cctext/language-api.test.ts +149 -0
- package/src/cctext/language-api.ts +285 -0
- package/src/cctext/language.ts +80 -0
- package/src/graph/graph.test.ts +392 -0
- package/src/graph/graph.ts +433 -0
- package/src/graph/index.ts +1 -0
- package/src/index.ts +96 -0
- package/src/library/folder-tree.test.ts +47 -0
- package/src/library/folder-tree.ts +156 -0
- package/src/library/index.ts +46 -0
- package/src/library/library-api.test.ts +32 -0
- package/src/library/library-api.ts +11 -0
- package/src/library/library.ts +61 -0
- package/src/library/oss-api.ts +449 -0
- package/src/library/oss-layout-api.ts +377 -0
- package/src/library/oss-layout.ts +27 -0
- package/src/library/oss.ts +150 -0
- package/src/library/rsengine.ts +593 -0
- package/src/library/rsform-api.ts +533 -0
- package/src/library/rsform.ts +228 -0
- package/src/library/rsmodel-api.ts +340 -0
- package/src/library/rsmodel.ts +50 -0
- package/src/library/structure-planner.ts +143 -0
- package/src/parsing/ast.ts +136 -0
- package/src/parsing/index.ts +15 -0
- package/src/parsing/lezer-tree.ts +69 -0
- package/src/rslang/api.test.ts +116 -0
- package/src/rslang/api.ts +183 -0
- package/src/rslang/ast-annotations.ts +70 -0
- package/src/rslang/error.ts +129 -0
- package/src/rslang/eval/calculator.test.ts +124 -0
- package/src/rslang/eval/calculator.ts +121 -0
- package/src/rslang/eval/evaluation-cache.ts +257 -0
- package/src/rslang/eval/evaluator.test.ts +352 -0
- package/src/rslang/eval/evaluator.ts +935 -0
- package/src/rslang/eval/value-api.test.ts +105 -0
- package/src/rslang/eval/value-api.ts +444 -0
- package/src/rslang/eval/value.ts +102 -0
- package/src/rslang/index.ts +23 -0
- package/src/rslang/labels.ts +191 -0
- package/src/rslang/parser/expression-generator.test.ts +100 -0
- package/src/rslang/parser/expression-generator.ts +466 -0
- package/src/rslang/parser/normalize.test.ts +99 -0
- package/src/rslang/parser/normalize.ts +462 -0
- package/src/rslang/parser/parser.terms.ts +42 -0
- package/src/rslang/parser/parser.test.ts +153 -0
- package/src/rslang/parser/parser.ts +20 -0
- package/src/rslang/parser/rslang.grammar +251 -0
- package/src/rslang/parser/syntax-errors.ts +209 -0
- package/src/rslang/parser/token.ts +106 -0
- package/src/rslang/semantic/analyzer.test.ts +59 -0
- package/src/rslang/semantic/analyzer.ts +179 -0
- package/src/rslang/semantic/arguments-extractor.ts +327 -0
- package/src/rslang/semantic/type-auditor.test.ts +326 -0
- package/src/rslang/semantic/type-auditor.ts +1049 -0
- package/src/rslang/semantic/typification-api.test.ts +46 -0
- package/src/rslang/semantic/typification-api.ts +321 -0
- package/src/rslang/semantic/typification-parser.test.ts +50 -0
- package/src/rslang/semantic/typification-parser.ts +220 -0
- package/src/rslang/semantic/typification.ts +180 -0
- package/src/rslang/semantic/value-auditor.test.ts +206 -0
- package/src/rslang/semantic/value-auditor.ts +332 -0
- package/src/rslang/semantic/value-class.ts +11 -0
- package/src/rslang/typification-graph.ts +155 -0
- package/src/shared/branded.ts +6 -0
- package/src/shared/hash.ts +17 -0
- package/src/shared/index.ts +2 -0
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { Graph } from './graph';
|
|
4
|
+
|
|
5
|
+
describe('Testing Graph construction', () => {
|
|
6
|
+
it('empty Graph should be empty', () => {
|
|
7
|
+
const graph = new Graph();
|
|
8
|
+
expect(graph.nodes.size).toBe(0);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('adding edges should create nodes', () => {
|
|
12
|
+
const graph = new Graph();
|
|
13
|
+
graph.addEdge(13, 37);
|
|
14
|
+
expect([...graph.nodes.keys()]).toStrictEqual([13, 37]);
|
|
15
|
+
|
|
16
|
+
graph.addEdge(13, 38);
|
|
17
|
+
expect([...graph.nodes.keys()]).toStrictEqual([13, 37, 38]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('creating from array', () => {
|
|
21
|
+
const graph = new Graph([[1, 2], [3], [4, 1]]);
|
|
22
|
+
expect([...graph.nodes.keys()]).toStrictEqual([1, 2, 3, 4]);
|
|
23
|
+
expect([...graph.nodes.get(1)!.outputs]).toStrictEqual([2]);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('cloning', () => {
|
|
27
|
+
const graph = new Graph([[1, 2], [3], [4, 1]]);
|
|
28
|
+
const clone = graph.clone();
|
|
29
|
+
expect([...graph.nodes.keys()]).toStrictEqual([...clone.nodes.keys()]);
|
|
30
|
+
expect([...graph.nodes.values()]).toStrictEqual([...clone.nodes.values()]);
|
|
31
|
+
|
|
32
|
+
clone.removeNode(3);
|
|
33
|
+
expect(clone.nodes.get(3)).toBeUndefined();
|
|
34
|
+
expect(graph.nodes.get(3)).not.toBeUndefined();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('Testing Graph editing', () => {
|
|
39
|
+
it('removing edges should not remove nodes', () => {
|
|
40
|
+
const graph = new Graph([[1, 2], [3], [4, 1]]);
|
|
41
|
+
expect(graph.hasEdge(4, 1)).toBeTruthy();
|
|
42
|
+
|
|
43
|
+
graph.removeEdge(5, 0);
|
|
44
|
+
graph.removeEdge(4, 1);
|
|
45
|
+
|
|
46
|
+
expect([...graph.nodes.keys()]).toStrictEqual([1, 2, 3, 4]);
|
|
47
|
+
expect(graph.hasEdge(4, 1)).toBeFalsy();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('folding node redirects edges', () => {
|
|
51
|
+
const graph = new Graph([
|
|
52
|
+
[1, 3],
|
|
53
|
+
[2, 3],
|
|
54
|
+
[3, 4],
|
|
55
|
+
[3, 5],
|
|
56
|
+
[3, 3]
|
|
57
|
+
]);
|
|
58
|
+
graph.foldNode(3);
|
|
59
|
+
expect(graph.hasNode(3)).toBeFalsy();
|
|
60
|
+
expect(graph.hasEdge(1, 4)).toBeTruthy();
|
|
61
|
+
expect(graph.hasEdge(1, 5)).toBeTruthy();
|
|
62
|
+
expect(graph.hasEdge(2, 4)).toBeTruthy();
|
|
63
|
+
expect(graph.hasEdge(2, 5)).toBeTruthy();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('folding a non-existent node should not change the graph', () => {
|
|
67
|
+
const graph = new Graph([
|
|
68
|
+
[1, 2],
|
|
69
|
+
[2, 3]
|
|
70
|
+
]);
|
|
71
|
+
const clone = graph.clone();
|
|
72
|
+
graph.foldNode(99); // Node 99 does not exist
|
|
73
|
+
expect(graph.nodes.size).toBe(clone.nodes.size);
|
|
74
|
+
expect([...graph.nodes.keys()]).toEqual([...clone.nodes.keys()]);
|
|
75
|
+
expect(graph.hasEdge(1, 2)).toBeTruthy();
|
|
76
|
+
expect(graph.hasEdge(2, 3)).toBeTruthy();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('folding a node with no inputs', () => {
|
|
80
|
+
const graph = new Graph([
|
|
81
|
+
[1, 2],
|
|
82
|
+
[1, 3]
|
|
83
|
+
]);
|
|
84
|
+
graph.foldNode(1);
|
|
85
|
+
expect(graph.hasNode(1)).toBeFalsy();
|
|
86
|
+
expect(graph.nodes.size).toBe(2); // Nodes 2 and 3 remain
|
|
87
|
+
expect(graph.hasNode(2)).toBeTruthy();
|
|
88
|
+
expect(graph.hasNode(3)).toBeTruthy();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('folding a node with no outputs', () => {
|
|
92
|
+
const graph = new Graph([
|
|
93
|
+
[1, 3],
|
|
94
|
+
[2, 3]
|
|
95
|
+
]);
|
|
96
|
+
graph.foldNode(3);
|
|
97
|
+
expect(graph.hasNode(3)).toBeFalsy();
|
|
98
|
+
expect(graph.nodes.size).toBe(2); // Nodes 1 and 2 remain
|
|
99
|
+
expect(graph.hasNode(1)).toBeTruthy();
|
|
100
|
+
expect(graph.hasNode(2)).toBeTruthy();
|
|
101
|
+
expect(graph.nodes.get(1)!.outputs.length).toBe(0);
|
|
102
|
+
expect(graph.nodes.get(2)!.outputs.length).toBe(0);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('removing isolated nodes', () => {
|
|
106
|
+
const graph = new Graph([[9, 1], [9, 2], [2, 1], [4, 3], [5, 9], [7], [8]]);
|
|
107
|
+
graph.removeIsolated();
|
|
108
|
+
expect([...graph.nodes.keys()]).toStrictEqual([9, 1, 2, 4, 3, 5]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('transitive reduction', () => {
|
|
112
|
+
const graph = new Graph([
|
|
113
|
+
[1, 3],
|
|
114
|
+
[1, 2],
|
|
115
|
+
[2, 3]
|
|
116
|
+
]);
|
|
117
|
+
graph.transitiveReduction();
|
|
118
|
+
expect(graph.hasEdge(1, 2)).toBeTruthy();
|
|
119
|
+
expect(graph.hasEdge(2, 3)).toBeTruthy();
|
|
120
|
+
expect(graph.hasEdge(1, 3)).toBeFalsy();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('transitive reduction - empty graph', () => {
|
|
124
|
+
const graph = new Graph();
|
|
125
|
+
expect(() => graph.transitiveReduction()).not.toThrow();
|
|
126
|
+
expect(graph.nodes.size).toBe(0);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('transitive reduction - single node', () => {
|
|
130
|
+
const graph = new Graph([[1]]);
|
|
131
|
+
graph.transitiveReduction();
|
|
132
|
+
expect(graph.hasNode(1)).toBeTruthy();
|
|
133
|
+
expect(graph.nodes.get(1)!.outputs.length).toBe(0);
|
|
134
|
+
expect(graph.nodes.get(1)!.inputs.length).toBe(0);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('transitive reduction - linear chain', () => {
|
|
138
|
+
const graph = new Graph([
|
|
139
|
+
[1, 2],
|
|
140
|
+
[2, 3],
|
|
141
|
+
[3, 4],
|
|
142
|
+
[4, 5]
|
|
143
|
+
]);
|
|
144
|
+
graph.transitiveReduction();
|
|
145
|
+
expect(graph.hasEdge(1, 2)).toBeTruthy();
|
|
146
|
+
expect(graph.hasEdge(2, 3)).toBeTruthy();
|
|
147
|
+
expect(graph.hasEdge(3, 4)).toBeTruthy();
|
|
148
|
+
expect(graph.hasEdge(4, 5)).toBeTruthy();
|
|
149
|
+
expect(graph.hasEdge(1, 3)).toBeFalsy();
|
|
150
|
+
expect(graph.hasEdge(1, 4)).toBeFalsy();
|
|
151
|
+
expect(graph.hasEdge(1, 5)).toBeFalsy();
|
|
152
|
+
expect(graph.hasEdge(2, 4)).toBeFalsy();
|
|
153
|
+
expect(graph.hasEdge(2, 5)).toBeFalsy();
|
|
154
|
+
expect(graph.hasEdge(3, 5)).toBeFalsy();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('transitive reduction - diamond pattern', () => {
|
|
158
|
+
const graph = new Graph([
|
|
159
|
+
[1, 2],
|
|
160
|
+
[1, 3],
|
|
161
|
+
[2, 4],
|
|
162
|
+
[3, 4]
|
|
163
|
+
]);
|
|
164
|
+
graph.transitiveReduction();
|
|
165
|
+
expect(graph.hasEdge(1, 2)).toBeTruthy();
|
|
166
|
+
expect(graph.hasEdge(1, 3)).toBeTruthy();
|
|
167
|
+
expect(graph.hasEdge(2, 4)).toBeTruthy();
|
|
168
|
+
expect(graph.hasEdge(3, 4)).toBeTruthy();
|
|
169
|
+
expect(graph.hasEdge(1, 4)).toBeFalsy();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('transitive reduction - complex transitive relationships', () => {
|
|
173
|
+
const graph = new Graph([
|
|
174
|
+
[6, 7],
|
|
175
|
+
[5, 7],
|
|
176
|
+
[4, 6],
|
|
177
|
+
[3, 5],
|
|
178
|
+
[2, 5],
|
|
179
|
+
[1, 4],
|
|
180
|
+
[1, 3],
|
|
181
|
+
[1, 2]
|
|
182
|
+
]);
|
|
183
|
+
graph.transitiveReduction();
|
|
184
|
+
expect(graph.hasEdge(1, 2)).toBeTruthy();
|
|
185
|
+
expect(graph.hasEdge(1, 3)).toBeTruthy();
|
|
186
|
+
expect(graph.hasEdge(1, 4)).toBeTruthy();
|
|
187
|
+
expect(graph.hasEdge(2, 5)).toBeTruthy();
|
|
188
|
+
expect(graph.hasEdge(3, 5)).toBeTruthy();
|
|
189
|
+
expect(graph.hasEdge(4, 6)).toBeTruthy();
|
|
190
|
+
expect(graph.hasEdge(5, 7)).toBeTruthy();
|
|
191
|
+
expect(graph.hasEdge(6, 7)).toBeTruthy();
|
|
192
|
+
|
|
193
|
+
expect(graph.hasEdge(1, 5)).toBeFalsy();
|
|
194
|
+
expect(graph.hasEdge(1, 7)).toBeFalsy();
|
|
195
|
+
expect(graph.hasEdge(2, 7)).toBeFalsy();
|
|
196
|
+
expect(graph.hasEdge(3, 7)).toBeFalsy();
|
|
197
|
+
expect(graph.hasEdge(4, 7)).toBeFalsy();
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('transitive reduction - disconnected components', () => {
|
|
201
|
+
const graph = new Graph([
|
|
202
|
+
[1, 2],
|
|
203
|
+
[2, 3],
|
|
204
|
+
[4, 5],
|
|
205
|
+
[5, 6],
|
|
206
|
+
[4, 6] // This should be removed
|
|
207
|
+
]);
|
|
208
|
+
graph.transitiveReduction();
|
|
209
|
+
expect(graph.hasEdge(1, 2)).toBeTruthy();
|
|
210
|
+
expect(graph.hasEdge(2, 3)).toBeTruthy();
|
|
211
|
+
expect(graph.hasEdge(4, 5)).toBeTruthy();
|
|
212
|
+
expect(graph.hasEdge(5, 6)).toBeTruthy();
|
|
213
|
+
expect(graph.hasEdge(4, 6)).toBeFalsy();
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('transitive reduction - multiple paths same length', () => {
|
|
217
|
+
const graph = new Graph([
|
|
218
|
+
[3, 4],
|
|
219
|
+
[2, 4],
|
|
220
|
+
[1, 3],
|
|
221
|
+
[1, 2]
|
|
222
|
+
]);
|
|
223
|
+
graph.transitiveReduction();
|
|
224
|
+
expect(graph.hasEdge(1, 2)).toBeTruthy();
|
|
225
|
+
expect(graph.hasEdge(1, 3)).toBeTruthy();
|
|
226
|
+
expect(graph.hasEdge(2, 4)).toBeTruthy();
|
|
227
|
+
expect(graph.hasEdge(3, 4)).toBeTruthy();
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('transitive reduction - already reduced graph', () => {
|
|
231
|
+
const graph = new Graph([
|
|
232
|
+
[1, 2],
|
|
233
|
+
[2, 3]
|
|
234
|
+
]);
|
|
235
|
+
const originalEdgeCount = 2;
|
|
236
|
+
graph.transitiveReduction();
|
|
237
|
+
expect(graph.hasEdge(1, 2)).toBeTruthy();
|
|
238
|
+
expect(graph.hasEdge(2, 3)).toBeTruthy();
|
|
239
|
+
expect(graph.hasEdge(1, 3)).toBeFalsy();
|
|
240
|
+
// Should still have 2 edges
|
|
241
|
+
let edgeCount = 0;
|
|
242
|
+
graph.nodes.forEach(node => (edgeCount += node.outputs.length));
|
|
243
|
+
expect(edgeCount).toBe(originalEdgeCount);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('transitive reduction - preserves all nodes', () => {
|
|
247
|
+
const graph = new Graph([
|
|
248
|
+
[1, 2],
|
|
249
|
+
[1, 3],
|
|
250
|
+
[2, 3]
|
|
251
|
+
]);
|
|
252
|
+
const originalNodeCount = graph.nodes.size;
|
|
253
|
+
graph.transitiveReduction();
|
|
254
|
+
expect(graph.nodes.size).toBe(originalNodeCount);
|
|
255
|
+
expect(graph.hasNode(1)).toBeTruthy();
|
|
256
|
+
expect(graph.hasNode(2)).toBeTruthy();
|
|
257
|
+
expect(graph.hasNode(3)).toBeTruthy();
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe('Testing Graph sort', () => {
|
|
262
|
+
it('topological order', () => {
|
|
263
|
+
const graph = new Graph([
|
|
264
|
+
[9, 1],
|
|
265
|
+
[9, 2],
|
|
266
|
+
[2, 1],
|
|
267
|
+
[4, 3],
|
|
268
|
+
[5, 9]
|
|
269
|
+
]);
|
|
270
|
+
expect(graph.topologicalOrder()).toStrictEqual([5, 4, 3, 9, 2, 1]);
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
describe('Testing Graph queries', () => {
|
|
275
|
+
it('expand outputs', () => {
|
|
276
|
+
const graph = new Graph([
|
|
277
|
+
[1, 2], //
|
|
278
|
+
[2, 3],
|
|
279
|
+
[2, 5],
|
|
280
|
+
[5, 6],
|
|
281
|
+
[6, 1],
|
|
282
|
+
[7]
|
|
283
|
+
]);
|
|
284
|
+
expect(graph.expandOutputs([])).toStrictEqual([]);
|
|
285
|
+
expect(graph.expandAllOutputs([])).toStrictEqual([]);
|
|
286
|
+
expect(graph.expandOutputs([3])).toStrictEqual([]);
|
|
287
|
+
expect(graph.expandAllOutputs([3])).toStrictEqual([]);
|
|
288
|
+
expect(graph.expandOutputs([7])).toStrictEqual([]);
|
|
289
|
+
expect(graph.expandAllOutputs([7])).toStrictEqual([]);
|
|
290
|
+
expect(graph.expandOutputs([2, 5])).toStrictEqual([3, 6]);
|
|
291
|
+
expect(graph.expandAllOutputs([2, 5])).toStrictEqual([3, 6, 1]);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('expand into unique array', () => {
|
|
295
|
+
const graph = new Graph([
|
|
296
|
+
[1, 2],
|
|
297
|
+
[1, 3],
|
|
298
|
+
[2, 5],
|
|
299
|
+
[3, 5]
|
|
300
|
+
]);
|
|
301
|
+
expect(graph.expandAllOutputs([1])).toStrictEqual([2, 3, 5]);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('expand inputs', () => {
|
|
305
|
+
const graph = new Graph([
|
|
306
|
+
[1, 2], //
|
|
307
|
+
[2, 3],
|
|
308
|
+
[2, 5],
|
|
309
|
+
[5, 6],
|
|
310
|
+
[6, 1],
|
|
311
|
+
[7]
|
|
312
|
+
]);
|
|
313
|
+
expect(graph.expandInputs([])).toStrictEqual([]);
|
|
314
|
+
expect(graph.expandAllInputs([])).toStrictEqual([]);
|
|
315
|
+
expect(graph.expandInputs([7])).toStrictEqual([]);
|
|
316
|
+
expect(graph.expandAllInputs([7])).toStrictEqual([]);
|
|
317
|
+
expect(graph.expandInputs([6])).toStrictEqual([5]);
|
|
318
|
+
expect(graph.expandAllInputs([6])).toStrictEqual([5, 2, 1]);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('maximize part', () => {
|
|
322
|
+
const graph = new Graph([
|
|
323
|
+
[1, 7], //
|
|
324
|
+
[1, 3],
|
|
325
|
+
[2, 3],
|
|
326
|
+
[2, 4],
|
|
327
|
+
[3, 5],
|
|
328
|
+
[3, 6],
|
|
329
|
+
[3, 4],
|
|
330
|
+
[7, 5],
|
|
331
|
+
[8]
|
|
332
|
+
]);
|
|
333
|
+
expect(graph.maximizePart([])).toStrictEqual([]);
|
|
334
|
+
expect(graph.maximizePart([8])).toStrictEqual([8]);
|
|
335
|
+
expect(graph.maximizePart([5])).toStrictEqual([5]);
|
|
336
|
+
expect(graph.maximizePart([3])).toStrictEqual([3, 6]);
|
|
337
|
+
expect(graph.maximizePart([3, 2])).toStrictEqual([3, 2, 6, 4]);
|
|
338
|
+
expect(graph.maximizePart([3, 1])).toStrictEqual([3, 1, 7, 5, 6]);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it('find elementary cycle', () => {
|
|
342
|
+
const graph = new Graph([
|
|
343
|
+
[1, 1] //
|
|
344
|
+
]);
|
|
345
|
+
expect(graph.findCycle()).toStrictEqual([1, 1]);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('find cycle acyclic', () => {
|
|
349
|
+
const graph = new Graph([
|
|
350
|
+
[1, 2], //
|
|
351
|
+
[2]
|
|
352
|
+
]);
|
|
353
|
+
expect(graph.findCycle()).toStrictEqual(null);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it('find cycle typical', () => {
|
|
357
|
+
const graph = new Graph([
|
|
358
|
+
[1, 2], //
|
|
359
|
+
[1, 4],
|
|
360
|
+
[2, 3],
|
|
361
|
+
[3, 1],
|
|
362
|
+
[3, 4],
|
|
363
|
+
[4]
|
|
364
|
+
]);
|
|
365
|
+
expect(graph.findCycle()).toStrictEqual([1, 2, 3, 1]);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it('find cycle acyclic 2 components', () => {
|
|
369
|
+
const graph = new Graph([
|
|
370
|
+
[0, 1], //
|
|
371
|
+
[2, 3],
|
|
372
|
+
[3, 0]
|
|
373
|
+
]);
|
|
374
|
+
expect(graph.findCycle()).toStrictEqual(null);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('sortStable should stably reorder node ids according to topological order', () => {
|
|
378
|
+
const graph = new Graph([
|
|
379
|
+
[1, 2],
|
|
380
|
+
[2, 3],
|
|
381
|
+
[1, 4],
|
|
382
|
+
[4, 3],
|
|
383
|
+
[3, 5]
|
|
384
|
+
]);
|
|
385
|
+
expect(graph.sortStable([5, 4, 3, 2, 1])).toStrictEqual([5, 3, 4, 2, 1]);
|
|
386
|
+
expect(graph.sortStable([1, 2, 4, 3, 5])).toStrictEqual([1, 2, 4, 3, 5]);
|
|
387
|
+
expect(graph.sortStable([4, 3, 5])).toStrictEqual([4, 3, 5]);
|
|
388
|
+
expect(graph.sortStable([2, 3])).toStrictEqual([2, 3]);
|
|
389
|
+
expect(graph.sortStable([3])).toStrictEqual([3]);
|
|
390
|
+
expect(graph.sortStable([])).toStrictEqual([]);
|
|
391
|
+
});
|
|
392
|
+
});
|