diff --git a/src/tests/gitlab/ckpt2/Ckpt2Tests.java b/src/tests/gitlab/ckpt2/Ckpt2Tests.java index 059f2f23d0467eb8c1c2c100b66965d7fba0af64..751e8e9fb8490169ffa823d87427dac0c5b8b3a2 100644 --- a/src/tests/gitlab/ckpt2/Ckpt2Tests.java +++ b/src/tests/gitlab/ckpt2/Ckpt2Tests.java @@ -11,7 +11,10 @@ public class Ckpt2Tests extends GradingUtility { return new Class<?>[] { AVLTreeTests.class, HashTableTests.class, - CircularArrayHashCodeTests.class + CircularArrayHashCodeTests.class, + QuickSortTests.class, + TopKSortTests.class, + HeapSortTests.class }; } } diff --git a/src/tests/gitlab/ckpt2/HeapSortTests.java b/src/tests/gitlab/ckpt2/HeapSortTests.java new file mode 100644 index 0000000000000000000000000000000000000000..1752dfe77f053991397d59882507cf99f5460461 --- /dev/null +++ b/src/tests/gitlab/ckpt2/HeapSortTests.java @@ -0,0 +1,40 @@ +package tests.gitlab.ckpt2; + +import p2.sorts.HeapSort; +import tests.TestsUtility; + +public class HeapSortTests extends TestsUtility { + public static void main(String[] args) { + new HeapSortTests().run(); + } + + @Override + protected void run() { + SHOW_TESTS = true; + test("integer_sorted"); + test("integer_random"); + finish(); + } + + public static int integer_sorted() { + Integer[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + Integer[] arr_sorted = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + HeapSort.sort(arr, (i1, i2) -> i1.compareTo(i2)); + for(int i = 0; i < arr.length; i++) { + if(!arr[i].equals(arr_sorted[i])) + return 0; + } + return 1; + } + + public static int integer_random() { + Integer[] arr = {3, 1, 4, 5, 9, 2, 6, 7, 8}; + Integer[] arr_sorted = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + HeapSort.sort(arr, (i1, i2) -> i1.compareTo(i2)); + for(int i = 0; i < arr.length; i++) { + if(!arr[i].equals(arr_sorted[i])) + return 0; + } + return 1; + } +} diff --git a/src/tests/gitlab/ckpt2/QuickSortTests.java b/src/tests/gitlab/ckpt2/QuickSortTests.java new file mode 100644 index 0000000000000000000000000000000000000000..d41bb85c10f74337075c35f9b4426dfc5d5830dd --- /dev/null +++ b/src/tests/gitlab/ckpt2/QuickSortTests.java @@ -0,0 +1,52 @@ +package tests.gitlab.ckpt2; + +import java.util.Comparator; + +import p2.sorts.QuickSort; +import tests.TestsUtility; + +public class QuickSortTests extends TestsUtility { + public static void main(String[] args) { + new QuickSortTests().run(); + } + + @Override + protected void run() { + SHOW_TESTS = true; + test("integer_sorted"); + test("integer_random"); + finish(); + } + + public static int integer_sorted() { + Integer[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + Integer[] arr_sorted = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + QuickSort.sort(arr, new Comparator<Integer>() { + @Override + public int compare(Integer e1, Integer e2) { + return e1.compareTo(e2); + } + }); + for(int i = 0; i < arr.length; i++) { + if(!arr[i].equals(arr_sorted[i])) + return 0; + } + return 1; + } + + public static int integer_random() { + Integer[] arr = {3, 1, 4, 5, 9, 2, 6, 7, 8}; + Integer[] arr_sorted = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + QuickSort.sort(arr, new Comparator<Integer>() { + @Override + public int compare(Integer e1, Integer e2) { + return e1.compareTo(e2); + } + }); + for(int i = 0; i < arr.length; i++) { + if(!arr[i].equals(arr_sorted[i])) + return 0; + } + return 1; + } +} \ No newline at end of file diff --git a/src/tests/gitlab/ckpt2/TopKSortTests.java b/src/tests/gitlab/ckpt2/TopKSortTests.java new file mode 100644 index 0000000000000000000000000000000000000000..2427a3ad79247e843fc44fb6c2dc37c896d22aea --- /dev/null +++ b/src/tests/gitlab/ckpt2/TopKSortTests.java @@ -0,0 +1,54 @@ +package tests.gitlab.ckpt2; + +import java.util.Comparator; + +import p2.sorts.TopKSort; +import tests.TestsUtility; + +public class TopKSortTests extends TestsUtility { + public static void main(String[] args) { + new TopKSortTests().run(); + } + + @Override + protected void run() { + SHOW_TESTS = true; + test("integer_sorted"); + test("integer_random"); + finish(); + } + + public static int integer_sorted() { + int K = 4; + Integer[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + Integer[] arr_sorted = {7, 8, 9, 10}; + TopKSort.sort(arr, K, new Comparator<Integer>() { + @Override + public int compare(Integer e1, Integer e2) { + return e1.compareTo(e2); + } + }); + for(int i = 0; i < K; i++) { + if(!arr[i].equals(arr_sorted[i])) + return 0; + } + return 1; + } + + public static int integer_random() { + int K = 4; + Integer[] arr = {3, 1, 4, 5, 9, 2, 6, 7, 8}; + Integer[] arr_sorted = {6, 7, 8, 9}; + TopKSort.sort(arr, K, new Comparator<Integer>() { + @Override + public int compare(Integer e1, Integer e2) { + return e1.compareTo(e2); + } + }); + for(int i = 0; i < K; i++) { + if(!arr[i].equals(arr_sorted[i])) + return 0; + } + return 1; + } +} \ No newline at end of file