import org.junit.Assert; import org.junit.Test; public class SimpleTest { @Test public void test0() { Partitioner solution = new MyPartitioner(); int[] list = new int[]{5,3,1,4,1}; int[] partition = solution.partition(list, 1); Assert.assertArrayEquals(new int[]{5}, partition); } @Test public void test1() { Partitioner solution = new MyPartitioner(); int[] list = new int[]{2,3,4,4}; int[] partition = solution.partition(list, 2); Assert.assertArrayEquals(new int[]{2,4}, partition); } @Test public void test2() { Partitioner solution = new MyPartitioner(); int[] list = new int[]{100,200,300,200,200,400,200}; int[] partition = solution.partition(list, 3); Assert.assertArrayEquals(new int[]{3,5,7}, partition); } @Test public void test3() { Partitioner solution = new MyPartitioner(); int[] list = new int[]{1,2,2,1,2,3,6}; int[] partition = solution.partition(list, 3); Assert.assertEquals(3, partition.length); Assert.assertEquals(7, partition[2]); Assert.assertEquals(6, partition[1]); Assert.assertTrue(partition[0] == 3 || partition[0] == 4); } @Test public void test4() { Partitioner solution = new MyPartitioner(); int[] list = new int[]{2,3,6,1,1,3,2,3}; int[] partition = solution.partition(list, 4); Assert.assertArrayEquals(new int[]{2,3,6,8}, partition); } @Test public void test5() { Partitioner solution = new MyPartitioner(); int[] list = new int[]{3,5,2,3,4,6,2,2,1,5,1,6}; int[] partition = solution.partition(list, 5); Assert.assertEquals(5, partition.length); checkSolution(list, partition, 9); } @Test public void largerTest(){ Partitioner solution = new MyPartitioner(); int[] list = new int[]{94, 38, 82, 1, 69, 78, 9, 71, 14, 67, 4, 58, 56, 51, 97}; int[] partition = solution.partition(list, 4); Assert.assertEquals(4, partition.length); checkSolution(list, partition, 214); } void checkSolution(int[] list, int[] partition, int maxSum){ int start = 0; for(int end: partition){ int sum = 0; for (int i = start; i < end; i++) { sum += list[i]; } Assert.assertTrue(String.format("Solution not optimal: %d possible, but was %d.", maxSum, sum), sum <= maxSum); start = end; } } }