Skip to content

Commit

Permalink
Update test_three_sum.py
Browse files Browse the repository at this point in the history
  • Loading branch information
anwar099 authored Jan 13, 2025
1 parent a3a7ceb commit 78fe85b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions solutions/tests/test_three_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class TestThreeSum(unittest.TestCase):
"""Unit tests for the three_sum function."""
"""Unit tests for the `three_sum` function."""

def test_basic_case(self):
"""Test basic example with valid triplets."""
Expand Down Expand Up @@ -32,8 +32,8 @@ def test_repeated_numbers(self):
def test_large_input(self):
"""Test with very large input arrays."""
nums = [1, -1, 0] * 10000
# Expecting a valid triplet
expected = [[-1, 0, 1]]
# Expecting valid triplets: [-1, 0, 1] and [0, 0, 0]
expected = [[-1, 0, 1], [0, 0, 0]]
self.assertEqual(sorted(three_sum(nums)), sorted(expected))

def test_invalid_input(self):
Expand All @@ -42,6 +42,18 @@ def test_invalid_input(self):
with self.assertRaises(ValueError):
three_sum(nums)

def test_duplicate_triplets(self):
"""Test to ensure duplicate triplets are not included in the result."""
nums = [-1, 0, 1, -1, 0, 1, -1, 0, 1]
expected = [[-1, 0, 1]]
self.assertEqual(sorted(three_sum(nums)), sorted(expected))

def test_zero_sum_only(self):
"""Test input with multiple zeros."""
nums = [0, 0, 0, 0, 0]
expected = [[0, 0, 0]]
self.assertEqual(sorted(three_sum(nums)), sorted(expected))


if __name__ == "__main__":
unittest.main()

0 comments on commit 78fe85b

Please sign in to comment.