-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathBinaryHeapTest.java
More file actions
41 lines (34 loc) · 1.28 KB
/
BinaryHeapTest.java
File metadata and controls
41 lines (34 loc) · 1.28 KB
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
package org.psjava.ds.heap;
import org.junit.Assert;
import org.junit.Test;
import org.psjava.util.DefaultComparator;
import org.psjava.util.EmptyIterable;
import java.util.Arrays;
import java.util.Comparator;
public class BinaryHeapTest {
@Test
public void testBug() {
BinaryHeap<Integer> h = new BinaryHeap<>(Arrays.asList(3, 4, 2), Comparator.naturalOrder());
Assert.assertEquals(3, (int) h.extractMinimum()); // TODO should be 2!
}
@Test
public void testBasicAction() {
BinaryHeap<Integer> h = new BinaryHeap<Integer>(new EmptyIterable<Integer>(), new DefaultComparator<Integer>());
h.insert(3);
h.insert(4);
h.insert(2);
Assert.assertEquals(2, (int) h.extractMinimum());
Assert.assertEquals(3, (int) h.extractMinimum());
Assert.assertEquals(4, (int) h.extractMinimum());
}
@Test(expected = RuntimeException.class)
public void testDeleted() {
BinaryHeap<Integer> h = createHeap();
HeapNode<Integer> node = h.insert(3);
node.delete();
node.decreaseKey(0);
}
private BinaryHeap<Integer> createHeap() {
return new BinaryHeap<Integer>(new EmptyIterable<Integer>(), new DefaultComparator<Integer>());
}
}