mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-03-13 08:51:02 +08:00
Make it possible to delete all vertex edges at once.
This commit is contained in:
@@ -70,6 +70,36 @@ describe('GraphVertex', () => {
|
||||
expect(vertexA.getEdges().length).toBe(0);
|
||||
});
|
||||
|
||||
it('should delete all edges from vertex', () => {
|
||||
const vertexA = new GraphVertex('A');
|
||||
const vertexB = new GraphVertex('B');
|
||||
const vertexC = new GraphVertex('C');
|
||||
|
||||
const edgeAB = new GraphEdge(vertexA, vertexB);
|
||||
const edgeAC = new GraphEdge(vertexA, vertexC);
|
||||
vertexA
|
||||
.addEdge(edgeAB)
|
||||
.addEdge(edgeAC);
|
||||
|
||||
expect(vertexA.hasEdge(edgeAB)).toBeTruthy();
|
||||
expect(vertexB.hasEdge(edgeAB)).toBeFalsy();
|
||||
|
||||
expect(vertexA.hasEdge(edgeAC)).toBeTruthy();
|
||||
expect(vertexC.hasEdge(edgeAC)).toBeFalsy();
|
||||
|
||||
expect(vertexA.getEdges().length).toBe(2);
|
||||
|
||||
vertexA.deleteAllEdges();
|
||||
|
||||
expect(vertexA.hasEdge(edgeAB)).toBeFalsy();
|
||||
expect(vertexB.hasEdge(edgeAB)).toBeFalsy();
|
||||
|
||||
expect(vertexA.hasEdge(edgeAC)).toBeFalsy();
|
||||
expect(vertexC.hasEdge(edgeAC)).toBeFalsy();
|
||||
|
||||
expect(vertexA.getEdges().length).toBe(0);
|
||||
});
|
||||
|
||||
it('should return vertex neighbors in case if current node is start one', () => {
|
||||
const vertexA = new GraphVertex('A');
|
||||
const vertexB = new GraphVertex('B');
|
||||
|
||||
Reference in New Issue
Block a user