From 83aab0e079ce72422da13b45de5aaf0eecd558c9 Mon Sep 17 00:00:00 2001 From: iMichael02 <73227939+iMichael02@users.noreply.github.com> Date: Tue, 31 May 2022 21:36:53 +0700 Subject: [PATCH 1/5] Check partition method --- .../pedrovgs/problem80/PartitionTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/test/java/com/github/pedrovgs/problem80/PartitionTest.java diff --git a/src/test/java/com/github/pedrovgs/problem80/PartitionTest.java b/src/test/java/com/github/pedrovgs/problem80/PartitionTest.java new file mode 100644 index 00000000..ffec3015 --- /dev/null +++ b/src/test/java/com/github/pedrovgs/problem80/PartitionTest.java @@ -0,0 +1,22 @@ +package com.github.pedrovgs.problem80; + +import static org.junit.Assert.assertTrue; + +import org.junit.jupiter.api.Test; + +import com.github.pedrovgs.sortingalgorithm.SortingAlgorithm; +import com.github.pedrovgs.sortingalgorithms.SortingAlgorithmTest; + +/** + * @author jsroyal. + */ +public class PartitionTest { + + @Test + public void testPartition() { + int[] arr = {2,4,7,3,9,1,8}; + QuickSort quickSortObject = new QuickSort(); + assertTrue("partition incorrect", 5 == quickSortObject.partition(arr, 0, 6)); + } + +} \ No newline at end of file From 9b6d7dcac1fe24ef293a3ed0b8f0c47a96245106 Mon Sep 17 00:00:00 2001 From: iMichael02 <73227939+iMichael02@users.noreply.github.com> Date: Tue, 31 May 2022 21:38:51 +0700 Subject: [PATCH 2/5] Delete PartitionTest.java --- .../pedrovgs/problem80/PartitionTest.java | 22 ------------------- 1 file changed, 22 deletions(-) delete mode 100644 src/test/java/com/github/pedrovgs/problem80/PartitionTest.java diff --git a/src/test/java/com/github/pedrovgs/problem80/PartitionTest.java b/src/test/java/com/github/pedrovgs/problem80/PartitionTest.java deleted file mode 100644 index ffec3015..00000000 --- a/src/test/java/com/github/pedrovgs/problem80/PartitionTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.pedrovgs.problem80; - -import static org.junit.Assert.assertTrue; - -import org.junit.jupiter.api.Test; - -import com.github.pedrovgs.sortingalgorithm.SortingAlgorithm; -import com.github.pedrovgs.sortingalgorithms.SortingAlgorithmTest; - -/** - * @author jsroyal. - */ -public class PartitionTest { - - @Test - public void testPartition() { - int[] arr = {2,4,7,3,9,1,8}; - QuickSort quickSortObject = new QuickSort(); - assertTrue("partition incorrect", 5 == quickSortObject.partition(arr, 0, 6)); - } - -} \ No newline at end of file From a201daf21a4a1a37a9829c7d609d89073eb25ad8 Mon Sep 17 00:00:00 2001 From: iMichael02 <73227939+iMichael02@users.noreply.github.com> Date: Tue, 31 May 2022 21:39:39 +0700 Subject: [PATCH 3/5] Check partition method --- .../pedrovgs/problem80/PartitionTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/test/java/com/github/pedrovgs/problem80/PartitionTest.java diff --git a/src/test/java/com/github/pedrovgs/problem80/PartitionTest.java b/src/test/java/com/github/pedrovgs/problem80/PartitionTest.java new file mode 100644 index 00000000..9b99816d --- /dev/null +++ b/src/test/java/com/github/pedrovgs/problem80/PartitionTest.java @@ -0,0 +1,19 @@ +package com.github.pedrovgs.problem80; + +import static org.junit.Assert.assertTrue; + +import org.junit.jupiter.api.Test; + +import com.github.pedrovgs.sortingalgorithm.SortingAlgorithm; +import com.github.pedrovgs.sortingalgorithms.SortingAlgorithmTest; + +public class PartitionTest { + + @Test + public void testPartition() { + int[] arr = {2,4,7,3,9,1,8}; + QuickSort quickSortObject = new QuickSort(); + assertTrue("partition incorrect", 5 == quickSortObject.partition(arr, 0, 6)); + } + +} \ No newline at end of file From 040a7a942e40f973d848e7dbc5c2996ab5af88ac Mon Sep 17 00:00:00 2001 From: iMichael02 <73227939+iMichael02@users.noreply.github.com> Date: Wed, 1 Jun 2022 09:05:20 +0700 Subject: [PATCH 4/5] Remove spacing --- .../java/com/github/pedrovgs/problem80/PartitionTest.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/test/java/com/github/pedrovgs/problem80/PartitionTest.java b/src/test/java/com/github/pedrovgs/problem80/PartitionTest.java index 9b99816d..7d282db9 100644 --- a/src/test/java/com/github/pedrovgs/problem80/PartitionTest.java +++ b/src/test/java/com/github/pedrovgs/problem80/PartitionTest.java @@ -1,19 +1,15 @@ package com.github.pedrovgs.problem80; import static org.junit.Assert.assertTrue; - import org.junit.jupiter.api.Test; - import com.github.pedrovgs.sortingalgorithm.SortingAlgorithm; import com.github.pedrovgs.sortingalgorithms.SortingAlgorithmTest; public class PartitionTest { - @Test public void testPartition() { int[] arr = {2,4,7,3,9,1,8}; QuickSort quickSortObject = new QuickSort(); assertTrue("partition incorrect", 5 == quickSortObject.partition(arr, 0, 6)); } - -} \ No newline at end of file +} From b710d14cac490a1d868a55216e02e41ce58416f2 Mon Sep 17 00:00:00 2001 From: iMichael02 <73227939+iMichael02@users.noreply.github.com> Date: Tue, 14 Jun 2022 11:56:53 +0700 Subject: [PATCH 5/5] Add partitioning with more test cases --- .../pedrovgs/problem80/PartitionTest.java | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/github/pedrovgs/problem80/PartitionTest.java b/src/test/java/com/github/pedrovgs/problem80/PartitionTest.java index 7d282db9..4203f12d 100644 --- a/src/test/java/com/github/pedrovgs/problem80/PartitionTest.java +++ b/src/test/java/com/github/pedrovgs/problem80/PartitionTest.java @@ -2,14 +2,56 @@ import static org.junit.Assert.assertTrue; import org.junit.jupiter.api.Test; +import junit.framework.AssertionFailedError; import com.github.pedrovgs.sortingalgorithm.SortingAlgorithm; import com.github.pedrovgs.sortingalgorithms.SortingAlgorithmTest; public class PartitionTest { @Test - public void testPartition() { + // Partition 1: array with multiple positive elements + public void testMultiplePositiveElements() { int[] arr = {2,4,7,3,9,1,8}; QuickSort quickSortObject = new QuickSort(); - assertTrue("partition incorrect", 5 == quickSortObject.partition(arr, 0, 6)); + assertTrue("Error in partition() method: array with multiple positive elements", 5 == quickSortObject.partition(arr, 0, 6)); + } + + @Test + // Partition 2: array with multiple negative elements + public void testMultipleNegativeElements() { + int[] arr = {-2,-4,-7,-3,-9,-1,-8}; + QuickSort quickSortObject = new QuickSort(); + assertTrue("Error in partition() method: array with multiple negative elements", 1 == quickSortObject.partition(arr, 0, 6)); + } + + @Test + // Partition 3: array with multiple mixed elements + public void testMultipleMixedElements() { + int[] arr = {-2,4,7,-3,-9,1,8}; + QuickSort quickSortObject = new QuickSort(); + assertTrue("Error in partition() method: array with multiple mixed elements", 6 == quickSortObject.partition(arr, 0, 6)); + } + + @Test + // Partition 4: array with no element + public void testNoElement() { + int[] arr = {}; + QuickSort quickSortObject = new QuickSort(); + try { + quickSortObject.partition(arr, 0, 0); + } catch (ArrayIndexOutOfBoundsException e){ + throw new AssertionFailedError (e.getMessage()); + } + } + + @Test + // Partition 5: array with one element + public void testOneElement() { + int[] arr = {2}; + QuickSort quickSortObject = new QuickSort(); + try { + quickSortObject.partition(arr, 0, 1); + } catch (ArrayIndexOutOfBoundsException e){ + throw new AssertionFailedError (e.getMessage()); + } } }