2020-07-04 22:56:49 +08:00
|
|
|
import unittest
|
2017-03-30 17:42:09 +08:00
|
|
|
|
|
|
|
|
2020-07-04 22:56:49 +08:00
|
|
|
class TestTwoSum(unittest.TestCase):
|
2017-03-30 17:42:09 +08:00
|
|
|
|
|
|
|
def test_two_sum(self):
|
|
|
|
solution = Solution()
|
2020-07-04 22:56:49 +08:00
|
|
|
self.assertRaises(TypeError, solution.two_sum, None, None)
|
|
|
|
self.assertRaises(ValueError, solution.two_sum, [], 0)
|
2017-03-30 17:42:09 +08:00
|
|
|
target = 7
|
|
|
|
nums = [1, 3, 2, -7, 5]
|
|
|
|
expected = [2, 4]
|
2020-07-04 22:56:49 +08:00
|
|
|
self.assertEqual(solution.two_sum(nums, target), expected)
|
2017-03-30 17:42:09 +08:00
|
|
|
print('Success: test_two_sum')
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
test = TestTwoSum()
|
|
|
|
test.test_two_sum()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-07-04 22:56:49 +08:00
|
|
|
main()
|