-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestDomesticPQ.java
69 lines (57 loc) · 1.98 KB
/
TestDomesticPQ.java
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.ttahb.graph;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.stream.IntStream;
import static org.junit.jupiter.api.Assertions.*;
/**
* This class tests heapify, insert, poll, peek, delete in a priority queue.
* @author - Vijay Bhatt - bhattvijay69@hotmail.com
*/
public class TestDomesticPQ {
private static int[] array = {3,7,9,5,2,8,1};
private static Integer[] testArray;
@BeforeAll
public static void initialize(){
testArray = Arrays.stream(array).boxed().toArray(Integer[]::new);
}
/**
* 3 1
* / \ / \
* 7 9 = > 2 3
* / \ / \ / \ / \
* 5 2 8 1 5 7 8 9
*/
@Test
public void testHeapify(){
DomesticPQ domesticPQ = new DomesticPQ(testArray);
assertEquals(Arrays.asList(1,2,3,5,7,8,9),domesticPQ.getHeap());
}
@Test
public void testInsert(){
DomesticPQ domesticPQ = new DomesticPQ(testArray);
domesticPQ.insert(0);
assertEquals(0,domesticPQ.peek());
domesticPQ.insert(10);
assertEquals(Arrays.asList(0,1,3,2,7,8,9,5,10),domesticPQ.getHeap());
}
@Test
public void testPoll(){
DomesticPQ domesticPQ = new DomesticPQ(testArray);
assertEquals(1,domesticPQ.poll());
assertEquals(2,domesticPQ.poll());
assertEquals(3,domesticPQ.poll());
assertEquals(5,domesticPQ.poll());
assertEquals(7,domesticPQ.poll());
assertEquals(8,domesticPQ.poll());
assertEquals(9,domesticPQ.poll());
assertEquals(null,domesticPQ.poll());
}
@Test
public void testDelete(){
DomesticPQ domesticPQ = new DomesticPQ(testArray);
assertTrue(domesticPQ.delete(2));
assertEquals(Arrays.asList(1,5,3,9,7,8),domesticPQ.getHeap());
}
}