Ejemplo n.º 1
0
class TestCase(unittest.TestCase):
    def setUp(self):
        self.solution = Solution()

    def test(self):
        test_data = [
            {
                'nums': [2, 7, 11, 15],
                'target': 9,
                'expected': [0, 1]
            },
            {
                'nums': [3, 2, 4],
                'target': 6,
                'expected': [1, 2]
            },
            {
                'nums': [3, 3],
                'target': 6,
                'expected': [0, 1]
            },
            {
                'nums': [2, 3, 7, 11, 15, 3],
                'target': 6,
                'expected': [1, 5]
            },
        ]
        for data in test_data:
            nums = data['nums']
            target = data['target']
            expected = data['expected']
            with self.subTest(nums=nums, target=target):
                self.assertEqual(self.solution.twoSum(nums, target), expected)
class TestCase(unittest.TestCase):
    def setUp(self):
        self.solution = Solution()

    def test(self):
        nums = [2, 3, 7, 11, 15, 3]
        target = 6
        self.assertEqual(self.solution.twoSum(nums, target), [1, 5])
Ejemplo n.º 3
0
 def setUp(self):
     self.solution = Solution()
Ejemplo n.º 4
0
def test_solution():
    s = Solution()
    for t in tests:
        result = s.twoSum(t.nums, t.target)
        assert result == t.result