-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.spec.ts
51 lines (41 loc) · 1.19 KB
/
index.spec.ts
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { beforeEach, describe, expect, test } from 'bun:test'
import { BinaryHeapMin } from './index'
describe('BinaryHeap', () => {
let heap: BinaryHeapMin
beforeEach(() => {
heap = new BinaryHeapMin()
})
test('should insert elements and maintain heap property', () => {
heap.insert(10)
heap.insert(20)
heap.insert(5)
heap.insert(15)
expect(heap.peek()).toBe(5)
})
test('should remove the minimum element and maintain heap property', () => {
heap.insert(10)
heap.insert(20)
heap.insert(5)
heap.insert(15)
expect(heap.remove()).toBe(5)
expect(heap.peek()).toBe(10)
})
test('should handle removing from an empty heap', () => {
expect(heap.remove()).toBeUndefined()
})
test('should handle peeking into an empty heap', () => {
expect(heap.peek()).toBeUndefined()
})
test('should maintain heap property after multiple insertions and removals', () => {
heap.insert(10)
heap.insert(20)
heap.insert(5)
heap.insert(15)
heap.insert(1)
expect(heap.remove()).toBe(1)
expect(heap.remove()).toBe(5)
expect(heap.remove()).toBe(10)
expect(heap.remove()).toBe(15)
expect(heap.remove()).toBe(20)
})
})