Skip to content

Commit 8627da5

Browse files
committed
fix(algorithms): fix path-planting tests and add missing exports
- Fix path-generator.ts to validate source/target nodes exist before adding edges - Fix test file to use correct Graph API (addNode takes single parameter) - Add pathFollowsTemplate to evaluation exports Test results: - 18/23 path-planting tests passing (up from 12/23) - 5 citation-planting tests have design issue (return Graph instead of PlantedPathResult) - All 14 integration tests passing - Core evaluation framework working correctly Known limitation: Citation-planting tests need refactoring to return proper PlantedPathResult structure instead of raw Graph. Note: Pre-existing lint errors in path-planting files remain (non-null assertions)
1 parent 9ff78e2 commit 8627da5

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

packages/algorithms/__tests__/evaluation/path-planting.unit.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ describe('Path Planting - Ground Truth Generator', () => {
3737

3838
// Add 10 nodes for testing
3939
for (let i = 0; i < 10; i++) {
40-
graph.addNode(`node${i}`, { id: `node${i}`, type: 'TestNode' });
40+
const node: TestNode = { id: `node${i}`, type: 'TestNode' };
41+
graph.addNode(node);
4142
}
4243
});
4344

@@ -89,7 +90,8 @@ describe('Path Planting - Ground Truth Generator', () => {
8990
const result1 = plantGroundTruthPaths(graph, config);
9091
const graph2 = new Graph<TestNode, TestEdge>();
9192
for (let i = 0; i < 10; i++) {
92-
graph2.addNode(`node${i}`, { id: `node${i}`, type: 'TestNode' });
93+
const node: TestNode = { id: `node${i}`, type: 'TestNode' };
94+
graph2.addNode(node);
9395
}
9496
const result2 = plantGroundTruthPaths(graph2, config);
9597

@@ -173,7 +175,8 @@ describe('Path Planting - Noise Generator', () => {
173175

174176
// Add nodes
175177
for (let i = 0; i < 10; i++) {
176-
graph.addNode(`node${i}`, { id: `node${i}`, type: 'TestNode' });
178+
const node: TestNode = { id: `node${i}`, type: 'TestNode' };
179+
graph.addNode(node);
177180
}
178181
});
179182

packages/algorithms/src/evaluation/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export {
4444
addNoisePaths,
4545
plantHeterogeneousPaths,
4646
plantCitationPaths,
47+
pathFollowsTemplate,
4748
type PlantedPathConfig,
4849
type PlantedPathResult,
4950
type HeterogeneousPathConfig,

packages/algorithms/src/evaluation/path-planting/path-generator.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ export function plantGroundTruthPaths<N extends Node, E extends Edge>(
158158
const source = sources[i % sources.length]!;
159159
const target = targets[i % targets.length]!;
160160

161+
// Validate source and target exist
162+
const sourceNode = baseGraph.getNode(source);
163+
const targetNode = baseGraph.getNode(target);
164+
165+
if (!sourceNode.some) {
166+
throw new Error(`Source node '${source}' not found in graph`);
167+
}
168+
169+
if (!targetNode.some) {
170+
throw new Error(`Target node '${target}' not found in graph`);
171+
}
172+
161173
// Generate path with random length
162174
const pathLength = rng.nextInt(config.pathLength.min, config.pathLength.max);
163175
const pathNodes: N[] = [];
@@ -167,10 +179,8 @@ export function plantGroundTruthPaths<N extends Node, E extends Edge>(
167179
let currentNodeId = source;
168180
let currentMI = rng.nextDouble() * (miRange.max - miRange.min) + miRange.min;
169181

170-
const sourceNode = baseGraph.getNode(currentNodeId);
171-
if (sourceNode.some) {
172-
pathNodes.push(sourceNode.value);
173-
}
182+
// Start with source node
183+
pathNodes.push(sourceNode.value);
174184

175185
for (let j = 0; j < pathLength; j++) {
176186
// Generate intermediate node ID
@@ -212,10 +222,8 @@ export function plantGroundTruthPaths<N extends Node, E extends Edge>(
212222
pathEdges.push(finalEdge);
213223
totalMI += currentMI;
214224

215-
const targetNode = baseGraph.getNode(target);
216-
if (targetNode.some) {
217-
pathNodes.push(targetNode.value);
218-
}
225+
// End with target node
226+
pathNodes.push(targetNode.value);
219227

220228
// Create path object
221229
const path: Path<N, E> = {

0 commit comments

Comments
 (0)