UNPKG

dist-javascript-algorithms-and-data-structures

Version:

Algorithms and data-structures implemented on JavaScript

40 lines (36 loc) 1.62 kB
"use strict"; var _GraphEdge = _interopRequireDefault(require("../GraphEdge")); var _GraphVertex = _interopRequireDefault(require("../GraphVertex")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } describe('GraphEdge', () => { it('should create graph edge with default weight', () => { const startVertex = new _GraphVertex.default('A'); const endVertex = new _GraphVertex.default('B'); const edge = new _GraphEdge.default(startVertex, endVertex); expect(edge.getKey()).toBe('A_B'); expect(edge.toString()).toBe('A_B'); expect(edge.startVertex).toEqual(startVertex); expect(edge.endVertex).toEqual(endVertex); expect(edge.weight).toEqual(0); }); it('should create graph edge with predefined weight', () => { const startVertex = new _GraphVertex.default('A'); const endVertex = new _GraphVertex.default('B'); const edge = new _GraphEdge.default(startVertex, endVertex, 10); expect(edge.startVertex).toEqual(startVertex); expect(edge.endVertex).toEqual(endVertex); expect(edge.weight).toEqual(10); }); it('should be possible to do edge reverse', () => { const vertexA = new _GraphVertex.default('A'); const vertexB = new _GraphVertex.default('B'); const edge = new _GraphEdge.default(vertexA, vertexB, 10); expect(edge.startVertex).toEqual(vertexA); expect(edge.endVertex).toEqual(vertexB); expect(edge.weight).toEqual(10); edge.reverse(); expect(edge.startVertex).toEqual(vertexB); expect(edge.endVertex).toEqual(vertexA); expect(edge.weight).toEqual(10); }); });