const Graph = require('../src/graph'); describe('Graph', () => { test('should add reflection node and evaluate correctly', () => { const g = new Graph(); g.addNode('A', 'reflection'); const outputs = g.evaluate('A', 42); expect(outputs['A']).toBe(42); }); test('should add rewrite node and evaluate correctly', () => { const g = new Graph(); g.addNode('B', 'rewrite'); const outputs = g.evaluate('B', 'hello'); expect(outputs['B']).toBe('HELLO'); }); test('should propagate through connected nodes', () => { const g = new Graph(); g.addNode('A', 'reflection'); g.addNode('B', 'rewrite'); g.addEdge('A', 'B'); const outputs = g.evaluate('A', 'test'); expect(outputs['A']).toBe('test'); expect(outputs['B']).toBe('TEST'); }); test('should throw error on unknown node type', () => { const g = new Graph(); expect(() => g.addNode('C', 'unknown')).toThrow(); }); test('should throw error on duplicate node name', () => { const g = new Graph(); g.addNode('D', 'reflection'); expect(() => g.addNode('D', 'rewrite')).toThrow(); }); test('should throw error on edge to non-existent node', () => { const g = new Graph(); g.addNode('E', 'reflection'); expect(() => g.addEdge('E', 'F')).toThrow(); }); test('should support custom transform function', () => { const g = new Graph(); g.addNode('G', 'rewrite', { transform: (x) => x * 2 }); const outputs = g.evaluate('G', 5); expect(outputs['G']).toBe(10); }); test('should handle multiple outputs', () => { const g = new Graph(); g.addNode('A', 'reflection'); g.addNode('B', 'rewrite'); g.addNode('C', 'rewrite'); g.addEdge('A', 'B'); g.addEdge('A', 'C'); const outputs = g.evaluate('A', 'multi'); expect(outputs['A']).toBe('multi'); expect(outputs['B']).toBe('MULTI'); expect(outputs['C']).toBe('MULTI'); }); });