class TestSingleNumber(unittest.TestCase): def setUp(self): self.sn = SingleNumber() def test_single_number(self): self.assertEqual(1, self.sn.singleNumber([2, 2, 1])) self.assertEqual(4, self.sn.singleNumber([4, 1, 2, 1, 2]))
def test_singleNumber(self): """ Given nums = [4,1,2,1,2] return 4. """ nums = [4,1,2,1,2] expected = 4 sol = Solution() result = sol.singleNumber(nums) self.assertEqual(int(result), expected)
def test_single_number(self): solution = Solution() self.assertEqual(solution.singleNumber_xor([1]), 1) self.assertEqual(solution.singleNumber_xor([1, 1, 2]), 2) self.assertEqual(solution.singleNumber_xor([1, 1, 2, 2, 3]), 3) self.assertEqual(solution.singleNumber_xor([1, 1, 2, 3, 3]), 2) self.assertEqual(solution.singleNumber_xor([1, 2, 2, 3, 3]), 1) self.assertEqual(solution.singleNumber_xor([1, 1, 2, 2, 3, 3, 4]), 4) self.assertEqual(solution.singleNumber_xor([2, 2, 1]), 1) self.assertEqual(solution.singleNumber_xor([4, 1, 2, 1, 2]), 4) self.assertEqual( solution.singleNumber_xor([ 17, 12, 5, -6, 12, 4, 17, -5, 2, -3, 2, 4, 5, 16, -3, -4, 15, 15, -4, -5, -6 ]), 16)
import pytest from single_number import Solution1, Solution2, Solution3, Solution4, Solution solution_list = [ Solution1(), Solution2(), Solution3(), Solution4(), Solution() ] # testcases: List[Tuple[inp, out]] # use `set` to indicate the expected output may be multiple data = [ ( ([2, 2, 3, 2], ), 3, ), ( ([0, 1, 0, 1, 0, 1, 100], ), 100, ), ( ([-1, -1, -1, 2], ), 2, ), ( ([-2, -2, 1, 1, 4, 1, 4, 4, -4, -2], ), -4, ),
def setUp(self): self.sn = SingleNumber()
def test_single_number(self): solution = Solution() actual = solution.single_number([1, 1, 2, 2, 3]) self.assertEqual(3, actual)