|
| 1 | +import { MinPriorityQueue } from '../MinPriorityQueue' |
| 2 | + |
| 3 | +describe('MinPriorityQueue', () => { |
| 4 | + const values = [5, 2, 4, 1, 7, 6, 3, 8] |
| 5 | + const capacity = values.length |
| 6 | + |
| 7 | + const Queue = new MinPriorityQueue(capacity); |
| 8 | + |
| 9 | + values.forEach(v => Queue.insert(v)) |
| 10 | + |
| 11 | + it('Check heap ordering', () => { |
| 12 | + const mockFn = jest.fn() |
| 13 | + Queue.print(mockFn) |
| 14 | + |
| 15 | + expect(mockFn.mock.calls.length).toBe(1) // Expect one call |
| 16 | + expect(mockFn.mock.calls[0].length).toBe(1) // Expect one argument |
| 17 | + |
| 18 | + const heap = mockFn.mock.calls[0][0] |
| 19 | + expect(heap.length).toBe(capacity) |
| 20 | + expect(heap).toStrictEqual([1, 2, 3, 5, 7, 6, 4, 8]) |
| 21 | + }) |
| 22 | + |
| 23 | + it('heapSort() expected to reverse the heap ordering', () => { |
| 24 | + Queue.heapSort() |
| 25 | + |
| 26 | + const mockFn = jest.fn() |
| 27 | + Queue.print(mockFn) |
| 28 | + |
| 29 | + expect(mockFn.mock.calls.length).toBe(1) |
| 30 | + expect(mockFn.mock.calls[0].length).toBe(1) |
| 31 | + |
| 32 | + const heap = mockFn.mock.calls[0][0] |
| 33 | + expect(heap.length).toBe(capacity) |
| 34 | + expect(heap).toStrictEqual([8, 7, 6, 5, 4, 3, 2, 1]) |
| 35 | + }) |
| 36 | +}) |
0 commit comments