mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +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>
45 lines
1.4 KiB
Java
45 lines
1.4 KiB
Java
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); });
|
|
}
|
|
}
|