|
| 1 | +package com.thealgorithms.dynamicprogramming; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | + |
| 5 | +import java.util.stream.Stream; |
| 6 | +import org.junit.jupiter.params.ParameterizedTest; |
| 7 | +import org.junit.jupiter.params.provider.Arguments; |
| 8 | +import org.junit.jupiter.params.provider.MethodSource; |
| 9 | + |
| 10 | +public class LongestArithmeticSubsequenceTest { |
| 11 | + |
| 12 | + @ParameterizedTest |
| 13 | + @MethodSource("provideTestCases") |
| 14 | + void testGetLongestArithmeticSubsequenceLength(int[] nums, int expected) { |
| 15 | + assertEquals(expected, LongestArithmeticSubsequence.getLongestArithmeticSubsequenceLength(nums)); |
| 16 | + } |
| 17 | + |
| 18 | + private static Stream<Arguments> provideTestCases() { |
| 19 | + return Stream.of( |
| 20 | + Arguments.of(new int[] {3, 6, 9, 12, 15}, 5), |
| 21 | + Arguments.of(new int[] {1, 7, 10, 13, 14, 19}, 4), |
| 22 | + Arguments.of(new int[] {1, 2, 3, 4}, 4), |
| 23 | + Arguments.of(new int[] {}, 0), // Edge case: empty array |
| 24 | + Arguments.of(new int[] {10}, 1), // Edge case: single element |
| 25 | + Arguments.of(new int[] {9, 4, 7, 2, 10}, 3) // Random test case |
| 26 | + ); |
| 27 | + } |
| 28 | +} |
0 commit comments