Skip to content

Add prime number substitution test. #12

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions test_ai_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@

# Run all tests, print the results, and return the number of failed tests
def run_tests(model):
test_functions = [test_1, test_2, test_3, test_4, test_5, test_6]
test_functions = [test_1, test_2, test_3, test_4, test_5, test_6, test_7]
test_names = [
"Generate fake people",
"Generate Random Password",
"Calculate area of triangle",
"Calculate the nth prime number",
"Encrypt text",
"Find missing numbers"
]
"Find missing numbers",
"Substitute prime numbers"
]
failed_tests = []

i = 0
Expand Down Expand Up @@ -167,5 +168,30 @@ def test_6(model):
print("Testing if the result list contains the expected missing numbers...")
assert result_list == expected_missing_numbers

def test_7(model):
function_string = "def substitute_prime_numbers_in_list(numbers: list[int]) -> list[int]:"
args = ["[5, 8, 10, 3, 29]"]
description_string = """Substitutes the prime numbers in a list with the closest greater composite and returns the list."""

result_string = ai_functions.ai_function(function_string, args, description_string, model)

print(f"Output: {result_string}")

# Assert the result can be parsed as a list
try:
result_list = ast.literal_eval(result_string)
print("Testing if result is a a list...")
assert isinstance(result_list, list)
except Exception as e:
print(e)
assert False

# Assert the result list contains the expected composite
expected_numbers = [6, 8, 10, 4, 30]
print("Testing if the result list is the same length as the input list...")
assert len(result_list) == len(expected_numbers)
print("Testing if the result list contains the expected composite numbers...")
assert result_list == expected_numbers

run_tests("gpt-4")
run_tests("gpt-3.5-turbo")