Skip to content

Commit c30da65

Browse files
committed
Added testcases
1 parent c9a773d commit c30da65

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

dynamic_programming/longest_arithmetic_subsequence.py

+17-5
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,21 @@ def longest_arithmetic_subsequence(nums: list[int]) -> int:
6464
import doctest
6565

6666
doctest.testmod()
67-
# Sample test case
68-
nums = [3, 6, 9, 12]
69-
expected_length = 4
7067

71-
result = longest_arithmetic_subsequence(nums)
72-
print("Length of longest arithmetic subsequence:", result)
68+
# test cases
69+
test_cases = [
70+
([3, 6, 9, 12], 4),
71+
([3, 6, 9, 12, 15], 5),
72+
([1, 7, 10, 13, 14, 19], 4),
73+
([1, 2, 3, 4], 4),
74+
([], 0),
75+
([10], 1),
76+
([9, 4, 7, 2, 10], 3),
77+
([1, 2, 2, 2, 2, 5], 4),
78+
]
79+
80+
for nums, expected_length in test_cases:
81+
result = longest_arithmetic_subsequence(nums)
82+
print(f"Test case {nums}: Expected {expected_length}, Got {result}")
83+
assert result == expected_length, f"Test failed for input {nums}"
84+

0 commit comments

Comments
 (0)