mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2026-03-13 15:21:15 +08:00
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:
20
Graphs/test/PrimMST.test.js
Normal file
20
Graphs/test/PrimMST.test.js
Normal 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)
|
||||
})
|
||||
Reference in New Issue
Block a user