Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two sum unit test too strict #230

Open
liavkoren opened this issue Mar 1, 2018 · 1 comment
Open

Two sum unit test too strict #230

liavkoren opened this issue Mar 1, 2018 · 1 comment

Comments

@liavkoren
Copy link

    def test_two_sum(self):
        solution = Solution()
        assert_raises(TypeError, solution.two_sum, None, None)
        assert_raises(ValueError, solution.two_sum, [], 0)
        target = 7
        nums = [1, 3, 2, -7, 5]
        expected = [2, 4]
        assert_equal(solution.two_sum(nums, target), expected)
        print('Success: test_two_sum')

[4, 2] should also be a valid answer. Unittest has an assertItemsEqual method, I'm not sure if nose has that too. I'm happy to write a PR for this, it's trivial to fix.

@havanagrawal
Copy link

The constraints in the problem clearly state that there is exactly one solution. Instead of modifying the solution, the problem should probably state:

...find the two indices i, j s.t. i < j...

though this is an implicit assumption for the two sum problem in general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants