From cbb64e8ab441750535ced849154f16df4add8d78 Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Sat, 16 Feb 2019 20:24:03 -0600 Subject: Build heap done! 1. Modifying code so it's easy to test is always worth it! Easier to identify the next concrete steps and carry them out! 2. Hand build a few arrays helped my understanding. --- src/test/BuildHeapTest.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/test/BuildHeapTest.java (limited to 'src/test') diff --git a/src/test/BuildHeapTest.java b/src/test/BuildHeapTest.java new file mode 100644 index 0000000..59b1711 --- /dev/null +++ b/src/test/BuildHeapTest.java @@ -0,0 +1,28 @@ +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +class BuildHeapTest { + @Test + void test1() { + int[] data = {5, 4, 3, 2, 1}; + List swaps = BuildHeap.getSwaps(data); + assertEquals(3, swaps.size()); + assertEquals(1, swaps.get(0).index1); + assertEquals(4, swaps.get(0).index2); + assertEquals(0, swaps.get(1).index1); + assertEquals(1, swaps.get(1).index2); + assertEquals(1, swaps.get(2).index1); + assertEquals(3, swaps.get(2).index2); + } + + @Test + void test2() { + int[] data = {1, 2, 3, 4, 5}; + List swaps = BuildHeap.getSwaps(data); + assertEquals(0, swaps.size()); + } + +} \ No newline at end of file -- cgit v1.2.3