SolutionTest.java 1013 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package leetcode.p53;
  2. import org.junit.Test;
  3. import org.junit.runner.RunWith;
  4. import org.junit.runners.Parameterized;
  5. import java.util.Arrays;
  6. import java.util.Collection;
  7. import static org.junit.Assert.assertEquals;
  8. /**
  9. * @ProjectName: LeetCode
  10. * @FileName: SolutionTest
  11. * @Author: 杨逸
  12. * @Data:2026/3/23 22:40
  13. * @Description:
  14. */
  15. @RunWith(Parameterized.class)
  16. public class SolutionTest {
  17. public static final Solution solution = new Solution();
  18. private int[] nums;
  19. private int expected;
  20. public SolutionTest(int[] nums, int expected) {
  21. this.nums = nums;
  22. this.expected = expected;
  23. }
  24. @Parameterized.Parameters
  25. public static Collection<Object[]> data() {
  26. return Arrays.asList(new Object[][]{
  27. {new int[]{-2,1,-3,4,-1,2,1,-5,4},6},
  28. {new int[]{1},1},
  29. {new int[]{5,4,-1,7,8},23},
  30. });
  31. }
  32. @Test
  33. public void maxSubArray() {
  34. assertEquals(expected,solution.maxSubArray(nums));
  35. }
  36. }