Skip to content

Commit 1b6ea02

Browse files
committed
test: add more test cases
1 parent 1a3706b commit 1b6ea02

File tree

4 files changed

+21
-39
lines changed

4 files changed

+21
-39
lines changed

.templates/leetcode/json/two_sum.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"name": "test_two_sum",
5252
"signature": "(self, nums: list[int], target: int, expected: list[int])",
5353
"parametrize": "nums, target, expected",
54-
"test_cases": "[([2, 7, 11, 15], 9, [0, 1]), ([3, 2, 4], 6, [1, 2]), ([3, 3], 6, [0, 1]), ([2, 5, 5, 11], 10, [1, 2]), ([1, 2, 3, 4, 5], 8, [2, 4]), ([0, 4, 3, 0], 0, [0, 3]), ([-1, -2, -3, -4, -5], -8, [2, 4]), ([1, 3, 4, 2], 6, [2, 3])]",
54+
"test_cases": "[([2, 7, 11, 15], 9, [0, 1]), ([3, 2, 4], 6, [1, 2]), ([3, 3], 6, [0, 1]), ([2, 5, 5, 11], 10, [1, 2]), ([1, 2, 3, 4, 5], 8, [2, 4]), ([0, 4, 3, 0], 0, [0, 3]), ([-1, -2, -3, -4, -5], -8, [2, 4]), ([1, 3, 4, 2], 6, [2, 3]), ([5, 75, 25], 100, [1, 2]), ([-3, 4, 3, 90], 0, [0, 2]), ([1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 2], 6, [5, 11]), ([2, 1, 9, 4, 4, 56, 90, 3], 8, [3, 4]), ([89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99], 185, [3, 4]), ([-1000000000, 1000000000], 0, [0, 1]), ([0, 1], 1, [0, 1]), ([1, 2], 5, []), ([3, 5, 7], 1, []), ([10, 20, 30], 15, [])]",
5555
"body": " result = run_two_sum(Solution, nums, target)\n assert_two_sum(result, expected)"
5656
}
5757
]

leetcode/two_sum/playground.ipynb

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 1,
5+
"execution_count": null,
66
"id": "imports",
77
"metadata": {},
88
"outputs": [],
@@ -13,7 +13,7 @@
1313
},
1414
{
1515
"cell_type": "code",
16-
"execution_count": 2,
16+
"execution_count": null,
1717
"id": "setup",
1818
"metadata": {},
1919
"outputs": [],
@@ -26,43 +26,21 @@
2626
},
2727
{
2828
"cell_type": "code",
29-
"execution_count": 3,
29+
"execution_count": null,
3030
"id": "run",
3131
"metadata": {},
32-
"outputs": [
33-
{
34-
"data": {
35-
"text/plain": [
36-
"[0, 1]"
37-
]
38-
},
39-
"execution_count": 3,
40-
"metadata": {},
41-
"output_type": "execute_result"
42-
}
43-
],
32+
"outputs": [],
4433
"source": [
4534
"result = run_two_sum(Solution, nums, target)\n",
4635
"result"
4736
]
4837
},
4938
{
5039
"cell_type": "code",
51-
"execution_count": 4,
40+
"execution_count": null,
5241
"id": "assert",
5342
"metadata": {},
54-
"outputs": [
55-
{
56-
"data": {
57-
"text/plain": [
58-
"True"
59-
]
60-
},
61-
"execution_count": 4,
62-
"metadata": {},
63-
"output_type": "execute_result"
64-
}
65-
],
43+
"outputs": [],
6644
"source": [
6745
"assert_two_sum(result, expected)"
6846
]
@@ -82,8 +60,7 @@
8260
"file_extension": ".py",
8361
"mimetype": "text/x-python",
8462
"name": "python",
85-
"nbconvert_exporter": "python",
86-
"pygments_lexer": "ipython3",
63+
"nbconvert_exporter": "python3",
8764
"version": "3.13.7"
8865
}
8966
},

leetcode/two_sum/solution.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
class Solution:
22

3-
# Time: O(n)
4-
# Space: O(n)
3+
# Time: O(?)
4+
# Space: O(?)
55
def two_sum(self, nums: list[int], target: int) -> list[int]:
6-
seen: dict[int, int] = {}
7-
for i, num in enumerate(nums):
8-
complement = target - num
9-
if complement in seen:
10-
return [seen[complement], i]
11-
seen[num] = i
6+
# TODO: Implement two_sum
127
return []

leetcode/two_sum/test_solution.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ def setup_method(self):
2222
([0, 4, 3, 0], 0, [0, 3]),
2323
([-1, -2, -3, -4, -5], -8, [2, 4]),
2424
([1, 3, 4, 2], 6, [2, 3]),
25+
([5, 75, 25], 100, [1, 2]),
26+
([-3, 4, 3, 90], 0, [0, 2]),
27+
([1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 2], 6, [5, 11]),
28+
([2, 1, 9, 4, 4, 56, 90, 3], 8, [3, 4]),
29+
([89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99], 185, [3, 4]),
30+
([-1000000000, 1000000000], 0, [0, 1]),
31+
([0, 1], 1, [0, 1]),
32+
([1, 2], 5, []),
33+
([3, 5, 7], 1, []),
34+
([10, 20, 30], 15, []),
2535
],
2636
)
2737
def test_two_sum(self, nums: list[int], target: int, expected: list[int]):

0 commit comments

Comments
 (0)