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

Create twoSum.py #72

Closed
wants to merge 1 commit into from
Closed

Create twoSum.py #72

wants to merge 1 commit into from

Conversation

isabellahoch
Copy link
Contributor

No description provided.

Copy link

benchify bot commented Dec 10, 2024

🧪 Benchify Analysis of PR 72

The twoSum function was tested for two properties: (1) returning indices that sum to the target value, and (2) only returning indices when a valid solution exists. While the function passed 100 test cases for finding valid pairs of indices that sum to the target, it showed a potential issue by returning a non-empty list in one case where no valid solution existed. This suggests the function's validation logic for "no solution" cases may need review.

File Example Input # Inputs Found Description
src/twoSum.py nums=[-19274, 51, -472040057, 136251459791962466178925144672030458614, 22086, -29265, 124, -29381, -21546, -15539, -4770, -2, -25, 1709063135, -34, -1168239076], target=-77 1 The function returned a non-empty list when no two distinct indices summed to the target.
src/twoSum.py nums=[125, 0], target=125 100 The function should return two distinct indices such that the sum of the elements at these indices equals the target.
Reproducible Unit Tests
import jsonpickle
import unittest
import time
import asyncio


from src.twoSum import *
# Property: The function should return an empty list if no two distinct indices can be found that sum to the target.
def benchify_test_two_sum_no_solution(nums, target):
    # Create a scenario where no solution exists
    if len(nums) >= 2:
        nums[0] = target + 1  # Ensure nums[0] + nums[1] != target
        nums[1] = target + 2
        result = twoSum(nums, target)
        assert result == []


# The next test is failing.
def test_two_sum_no_solution_failure_0():
    nums=[-19274, 51, -472040057, 136251459791962466178925144672030458614, 22086, -29265, 124, -29381, -21546, -15539, -4770, -2, -25, 1709063135, -34, -1168239076]
    target=-77
    benchify_test_two_sum_no_solution(nums, target)



# The next batch of tests are passing.
def test_two_sum_no_solution_passing_0():
    nums=[0, 0]
    target=0
    benchify_test_two_sum_no_solution(nums, target)

def test_two_sum_no_solution_passing_1():
    nums=[20853, 0]
    target=0
    benchify_test_two_sum_no_solution(nums, target)

def test_two_sum_no_solution_passing_2():
    nums=[-17329, 0]
    target=0
    benchify_test_two_sum_no_solution(nums, target)

# Found 39 more passing tests.
# Property: The function should return two distinct indices such that the sum of the elements at these indices equals the target.

def benchify_test_two_sum_indices(nums, target):
    # Create a valid input scenario where a solution exists
    if len(nums) >= 2:
        nums[0] = target - nums[1]  # Ensure nums[0] + nums[1] == target
        result = twoSum(nums, target)
        assert len(result) == 2
        assert nums[result[0]] + nums[result[1]] == target
        assert result[0] != result[1]


# The next batch of tests are passing.
def test_two_sum_indices_passing_0():
    nums=[0, 0]
    target=0
    benchify_test_two_sum_indices(nums, target)

def test_two_sum_indices_passing_1():
    nums=[54, 0]
    target=0
    benchify_test_two_sum_indices(nums, target)

def test_two_sum_indices_passing_2():
    nums=[-74, 0]
    target=0
    benchify_test_two_sum_indices(nums, target)

# Found 97 more passing tests.

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

Successfully merging this pull request may close these issues.

1 participant