Sborole commited on
Commit
b6c3679
·
verified ·
1 Parent(s): e11ef2b

Create test_case_generator.py

Browse files
Files changed (1) hide show
  1. tools/test_case_generator.py +40 -0
tools/test_case_generator.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List, Dict
2
+ from langchain.tools import tool
3
+
4
+ @tool
5
+ def suggest_test_cases(topic: str) -> List[Dict[str, str]]:
6
+ """
7
+ Suggest simple QA test cases for a given topic.
8
+
9
+ Args:
10
+ topic: The feature, function, or topic to generate test cases for.
11
+
12
+ Returns:
13
+ A list of test cases, each with input and expected output.
14
+ """
15
+ topic_lower = topic.lower()
16
+ test_cases = []
17
+
18
+ if "login" in topic_lower:
19
+ test_cases = [
20
+ {"test_case": "Valid login", "input": "Correct username/password", "expected_output": "User is logged in successfully"},
21
+ {"test_case": "Invalid password", "input": "Wrong password", "expected_output": "Error message displayed"},
22
+ {"test_case": "Empty username", "input": "Username left blank", "expected_output": "Error message displayed"},
23
+ {"test_case": "Empty password", "input": "Password left blank", "expected_output": "Error message displayed"},
24
+ ]
25
+ elif "calculator" in topic_lower:
26
+ test_cases = [
27
+ {"test_case": "Addition", "input": "2 + 3", "expected_output": "5"},
28
+ {"test_case": "Subtraction", "input": "5 - 2", "expected_output": "3"},
29
+ {"test_case": "Multiplication", "input": "4 * 5", "expected_output": "20"},
30
+ {"test_case": "Divide by zero", "input": "5 / 0", "expected_output": "Error handled gracefully"},
31
+ ]
32
+ else:
33
+ # Generic template
34
+ test_cases = [
35
+ {"test_case": f"Test case 1 for {topic}", "input": "Sample input", "expected_output": "Expected behavior"},
36
+ {"test_case": f"Test case 2 for {topic}", "input": "Another input", "expected_output": "Expected behavior"},
37
+ {"test_case": f"Test case 3 for {topic}", "input": "Additional input", "expected_output": "Expected behavior"},
38
+ ]
39
+
40
+ return test_cases