-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvertex.test.ts
50 lines (40 loc) · 1.32 KB
/
vertex.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Vertex } from './vertex'
import { Edge } from './edge'
describe('Test Graph Vertex', () => {
let vertex: Vertex
beforeEach(() => {
vertex = new Vertex(0)
})
it('should create vertex', () => {
expect(vertex.value).toBe(0)
expect(vertex.getEdges()).toStrictEqual([])
})
it('should add and remove edge', () => {
const edgeA = new Edge(vertex, new Vertex(1))
vertex.addEdge(edgeA)
expect(vertex.hasEdge(edgeA)).toBeTruthy()
expect(vertex.getEdges()[0].toString()).toBe('0_1')
vertex.removeEdge(edgeA)
expect(vertex.hasEdge(edgeA)).not.toBeTruthy()
})
it('should getNeighborEdge works', () => {
const vertex1 = new Vertex(1)
const edgeA = new Edge(vertex, vertex1)
vertex.addEdge(edgeA)
expect(vertex.getNeighborEdge(vertex1)).toBe(edgeA)
expect(vertex.hasNeighbor(vertex1)).toBeTruthy()
})
it('should getNeighbors works', () => {
const vertex1 = new Vertex(1)
const vertex2 = new Vertex(2)
const edgeA = new Edge(vertex, vertex1)
const edgeB = new Edge(vertex, vertex2)
expect(vertex.getNeighbors()).toStrictEqual([])
vertex.addEdge(edgeA)
vertex.addEdge(edgeB)
const neighbors = vertex.getNeighbors()
expect(neighbors.length).toBe(2)
expect(neighbors[0]).toEqual(vertex1)
expect(neighbors[1]).toEqual(vertex2)
})
})