-
Notifications
You must be signed in to change notification settings - Fork 44.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Douglas Schonholtz <[email protected]> Co-authored-by: symphony <[email protected]>
- Loading branch information
1 parent
87776b2
commit 6e1c2e7
Showing
7 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# mypy: ignore-errors | ||
from typing import List, Optional | ||
|
||
|
||
def two_sum(nums: List, target: int) -> Optional[int]: | ||
seen = {} | ||
for i, num in enumerate(nums): | ||
complement = target - num | ||
if complement in seen: | ||
return [seen[complement], i] | ||
seen[num] = i | ||
return None | ||
|
||
|
||
# Example usage: | ||
nums = [2, 7, 11, 15] | ||
target = 9 | ||
result = two_sum(nums, target) | ||
print(result) # Output: [0, 1] |
30 changes: 30 additions & 0 deletions
30
tests/integration/challenges/debug_code/data/two_sum_tests.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# mypy: ignore-errors | ||
# we need a new line at the top of the file to avoid a syntax error | ||
|
||
|
||
def test_two_sum(nums, target, expected_result): | ||
# These tests are appended to the two_sum file so we can ignore this error for now | ||
result = two_sum(nums, target) | ||
print(result) | ||
assert ( | ||
result == expected_result | ||
), f"AssertionError: Expected the output to be {expected_result}" | ||
|
||
|
||
# test the trivial case with the first two numbers | ||
nums = [2, 7, 11, 15] | ||
target = 9 | ||
expected_result = [0, 1] | ||
test_two_sum(nums, target, expected_result) | ||
|
||
# test for ability to use zero and the same number twice | ||
nums = [2, 7, 0, 15, 12, 0] | ||
target = 0 | ||
expected_result = [2, 5] | ||
test_two_sum(nums, target, expected_result) | ||
|
||
# test for first and last index usage and negative numbers | ||
nums = [-6, 7, 11, 4] | ||
target = -2 | ||
expected_result = [0, 3] | ||
test_two_sum(nums, target, expected_result) |
51 changes: 51 additions & 0 deletions
51
tests/integration/challenges/debug_code/test_debug_code_challenge_a.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
from pytest_mock import MockerFixture | ||
|
||
from autogpt.agent import Agent | ||
from autogpt.commands.execute_code import execute_python_file | ||
from autogpt.commands.file_operations import append_to_file, write_to_file | ||
from autogpt.config import Config | ||
from tests.integration.challenges.challenge_decorator.challenge_decorator import ( | ||
challenge, | ||
) | ||
from tests.integration.challenges.utils import run_interaction_loop | ||
from tests.utils import requires_api_key | ||
|
||
CYCLE_COUNT = 5 | ||
|
||
|
||
@pytest.mark.vcr | ||
@requires_api_key("OPENAI_API_KEY") | ||
@challenge | ||
def test_debug_code_challenge_a( | ||
debug_code_agent: Agent, | ||
monkeypatch: pytest.MonkeyPatch, | ||
patched_api_requestor: MockerFixture, | ||
config: Config, | ||
level_to_run: int, | ||
) -> None: | ||
""" | ||
Test whether the agent can debug a simple code snippet. | ||
:param debug_code_agent: The agent to test. | ||
:param monkeypatch: pytest's monkeypatch utility for modifying builtins. | ||
:patched_api_requestor: Sends api requests to our API CI pipeline | ||
:config: The config object for the agent. | ||
:level_to_run: The level to run. | ||
""" | ||
|
||
file_path = str(debug_code_agent.workspace.get_path("code.py")) | ||
|
||
code_file_path = Path(__file__).parent / "data" / "two_sum.py" | ||
test_file_path = Path(__file__).parent / "data" / "two_sum_tests.py" | ||
|
||
write_to_file(file_path, code_file_path.read_text(), config) | ||
|
||
run_interaction_loop(monkeypatch, debug_code_agent, CYCLE_COUNT) | ||
|
||
append_to_file(file_path, test_file_path.read_text(), config) | ||
|
||
output = execute_python_file(file_path, config) | ||
assert "error" not in output.lower(), f"Errors found in output: {output}!" |