|
| 1 | +package heap; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.DisplayName; |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | +import org.junit.jupiter.params.ParameterizedTest; |
| 8 | +import org.junit.jupiter.params.provider.CsvSource; |
| 9 | + |
| 10 | +class UsefulHeapTest { |
| 11 | + |
| 12 | + @Test |
| 13 | + @DisplayName("쓸만한_힙의_초기화_테스트") |
| 14 | + void 쓸만한_힙의_초기화_테스트() { |
| 15 | + UsefulHeap<Character> charHeap = new ArrayUsefulHeap<>((o1, o2) -> o2 - o1); |
| 16 | + |
| 17 | + assertThat(charHeap).isNotNull(); |
| 18 | + assertThat(charHeap.isEmpty()).isTrue(); |
| 19 | + } |
| 20 | + |
| 21 | + @ParameterizedTest |
| 22 | + @CsvSource({"'A','B','C'"}) |
| 23 | + @DisplayName("쓸만한_힙_저장_테스트") |
| 24 | + void 쓸만한_힙_저장_테스트(char firstElem, char secondElem, char thirdElem) { |
| 25 | + UsefulHeap<Character> charHeap = new ArrayUsefulHeap<>((o1, o2) -> o2 - o1); |
| 26 | + |
| 27 | + charHeap.insert(firstElem); |
| 28 | + charHeap.insert(secondElem); |
| 29 | + charHeap.insert(thirdElem); |
| 30 | + |
| 31 | + assertThat(charHeap).isNotNull(); |
| 32 | + assertThat(charHeap.isEmpty()).isFalse(); |
| 33 | + } |
| 34 | + |
| 35 | + @ParameterizedTest |
| 36 | + @CsvSource({"'A','B','C'"}) |
| 37 | + @DisplayName("쓸만한_힙_저장_후_제거_테스트") |
| 38 | + void 쓸만한_힙_저장_후_제거_테스트(char firstElem, char secondElem, char thirdElem) { |
| 39 | + UsefulHeap<Character> charHeap = new ArrayUsefulHeap<>((o1, o2) -> o2 - o1); |
| 40 | + |
| 41 | + charHeap.insert(firstElem); |
| 42 | + charHeap.insert(secondElem); |
| 43 | + charHeap.insert(thirdElem); |
| 44 | + |
| 45 | + assertThat(charHeap).isNotNull(); |
| 46 | + assertThat(charHeap.isEmpty()).isFalse(); |
| 47 | + assertThat(charHeap.delete()).isEqualTo(firstElem); |
| 48 | + assertThat(charHeap.delete()).isEqualTo(secondElem); |
| 49 | + assertThat(charHeap.delete()).isEqualTo(thirdElem); |
| 50 | + assertThat(charHeap.isEmpty()).isTrue(); |
| 51 | + } |
| 52 | + |
| 53 | + @ParameterizedTest |
| 54 | + @CsvSource({"'A','B','C'"}) |
| 55 | + @DisplayName("쓸만한_힙_사용_테스트") |
| 56 | + void 쓸만한_힙_사용_테스트(char firstElem, char secondElem, char thirdElem) { |
| 57 | + UsefulHeap<Character> charHeap = new ArrayUsefulHeap<>((o1, o2) -> o2 - o1); |
| 58 | + |
| 59 | + charHeap.insert(firstElem); |
| 60 | + charHeap.insert(secondElem); |
| 61 | + charHeap.insert(thirdElem); |
| 62 | + |
| 63 | + assertThat(charHeap.delete()).isEqualTo('A'); |
| 64 | + |
| 65 | + charHeap.insert(firstElem); |
| 66 | + charHeap.insert(secondElem); |
| 67 | + charHeap.insert(thirdElem); |
| 68 | + |
| 69 | + assertThat(charHeap).isNotNull(); |
| 70 | + assertThat(charHeap.isEmpty()).isFalse(); |
| 71 | + assertThat(charHeap.delete()).isEqualTo(firstElem); |
| 72 | + assertThat(charHeap.delete()).isEqualTo(secondElem); |
| 73 | + assertThat(charHeap.delete()).isEqualTo(secondElem); |
| 74 | + assertThat(charHeap.delete()).isEqualTo(thirdElem); |
| 75 | + assertThat(charHeap.delete()).isEqualTo(thirdElem); |
| 76 | + assertThat(charHeap.isEmpty()).isTrue(); |
| 77 | + } |
| 78 | +} |
0 commit comments