Skip to content

Commit 93273c4

Browse files
committed
two-sum: add test cases
1 parent 8c61285 commit 93273c4

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

two-sum/gyeo-ri.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,22 @@ def twoSum(self, nums: list[int], target: int) -> list[int]:
88
return [idx1, idx1 + idx2 + 1]
99

1010
raise Exception("Invalid nums and target")
11+
12+
13+
if __name__ == "__main__":
14+
test_cases = [
15+
([2, 7, 11, 15], 9, [0, 1]),
16+
([3, 2, 4], 6, [1, 2]),
17+
([3, 3], 6, [0, 1]),
18+
([-2, -3, 0, 3], 1, [0, 3]),
19+
([0, -5, 2, 6], -3, [1, 2]),
20+
([4, 7, 2, 0, 0], 0, [3, 4]),
21+
]
22+
23+
solution = Solution()
24+
for idx, case_ in enumerate(test_cases):
25+
nums, target, answer = case_
26+
result = solution.twoSum(nums, target)
27+
assert (
28+
answer == result
29+
), f"Test Case {idx} Failed: Expected {answer}, Got {result}"

0 commit comments

Comments
 (0)