-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_three_sum.py
More file actions
39 lines (31 loc) · 1.29 KB
/
test_three_sum.py
File metadata and controls
39 lines (31 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import unittest
from typing import List
from parameterized import parameterized
from algorithms.two_pointers.three_sum import three_sum, three_number_sum
THREE_SUM_TEST_CASES = [
([-1, 0, 1, 2, -1, -4], [[-1, -1, 2], [-1, 0, 1]]),
([0, 1, 1], []),
([0, 0, 0], [[0, 0, 0]]),
([-1, 0, 1, 2, -1, -1], [[-1, -1, 2], [-1, 0, 1]]),
([-1, 0, 1, 2, -1, -4], [[-1, -1, 2], [-1, 0, 1]]),
([-1, 0, 1, 2, -1, -4, 2], [[-1, -1, 2], [-1, 0, 1], [-4, 2, 2]]),
([-1, -1, 0, 1, 1, 1, 2], [[-1, -1, 2], [-1, 0, 1]]),
([-1, 0, 1, 2, -1, -4, -1, 2, 1], [[-1, -1, 2], [-1, 0, 1], [-4, 2, 2]]),
]
THREE_NUMBER_SUM_TEST_CASES = [
([12, 3, 1, 2, -6, 5, -8, 6], 0, [[-8, 2, 6], [-8, 3, 5], [-6, 1, 5]]),
]
class ThreeSumTestCases(unittest.TestCase):
@parameterized.expand(THREE_SUM_TEST_CASES)
def test_three_sum(self, nums: List[int], expected: List[List[int]]):
actual = three_sum(nums)
self.assertEqual(expected, actual)
class ThreeNumberSumTestCases(unittest.TestCase):
@parameterized.expand(THREE_NUMBER_SUM_TEST_CASES)
def test_three_number_sum(
self, nums: List[int], target_sum: int, expected: List[List[int]]
):
actual = three_number_sum(nums, target_sum)
self.assertEqual(expected, actual)
if __name__ == "__main__":
unittest.main()