feat: solution for 'Повторный экзамен: Граф с рефлексией и доработкой'
This commit is contained in:
@@ -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');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user