Files
JavaScript/Graphs/test/PrimMST.test.js
paulinegarelli 566d9103cd fix: refactor PrimMST and fix bug in PriorityQueue (#1300)
* ref: KeyPriorityQueue in separate  file #1298

* feat: add tests for KeyPriorityQueue #1298

* fix: _shiftDown refactored and corrected #1298

* fix: use KeyPriorityQueue in PrimMST #1298

* feat: add test for PrimMST #1298

* fix: format files #1298

* fix: minor coding style changes

* fix: use map for keys and priorities #1298
2023-02-23 20:05:45 +05:30

21 lines
664 B
JavaScript

import { GraphWeightedUndirectedAdjacencyList } from '../PrimMST.js'
test('Test Case PrimMST 1', () => {
// create graph to compute MST on
const graph = new GraphWeightedUndirectedAdjacencyList()
graph.addEdge(1, 2, 1)
graph.addEdge(2, 3, 2)
graph.addEdge(3, 4, 1)
graph.addEdge(3, 5, 100) // Removed in MST
graph.addEdge(4, 5, 5)
// create expected graph
const expectedGraph = new GraphWeightedUndirectedAdjacencyList()
expectedGraph.addEdge(1, 2, 1)
expectedGraph.addEdge(2, 3, 2)
expectedGraph.addEdge(3, 4, 1)
expectedGraph.addEdge(4, 5, 5)
// result from MST
const res = graph.PrimMST(1)
expect(res).toEqual(expectedGraph)
})