-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete-tests.js
More file actions
28 lines (26 loc) · 884 Bytes
/
delete-tests.js
File metadata and controls
28 lines (26 loc) · 884 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
'use strict';
module.exports.run = function (test, Heap) {
test('should delete the head of the heap', function (t) {
var heap = new Heap();
var node1 = heap.insert(1, null);
var node2 = heap.insert(2, null);
heap.delete(node1);
t.is(heap.extractMinimum(), node2);
t.true(heap.isEmpty());
});
test('should delete nodes in a heap with multiple elements', function (t) {
var heap = new Heap();
var node3 = heap.insert(13, null);
var node4 = heap.insert(26, null);
var node2 = heap.insert(3, null);
var node1 = heap.insert(-6, null);
var node5 = heap.insert(27, null);
t.is(heap.size(), 5);
t.is(heap.extractMinimum(), node1);
t.is(heap.extractMinimum(), node2);
t.is(heap.extractMinimum(), node3);
t.is(heap.extractMinimum(), node4);
t.is(heap.extractMinimum(), node5);
t.true(heap.isEmpty());
});
};