Skip to content

Commit 432646b

Browse files
committed
test: add more test cases
1 parent 060ef6e commit 432646b

File tree

27 files changed

+505
-27
lines changed

27 files changed

+505
-27
lines changed

.amazonq/rules/test-case-enhancement.md

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
## Assistant Workflow for Adding Comprehensive Test Cases
44

5+
### Automated Workflow (Recommended)
6+
7+
For single problem enhancement:
8+
9+
1. **Use automation script**: `./.amazonq/rules/test-case-enhancement/scripts/enhance_single_problem.sh <problem_name>`
10+
2. **Verify results**: `./.amazonq/rules/test-case-enhancement/scripts/verify_enhancement.sh <problem_name>`
11+
12+
For batch enhancement:
13+
14+
1. **Find problems**: `./.amazonq/rules/test-case-enhancement/scripts/find_problems_needing_enhancement.sh`
15+
2. **Batch enhance**: `./.amazonq/rules/test-case-enhancement/scripts/enhance_batch_problems.sh`
16+
17+
### Manual Workflow (Fallback)
18+
519
When user requests to enhance test cases for a problem, the assistant will:
620

721
### 1. Problem Resolution (Priority Order)
@@ -98,7 +112,45 @@ When user requests to enhance test cases for a problem, the assistant will:
98112
- **NEVER include custom solution classes** in test_imports - only import the main solution class specified in solution_class_name
99113
- **PRESERVE existing solution class parametrization** - if original test had multiple solution classes, restore them after JSON regeneration
100114

101-
## Commands Reference
115+
## Automation Scripts 🤖
116+
117+
**RECOMMENDED APPROACH**: Use prebuilt scripts in `.amazonq/rules/test-case-enhancement/scripts/` to streamline the enhancement process:
118+
119+
### Find Problems Needing Enhancement
120+
121+
```bash
122+
# Find problems with ≤10 test cases (default)
123+
./.amazonq/rules/test-case-enhancement/scripts/find_problems_needing_enhancement.sh
124+
125+
# Custom threshold and max results
126+
./.amazonq/rules/test-case-enhancement/scripts/find_problems_needing_enhancement.sh 8 15
127+
```
128+
129+
### Enhance Single Problem
130+
131+
```bash
132+
# Enhance specific problem (handles full workflow automatically)
133+
./.amazonq/rules/test-case-enhancement/scripts/enhance_single_problem.sh <problem_name>
134+
```
135+
136+
### Batch Enhancement
137+
138+
```bash
139+
# Enhance up to 10 problems with ≤10 test cases (default)
140+
./.amazonq/rules/test-case-enhancement/scripts/enhance_batch_problems.sh
141+
142+
# Custom batch size and threshold
143+
./.amazonq/rules/test-case-enhancement/scripts/enhance_batch_problems.sh 5 8
144+
```
145+
146+
### Verify Enhancement Results
147+
148+
```bash
149+
# Verify enhancement was successful
150+
./.amazonq/rules/test-case-enhancement/scripts/verify_enhancement.sh <problem_name>
151+
```
152+
153+
## Manual Commands Reference
102154

