diff options
author | Haidong Ji | 2019-02-16 20:24:03 -0600 |
---|---|---|
committer | Haidong Ji | 2019-02-16 20:24:03 -0600 |
commit | cbb64e8ab441750535ced849154f16df4add8d78 (patch) | |
tree | bf312fe915c698ab6f2d5e41bbc75358553890f9 /src/test | |
parent | 83292a326000d1c7c5695f6cb8b8575081221cda (diff) |
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.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/BuildHeapTest.java | 28 |
1 files changed, 28 insertions, 0 deletions
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<BuildHeap.Swap> 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<BuildHeap.Swap> swaps = BuildHeap.getSwaps(data); + assertEquals(0, swaps.size()); + } + +}
\ No newline at end of file |