Files
Carlos Rafael 00e40e6f06 Fix/code smells (#1338)
* ♻️ refactor: improving and fixing some code

* Updated Documentation in README.md

* ♻️ refactor: improving isLeapYear

* 🐛 chore: back changes

* 🐛 fix: using reduce instead forEach

* 🐛 fix: using reduce instead forEach

* 🐛 fix: removing duplicated code

* 🐛 chore: removing .js

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2023-08-21 23:36:43 +05:30

40 lines
942 B
JavaScript

import { Graph } from '../Graph2'
describe('Test Graph2', () => {
const vertices = ['A', 'B', 'C', 'D', 'E', 'F']
const graph = new Graph(vertices.length)
// adding vertices
vertices.forEach((vertice) => graph.addVertex(vertice))
// adding edges
graph.addEdge('A', 'B')
graph.addEdge('A', 'D')
graph.addEdge('A', 'E')
graph.addEdge('B', 'C')
graph.addEdge('D', 'E')
graph.addEdge('E', 'F')
graph.addEdge('E', 'C')
graph.addEdge('C', 'F')
it('Check adjacency lists', () => {
const mockFn = jest.fn()
graph.printGraph(mockFn)
// Expect one call per vertex
expect(mockFn.mock.calls.length).toBe(vertices.length)
// Collect adjacency lists from output (call args)
const adjListArr = mockFn.mock.calls.map((v) => v[0])
expect(adjListArr).toEqual([
'A -> B D E ',
'B -> A C ',
'C -> B E F ',
'D -> A E ',
'E -> A D F C ',
'F -> E C '
])
})
})