103155
```bash
104156
# Find problems needing more test cases
@@ -129,3 +181,33 @@ make p-lint PROBLEM={problem_name}
129181
- Original solution code preserved and working
130182
- JSON template updated for future regeneration
131183
- Clean final state with no temporary files
184+
185+
## Automation Benefits
186+
187+
Using the prebuilt scripts provides several advantages:
188+
189+
### **Speed & Efficiency**
190+
191+
- **Single command execution** - No need to remember complex multi-step workflows
192+
- **Batch processing** - Enhance multiple problems simultaneously
193+
- **Automatic cleanup** - No manual file management required
194+
195+
### 🛡️ **Safety & Reliability**
196+
197+
- **Automatic backups** - Original code always preserved
198+
- **Error handling** - Graceful failure recovery
199+
- **Validation checks** - Syntax and structure verification
200+
201+
### 📊 **Visibility & Tracking**
202+
203+
- **Progress reporting** - Real-time status updates
204+
- **Result verification** - Automatic test case counting
205+
- **Success metrics** - Clear pass/fail indicators
206+
207+
### 🔄 **Consistency**
208+
209+
- **Standardized process** - Same workflow every time
210+
- **Quality assurance** - Built-in lint and validation checks
211+
- **Reproducible results** - Eliminates human error
212+
213+
**Recommendation**: Always use automation scripts for test case enhancement unless debugging specific issues requires manual intervention.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Test Case Enhancement Automation Scripts
2+
3+
This directory contains prebuilt scripts to streamline the test case enhancement process for LeetCode problems.
4+
5+
## Scripts Overview
6+
7+
### 🔍 `find_problems_needing_enhancement.sh`
8+
9+
**Purpose**: Find problems with insufficient test cases
10+
**Usage**: `bash find_problems_needing_enhancement.sh [threshold] [max_results]`
11+
**Example**: `bash find_problems_needing_enhancement.sh 10 5`
12+
13+
### 🚀 `enhance_single_problem.sh`
14+
15+
**Purpose**: Enhance test cases for a single problem (full automated workflow)
16+
**Usage**: `bash enhance_single_problem.sh <problem_name>`
17+
**Example**: `bash enhance_single_problem.sh two_sum`
18+
19+
### 📦 `enhance_batch_problems.sh`
20+
21+
**Purpose**: Enhance test cases for multiple problems in batch
22+
**Usage**: `bash enhance_batch_problems.sh [max_problems] [threshold]`
23+
**Example**: `bash enhance_batch_problems.sh 5 10`
24+
25+
### `verify_enhancement.sh`
26+
27+
**Purpose**: Verify that test case enhancement was successful
28+
**Usage**: `bash verify_enhancement.sh <problem_name>`
29+
**Example**: `bash verify_enhancement.sh two_sum`
30+
31+
## Typical Workflow
32+
33+
1. **Find problems needing enhancement**:
34+
35+
```bash
36+
bash .amazonq/rules/test-case-enhancement/scripts/find_problems_needing_enhancement.sh
37+
```
38+
39+
2. **Enhance problems** (choose one):
40+
41+
```bash
42+
# Single problem
43+
bash .amazonq/rules/test-case-enhancement/scripts/enhance_single_problem.sh <problem_name>
44+
45+
# Batch enhancement
46+
bash .amazonq/rules/test-case-enhancement/scripts/enhance_batch_problems.sh
47+
```
48+
49+
3. **Verify results**:
50+
```bash
51+
bash .amazonq/rules/test-case-enhancement/scripts/verify_enhancement.sh <problem_name>
52+
```
53+
54+
## What the Scripts Do
55+
56+
### Automated Process
57+
58+
1. **Backup** original problem structure
59+
2. **Regenerate** from enhanced JSON templates
60+
3. **Lint check** to ensure code quality
61+
4. **Preserve** enhanced test files
62+
5. **Restore** original solution code
63+
6. **Verify** final state
64+
65+
### Safety Features
66+
67+
- Automatic backups before any changes
68+
- Rollback capability if errors occur
69+
- Syntax validation of generated tests
70+
- Comprehensive error handling
71+
72+
## Requirements
73+
74+
- All scripts must be run from the repository root directory
75+
- Requires `poetry`, `make`, and standard Unix tools
76+
- JSON templates must be updated with enhanced test cases before running scripts
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
3+
# Batch Test Case Enhancement Script
4+
# Usage: ./enhance_batch_problems.sh [max_problems]
5+
6+
set -e
7+
8+
MAX_PROBLEMS="${1:-10}"
9+
THRESHOLD="${2:-10}"
10+
11+
echo "🚀 Starting batch test case enhancement"
12+
echo "📊 Finding problems with ≤$THRESHOLD test cases (max: $MAX_PROBLEMS)"
13+
14+
# Get list of problems needing enhancement
15+
PROBLEMS=$(poetry run python .templates/check_test_cases.py --threshold="$THRESHOLD" --max="$MAX_PROBLEMS" | grep "\.json:" | cut -d':' -f1 | sed 's/\.json$//')
16+
17+
if [ -z "$PROBLEMS" ]; then
18+
echo "✅ No problems found needing test case enhancement"
19+
exit 0
20+
fi
21+
22+
echo "📋 Problems to enhance:"
23+
echo "$PROBLEMS" | sed 's/^/ - /'
24+
25+
# Create backup directory
26+
mkdir -p .cache/leetcode
27+
28+
# Process each problem
29+
SUCCESS_COUNT=0
30+
TOTAL_COUNT=0
31+
32+
for PROBLEM in $PROBLEMS; do
33+
TOTAL_COUNT=$((TOTAL_COUNT + 1))
34+
echo ""
35+
echo "🔄 Processing problem $TOTAL_COUNT: $PROBLEM"
36+
37+
# Backup original
38+
if [ -d "leetcode/$PROBLEM" ]; then
39+
cp -r "leetcode/$PROBLEM" ".cache/leetcode/"
40+
echo " 📦 Backed up original"
41+
else
42+
echo " ❌ Problem directory not found: leetcode/$PROBLEM"
43+
continue
44+
fi
45+
46+
# Regenerate from JSON
47+
if make p-gen PROBLEM="$PROBLEM" FORCE=1 > /dev/null 2>&1; then
48+
echo " 🔄 Regenerated from JSON"
49+
else
50+
echo " ❌ Failed to regenerate from JSON"
51+
continue
52+
fi
53+
54+
# Preserve enhanced test and restore structure
55+
cp "leetcode/$PROBLEM/test_solution.py" ".temp_test_$PROBLEM.py"
56+
rm -rf "leetcode/$PROBLEM"
57+
cp -r ".cache/leetcode/$PROBLEM" "leetcode/"
58+
cp ".temp_test_$PROBLEM.py" "leetcode/$PROBLEM/test_solution.py"
59+
rm ".temp_test_$PROBLEM.py"
60+
61+
SUCCESS_COUNT=$((SUCCESS_COUNT + 1))
62+
echo " ✅ Enhanced successfully"
63+
done
64+
65+
# Cleanup
66+
rm -rf .cache/leetcode
67+
68+
echo ""
69+
echo "🎉 Batch enhancement completed!"
70+
echo "📊 Results: $SUCCESS_COUNT/$TOTAL_COUNT problems enhanced successfully"
71+
72+
# Verify results
73+
echo ""
74+
echo "📋 Final verification:"
75+
poetry run python .templates/check_test_cases.py --threshold="$THRESHOLD" --max=5
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
3+
# Enhanced Test Case Generation Script for Single Problem
4+
# Usage: ./enhance_single_problem.sh <problem_name>
5+
6+
set -e
7+
8+
PROBLEM_NAME="$1"
9+
10+
if [ -z "$PROBLEM_NAME" ]; then
11+
echo "Usage: $0 <problem_name>"
12+
exit 1
13+
fi
14+
15+
echo "🚀 Enhancing test cases for: $PROBLEM_NAME"
16+
17+
# Step 1: Backup original problem
18+
echo "📦 Backing up original problem..."
19+
mkdir -p .cache/leetcode
20+
if [ -d "leetcode/$PROBLEM_NAME" ]; then
21+
cp -r "leetcode/$PROBLEM_NAME" ".cache/leetcode/"
22+
echo "✅ Backup created"
23+
else
24+
echo "❌ Problem directory not found: leetcode/$PROBLEM_NAME"
25+
exit 1
26+
fi
27+
28+
# Step 2: Regenerate from JSON template
29+
echo "🔄 Regenerating from enhanced JSON template..."
30+
make p-gen PROBLEM="$PROBLEM_NAME" FORCE=1
31+
32+
# Step 3: Lint check
33+
echo "🔍 Running lint check..."
34+
if make p-lint PROBLEM="$PROBLEM_NAME"; then
35+
echo "✅ Lint check passed"
36+
else
37+
echo "❌ Lint check failed - please fix JSON template"
38+
exit 1
39+
fi
40+
41+
# Step 4: Preserve enhanced test file and restore original structure
42+
echo "🔄 Preserving enhanced tests and restoring original structure..."
43+
cp "leetcode/$PROBLEM_NAME/test_solution.py" ".temp_enhanced_test.py"
44+
rm -rf "leetcode/$PROBLEM_NAME"
45+
cp -r ".cache/leetcode/$PROBLEM_NAME" "leetcode/"
46+
cp ".temp_enhanced_test.py" "leetcode/$PROBLEM_NAME/test_solution.py"
47+
rm ".temp_enhanced_test.py"
48+
49+
# Step 5: Verify final state
50+
echo "✅ Enhancement complete for: $PROBLEM_NAME"
51+
echo "📊 Test case count verification:"
52+
python3 -c "
53+
import re
54+
with open('leetcode/$PROBLEM_NAME/test_solution.py', 'r') as f:
55+
content = f.read()
56+
matches = re.findall(r'@pytest\.mark\.parametrize.*?\[(.*?)\]', content, re.DOTALL)
57+
if matches:
58+
test_cases = matches[0].count('(')
59+
print(f'Total test cases: {test_cases}')
60+
else:
61+
print('Could not count test cases')
62+
"
63+
64+
echo "🎉 Test case enhancement completed successfully!"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# Find Problems Needing Test Case Enhancement
4+
# Usage: ./find_problems_needing_enhancement.sh [threshold] [max_results]
5+
6+
THRESHOLD="${1:-10}"
7+
MAX_RESULTS="${2:-20}"
8+
9+
echo "🔍 Finding problems with ≤$THRESHOLD test cases (showing max $MAX_RESULTS results)"
10+
echo ""
11+
12+
# Run the check and format output
13+
OUTPUT=$(poetry run python .templates/check_test_cases.py --threshold="$THRESHOLD" --max="$MAX_RESULTS")
14+
15+
if echo "$OUTPUT" | grep -q "Files with ≤"; then
16+
echo "$OUTPUT"
17+
echo ""
18+
19+
# Extract just the problem names for easy copying
20+
PROBLEM_NAMES=$(echo "$OUTPUT" | grep "\.json:" | cut -d':' -f1 | sed 's/\.json$//')
21+
PROBLEM_COUNT=$(echo "$PROBLEM_NAMES" | wc -l | tr -d ' ')
22+
23+
echo "📋 Problem names for batch processing:"
24+
echo "$PROBLEM_NAMES" | sed 's/^/ /'
25+
echo ""
26+
echo "📊 Total problems found: $PROBLEM_COUNT"
27+
28+
if [ "$PROBLEM_COUNT" -gt 0 ]; then
29+
echo ""
30+
echo "💡 Quick commands:"
31+
echo " # Enhance all found problems:"
32+
echo " ./.amazonq/rules/test-case-enhancement/scripts/enhance_batch_problems.sh $PROBLEM_COUNT $THRESHOLD"
33+
echo ""
34+
echo " # Enhance single problem:"
35+
echo " ./.amazonq/rules/test-case-enhancement/scripts/enhance_single_problem.sh <problem_name>"
36+
fi
37+
else
38+
echo "✅ No problems found needing test case enhancement (threshold: $THRESHOLD)"
39+
fi

0 commit comments

Comments
 (0)