Spaces:
Sleeping
Sleeping
Create test_case_generator.py
Browse files- test_case_generator.py +33 -0
test_case_generator.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List, Dict
|
| 2 |
+
|
| 3 |
+
def generate_test_cases(topic: str) -> List[Dict[str, str]]:
|
| 4 |
+
"""
|
| 5 |
+
Generate simple test cases for a given topic.
|
| 6 |
+
Each test case includes a name/idea, input, and expected output.
|
| 7 |
+
"""
|
| 8 |
+
topic_lower = topic.lower()
|
| 9 |
+
test_cases = []
|
| 10 |
+
|
| 11 |
+
if "login" in topic_lower:
|
| 12 |
+
test_cases = [
|
| 13 |
+
{"test_case": "Valid login", "input": "Correct username and password", "expected_output": "User is logged in successfully"},
|
| 14 |
+
{"test_case": "Invalid password", "input": "Wrong password", "expected_output": "Error message displayed"},
|
| 15 |
+
{"test_case": "Empty username", "input": "Username field left blank", "expected_output": "Error message displayed"},
|
| 16 |
+
{"test_case": "Empty password", "input": "Password field left blank", "expected_output": "Error message displayed"},
|
| 17 |
+
]
|
| 18 |
+
elif "calculator" in topic_lower:
|
| 19 |
+
test_cases = [
|
| 20 |
+
{"test_case": "Addition", "input": "2 + 3", "expected_output": "5"},
|
| 21 |
+
{"test_case": "Subtraction", "input": "5 - 2", "expected_output": "3"},
|
| 22 |
+
{"test_case": "Multiplication", "input": "4 * 5", "expected_output": "20"},
|
| 23 |
+
{"test_case": "Divide by zero", "input": "5 / 0", "expected_output": "Error handled gracefully"},
|
| 24 |
+
]
|
| 25 |
+
else:
|
| 26 |
+
# Generic template for other topics
|
| 27 |
+
test_cases = [
|
| 28 |
+
{"test_case": f"Test case 1 for {topic}", "input": "Sample input", "expected_output": "Expected behavior"},
|
| 29 |
+
{"test_case": f"Test case 2 for {topic}", "input": "Another input", "expected_output": "Expected behavior"},
|
| 30 |
+
{"test_case": f"Test case 3 for {topic}", "input": "Additional input", "expected_output": "Expected behavior"},
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
+
return test_cases
|