feat: solution for 'Повторный экзамен: Граф с рефлексией и доработкой'

This commit is contained in:
2026-06-30 14:34:54 +03:00
parent 9ab33ca6a8
commit babdcf160b
5 changed files with 126 additions and 82 deletions
+39
View File
@@ -0,0 +1,39 @@
import Graph from '../src/graph.js';
describe('Graph', () => {
test('should add nodes and edges correctly', () => {
const g = new Graph();
g.addNode('x');
g.addNode('y');
g.addEdge('x', 'y');
expect(g.hasEdge('x', 'y')).toBe(true);
expect(g.hasEdge('y', 'x')).toBe(false);
});
test('reflexive should add self loops', () => {
const g = new Graph();
g.addNode('x');
g.addNode('y');
g.addEdge('x', 'y');
g.reflexive();
expect(g.hasEdge('x', 'x')).toBe(true);
expect(g.hasEdge('y', 'y')).toBe(true);
});
test('getAdjacencyList returns correct structure', () => {
const g = new Graph();
g.addNode('x');
g.addNode('y');
g.addEdge('x', 'y');
g.reflexive();
const adj = g.getAdjacencyList();
expect(adj['x']).toContain('y');
expect(adj['x']).toContain('x');
expect(adj['y']).toContain('y');
});
});