mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 00:01:37 +08:00

* 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
21 lines
664 B
JavaScript
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)
|
|
})
|