About Prompt
- Niche – Code Generation
- Language – English
- Category – Software Development
- Prompt Title – Testing and Debugging AI Prompt
Prompt:
**Task Description:**
[Provide a clear and concise description of the task. Be extremely specific about the desired functionality, including input formats, expected output formats, edge cases, and any specific algorithms or libraries to be used. For example, “Generate a function that takes a list of integers as input and returns a new list containing only the even numbers. Handle empty input lists and lists containing non-integer values.” or “Implement a class that represents a binary search tree. Include methods for insertion, deletion, search, and finding the minimum/maximum values. The class should handle duplicate values and raise appropriate exceptions for invalid operations.”]
**Code Requirements:**
* **Language:** Python 3.9+
* **Style:** PEP 8 compliant. Use descriptive variable names and maintain consistent indentation.
* **Error Handling:** Implement robust error handling for invalid inputs, edge cases, and potential exceptions. Raise custom exceptions where appropriate with informative error messages.
* **Documentation:** Include docstrings for all functions and classes explaining their purpose, arguments, return values, and any exceptions raised. Use clear and concise language.
* **Efficiency:** Strive for efficient code with optimized algorithms and data structures. Avoid unnecessary computations or memory usage. If performance is critical, mention it explicitly in the task description.
**Unit Tests Requirements:**
* **Framework:** pytest
* **Coverage:** Aim for 100% branch coverage. Test all possible code paths, including edge cases, boundary conditions, and error handling logic.
* **Assertions:** Use clear and concise assertions to verify the expected behavior of the code.
* **Test Data:** Include a diverse set of test cases that cover all possible scenarios. Use parameterized tests where appropriate.
* **Test Organization:** Organize tests logically into test functions with descriptive names. Group related tests together.
**Output Format:**
The generated output should be formatted as a single Markdown code block containing:
1. **Code Section:** The complete Python code implementation, including all necessary imports, functions, and classes.
2. **Test Section:** The complete pytest test suite.
**Example (for a simple task):**
“`markdown
“`python
def even_numbers(numbers):
“””
Returns a list containing only the even numbers from the input list.
Args:
numbers: A list of integers.
Returns:
A list of even integers.
Raises:
TypeError: If the input is not a list or contains non-integer values.
“””
if not isinstance(numbers, list):
raise TypeError(“Input must be a list.”)
even_nums = []
for num in numbers:
if not isinstance(num, int):
raise TypeError(“List elements must be integers.”)
if num % 2 == 0:
even_nums.append(num)
return even_nums
“`
“`python
import pytest
from your_module import even_numbers # Replace your_module
def test_even_numbers_empty_list():
assert even_numbers([]) == []
def test_even_numbers_all_even():
assert even_numbers([2, 4, 6]) == [2, 4, 6]
def test_even_numbers_mixed():
assert even_numbers([1, 2, 3, 4, 5, 6]) == [2, 4, 6]
def test_even_numbers_invalid_input():
with pytest.raises(TypeError):
even_numbers(“not a list”)
def test_even_numbers_non_integer_element():
with pytest.raises(TypeError):
even_numbers([1, 2, “a”])
“`
“`
**Note:** Replace “[Specific Task]” with a detailed description of the task you want the AI to perform. The more detail you provide, the better the generated code will be. This includes specific examples of inputs and expected outputs. If you have performance requirements, limitations on library usage, or specific coding patterns to follow, clearly articulate them within the Task Description.