Merge branch 'master' of https://github.com/eugenp/tutorials into BAEL-9635
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package com.baeldung.heapsort;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class HeapUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenNotEmptyHeap_whenPopCalled_thenItShouldReturnSmallestElement() {
|
||||
// given
|
||||
Heap<Integer> heap = Heap.of(3, 5, 1, 4, 2);
|
||||
|
||||
// when
|
||||
int head = heap.pop();
|
||||
|
||||
// then
|
||||
assertThat(head).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNotEmptyIterable_whenSortCalled_thenItShouldReturnElementsInSortedList() {
|
||||
// given
|
||||
List<Integer> elements = Arrays.asList(3, 5, 1, 4, 2);
|
||||
|
||||
// when
|
||||
List<Integer> sortedElements = Heap.sort(elements);
|
||||
|
||||
// then
|
||||
assertThat(sortedElements).isEqualTo(Arrays.asList(1, 2, 3, 4, 5));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user