def test_twoSum(self): solution = Solution() cases = [ [[2, 7, 11, 15], 9, [0, 1]], [[3, 2, 4], 6, [1, 2]], #[[3, 3], 6, [0, 1]], ] for arg, target, expected in cases: assert solution.twoSum(arg, target) == expected
from main import Solution s = Solution() inp1 = [2, 7, 11, 15] inp2 = 9 print(s.twoSum(inp1, inp2)) inp1 = [3, 2, 4] inp2 = 6 print(s.twoSum(inp1, inp2)) inp1 = [3, 3] inp2 = 6 print(s.twoSum(inp1, inp2))
class SolutionTest(unittest.TestCase): def setUp(self): self.sol = Solution() def test_1(self): self.assertEqual(self.sol.twoSum([2, 7, 11, 15], 9), [0, 1])
def test_twoSum(self): solution = Solution() cases = [[[2, 7, 11, 15], 9, [1, 2]], [[2, 3, 4], 6, [1, 3]], [[-1, 0], -1, [1, 2]]] for nums, target, expected in cases: assert solution.twoSum(nums, target) == expected