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
This commit is contained in:
paulinegarelli
2023-02-23 15:35:45 +01:00
committed by GitHub
parent 0c427580f1
commit 566d9103cd
4 changed files with 301 additions and 154 deletions

View File

@@ -0,0 +1,20 @@
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)
})