-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmax-binary-heap.test.js
More file actions
37 lines (27 loc) · 951 Bytes
/
Copy pathmax-binary-heap.test.js
File metadata and controls
37 lines (27 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import test from 'ava'
import MaxBinaryHeap from './max-binary-heap'
test(`Should create empty MaxBinaryHeap`, t => {
const maxBinaryHeap = new MaxBinaryHeap()
t.is(maxBinaryHeap.values.length, 0)
})
//===
//Test Input
/**
* 41
* 39 33
* 18 27 12
*
*/
test(`Should insert a new element into MaxBinaryHeap with insert(val)`, t => {
const maxBinaryHeap = new MaxBinaryHeap()
maxBinaryHeap.values = [41, 39, 33, 18, 27, 12]
maxBinaryHeap.insert(55)
t.is(JSON.stringify(maxBinaryHeap.values), JSON.stringify([55, 39, 41, 18, 27, 12, 33]))
t.is(maxBinaryHeap.values.length, 7)
})
test(`Should extract max element and then sink-down the heap with extractMax()`, t => {
const maxBinaryHeap = new MaxBinaryHeap()
maxBinaryHeap.values = [55, 39, 41, 18, 27, 12, 33]
t.is(maxBinaryHeap.extractMax(), 55)
t.is(JSON.stringify(maxBinaryHeap.values), JSON.stringify([41, 39, 33, 18, 27, 12]))
})