mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 14:34:05 +08:00
* Enhance Minimum sum partition problem implementation * Linter resolved * Linter resolved * Code review comments * Code review comments * Add validation for non-negative numbers * Linter resolved * style: fix formiatting --------- Co-authored-by: Piotr Idzik <65706193+vil02@users.noreply.github.com>
This commit is contained in:
@ -0,0 +1,44 @@
|
||||
package com.thealgorithms.dynamicprogramming;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class MinimumSumPartitionTest {
|
||||
@Test
|
||||
public void testMinimumSumPartitionWithEvenSum() {
|
||||
int[] array = {1, 6, 11, 4};
|
||||
assertEquals(0, MinimumSumPartition.minimumSumPartition(array));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimumSumPartitionWithOddSum() {
|
||||
int[] array = {36, 7, 46, 40};
|
||||
assertEquals(23, MinimumSumPartition.minimumSumPartition(array));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimumSumPartitionWithSingleElement() {
|
||||
int[] array = {7};
|
||||
assertEquals(7, MinimumSumPartition.minimumSumPartition(array));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimumSumPartitionWithLargeNumbers() {
|
||||
int[] array = {100, 200, 300, 400, 500};
|
||||
assertEquals(100, MinimumSumPartition.minimumSumPartition(array));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimumSumPartitionWithEmptyArray() {
|
||||
int[] array = {};
|
||||
assertEquals(0, MinimumSumPartition.minimumSumPartition(array));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimumSumPartitionThrowsForNegativeArray() {
|
||||
int[] array = {4, 1, -6, 7};
|
||||
assertThrows(IllegalArgumentException.class, () -> { MinimumSumPartition.minimumSumPartition(array); });
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user