|
| 1 | +package priorityqueue; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 5 | + |
| 6 | +import exception.EmptyQueueException; |
| 7 | +import org.junit.jupiter.api.DisplayName; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | +import org.junit.jupiter.params.ParameterizedTest; |
| 10 | +import org.junit.jupiter.params.provider.CsvSource; |
| 11 | + |
| 12 | +class PriorityQueueTest { |
| 13 | + |
| 14 | + @Test |
| 15 | + @DisplayName("우선순위_큐_초기화_테스트") |
| 16 | + void 우선순위_큐_초기화_테스트() { |
| 17 | + PriorityQueue<Character> priorityQueue = new HeapPriorityQueue<>((o1, o2) -> o2 - o1); |
| 18 | + |
| 19 | + assertThat(priorityQueue).isNotNull(); |
| 20 | + } |
| 21 | + |
| 22 | + @ParameterizedTest |
| 23 | + @CsvSource({"'A','B','C'"}) |
| 24 | + @DisplayName("우선순위_큐_저장_테스트") |
| 25 | + void 우선순위_큐_저장_테스트(char firstElem, char secondElem, char thirdElem) { |
| 26 | + PriorityQueue<Character> charHeap = new HeapPriorityQueue<>((o1, o2) -> o2 - o1); |
| 27 | + |
| 28 | + charHeap.enqueue(firstElem); |
| 29 | + charHeap.enqueue(secondElem); |
| 30 | + charHeap.enqueue(thirdElem); |
| 31 | + |
| 32 | + assertThat(charHeap).isNotNull(); |
| 33 | + assertThat(charHeap.isEmpty()).isFalse(); |
| 34 | + } |
| 35 | + |
| 36 | + @ParameterizedTest |
| 37 | + @CsvSource({"'A','B','C'"}) |
| 38 | + @DisplayName("우선순위_큐_저장_후_제거_테스트") |
| 39 | + void 우선순위_큐_저장_후_제거_테스트(char firstElem, char secondElem, char thirdElem) { |
| 40 | + PriorityQueue<Character> charHeap = new HeapPriorityQueue<>((o1, o2) -> o2 - o1); |
| 41 | + |
| 42 | + charHeap.enqueue(firstElem); |
| 43 | + charHeap.enqueue(secondElem); |
| 44 | + charHeap.enqueue(thirdElem); |
| 45 | + |
| 46 | + assertThat(charHeap).isNotNull(); |
| 47 | + assertThat(charHeap.isEmpty()).isFalse(); |
| 48 | + assertThat(charHeap.dequeue()).isEqualTo(firstElem); |
| 49 | + assertThat(charHeap.dequeue()).isEqualTo(secondElem); |
| 50 | + assertThat(charHeap.dequeue()).isEqualTo(thirdElem); |
| 51 | + assertThat(charHeap.isEmpty()).isTrue(); |
| 52 | + } |
| 53 | + |
| 54 | + @ParameterizedTest |
| 55 | + @CsvSource({"'A','B','C'"}) |
| 56 | + @DisplayName("우선순위_큐_사용_테스트") |
| 57 | + void 우선순위_큐_사용_테스트(char firstElem, char secondElem, char thirdElem) { |
| 58 | + PriorityQueue<Character> charHeap = new HeapPriorityQueue<>((o1, o2) -> o2 - o1); |
| 59 | + |
| 60 | + charHeap.enqueue(firstElem); |
| 61 | + charHeap.enqueue(secondElem); |
| 62 | + charHeap.enqueue(thirdElem); |
| 63 | + |
| 64 | + assertThat(charHeap.dequeue()).isEqualTo('A'); |
| 65 | + |
| 66 | + charHeap.enqueue(firstElem); |
| 67 | + charHeap.enqueue(secondElem); |
| 68 | + charHeap.enqueue(thirdElem); |
| 69 | + |
| 70 | + assertThat(charHeap).isNotNull(); |
| 71 | + assertThat(charHeap.isEmpty()).isFalse(); |
| 72 | + assertThat(charHeap.dequeue()).isEqualTo(firstElem); |
| 73 | + assertThat(charHeap.dequeue()).isEqualTo(secondElem); |
| 74 | + assertThat(charHeap.dequeue()).isEqualTo(secondElem); |
| 75 | + assertThat(charHeap.dequeue()).isEqualTo(thirdElem); |
| 76 | + assertThat(charHeap.dequeue()).isEqualTo(thirdElem); |
| 77 | + assertThat(charHeap.isEmpty()).isTrue(); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + @DisplayName("우선순위_큐_제거시_에러_테스트") |
| 82 | + void 우선순위_큐_제거시_에러_테스트() { |
| 83 | + PriorityQueue<Character> charHeap = new HeapPriorityQueue<>((o1, o2) -> o2 - o1); |
| 84 | + |
| 85 | + assertThat(charHeap).isNotNull(); |
| 86 | + assertThatThrownBy(charHeap::dequeue).isInstanceOf(EmptyQueueException.class); |
| 87 | + assertThat(charHeap.isEmpty()).isTrue(); |
| 88 | + } |
| 89 | +} |
0 commit comments