code-permutation-testing
Systematic testing of code variations, edge cases, boundary conditions, and alternative implementations. This skill provides methodologies and tools for exhaustive testing including input permutation, code path analysis, mutation testing, and implementation alternatives. Use when ensuring code robustness through comprehensive test coverage or when exploring edge cases and boundary conditions.
What this skill does
# Code Permutation Testing
## Overview
This skill enables systematic testing of code variations, edge cases, and alternative implementations to ensure robustness and comprehensive test coverage. It provides methodologies for input permutation, code path analysis, mutation testing, and implementation exploration.
## When to Use
Invoke this skill when:
- Testing functions with complex input domains requiring boundary testing
- Exploring edge cases and corner conditions systematically
- Analyzing code path coverage and branch conditions
- Running mutation testing to verify test suite effectiveness
- Comparing alternative implementations for correctness
- Generating comprehensive test suites for critical code
- Validating error handling and recovery paths
## Core Testing Modes
### 1. Input Permutation Testing
Generate comprehensive test cases covering:
- **Boundary values**: Min, max, just inside, just outside boundaries
- **Edge cases**: Empty inputs, null values, extreme sizes
- **Type variations**: Different numeric types, string encodings, data structures
- **Combinatorial testing**: Pairwise and n-wise testing of input combinations
Load `references/boundary_patterns.md` for common boundary testing patterns and strategies.
Use `scripts/generate_boundaries.py` to automatically generate boundary test cases from function signatures.
### 2. Code Path Analysis
Analyze all possible execution paths through code:
- **Branch coverage**: Test all conditional branches
- **Loop coverage**: Zero, one, many, maximum iterations
- **Exception paths**: Force error conditions systematically
- **State transitions**: Test all valid and invalid state changes
Use `scripts/analyze_paths.py` to identify uncovered code paths and generate test suggestions.
### 3. Mutation Testing
Verify test suite effectiveness by introducing controlled mutations:
**For Rust projects:**
```bash
# Install cargo-mutants
cargo install cargo-mutants
# Run mutation testing
cargo mutants --no-shuffle --test-timeout 30
# Generate detailed report
cargo mutants --json > mutations.json
```
**For Python projects:**
```bash
# Install mutmut
pip install mutmut
# Run mutation testing
mutmut run --paths-to-mutate src/
# Show results
mutmut results
```
Load `references/mutation_testing.md` for detailed mutation testing guidance and interpretation.
### 4. Implementation Alternatives
Test different algorithmic approaches:
- **Iterative vs Recursive**: Compare implementations for stack safety
- **Mutable vs Immutable**: Test functional and imperative variations
- **Synchronous vs Asynchronous**: Verify concurrency behavior
- **Naive vs Optimized**: Validate optimizations maintain correctness
## Workflow
### Step 1: Analyze Target Code
First, understand the code structure:
- Identify function signatures and parameter types
- Map control flow and decision points
- Note error handling and edge cases
- Document assumptions and invariants
### Step 2: Generate Test Matrix
Create comprehensive test coverage:
```python
# Example for a function: divide(a: i32, b: i32) -> Result<i32, Error>
# Boundary tests
test_cases = [
# Normal cases
(10, 2, Ok(5)),
(10, 3, Ok(3)),
# Boundary values
(i32::MAX, 1, Ok(i32::MAX)),
(i32::MIN, 1, Ok(i32::MIN)),
(i32::MIN, -1, Err(Overflow)), # Special overflow case
# Edge cases
(0, 5, Ok(0)),
(5, 0, Err(DivisionByZero)),
(0, 0, Err(DivisionByZero)),
# Sign variations
(-10, 2, Ok(-5)),
(10, -2, Ok(-5)),
(-10, -2, Ok(5)),
]
```
### Step 3: Execute Permutation Tests
Run the generated test matrix:
- Execute each test case
- Verify expected outcomes
- Check for unexpected behaviors
- Monitor performance characteristics
### Step 4: Analyze Coverage
Evaluate test completeness:
- Generate coverage reports
- Identify uncovered paths
- Run mutation testing
- Add tests for gaps
### Step 5: Document Results
Create comprehensive test documentation:
- List all tested scenarios
- Document discovered edge cases
- Note performance characteristics
- Highlight critical paths
## Language-Specific Guidance
### Rust
```rust
#[cfg(test)]
mod permutation_tests {
use super::*;
use proptest::prelude::*;
// Property-based testing for automatic permutation
proptest! {
#[test]
fn test_function_properties(
a in any::<i32>(),
b in any::<i32>().prop_filter("non-zero", |x| *x != 0)
) {
let result = divide(a, b);
prop_assert!(result.is_ok());
prop_assert_eq!(result.unwrap(), a / b);
}
}
// Boundary value testing
#[test]
fn test_boundaries() {
let boundaries = vec![
i32::MIN, i32::MIN + 1, -1, 0, 1, i32::MAX - 1, i32::MAX
];
for a in &boundaries {
for b in &boundaries {
if *b != 0 {
let result = divide(*a, *b);
// Verify result or expected error
}
}
}
}
}
```
### Python
```python
import hypothesis.strategies as st
from hypothesis import given, assume
import pytest
# Property-based testing
@given(st.integers(), st.integers())
def test_division_properties(a, b):
assume(b != 0) # Precondition
result = divide(a, b)
assert result == a // b
# Parametrized boundary testing
@pytest.mark.parametrize("a,b,expected", [
(10, 2, 5),
(sys.maxsize, 1, sys.maxsize),
(-sys.maxsize-1, 1, -sys.maxsize-1),
(0, 5, 0),
# Add more boundary cases
])
def test_boundaries(a, b, expected):
assert divide(a, b) == expected
```
## Resources
### Scripts
- `scripts/generate_boundaries.py` - Analyzes function signatures and generates boundary test cases
- `scripts/analyze_paths.py` - Identifies code paths and suggests tests for uncovered branches
### References
- `references/boundary_patterns.md` - Common patterns for boundary value analysis and edge case identification
- `references/mutation_testing.md` - Comprehensive guide to mutation testing tools and result interpretation
## Best Practices
1. **Start with boundaries**: Test limits before normal cases
2. **Consider combinations**: Use pairwise testing for multiple parameters
3. **Test error paths**: Ensure error handling is robust
4. **Use property-based testing**: Let tools generate test cases automatically
5. **Verify with mutations**: Ensure tests actually catch bugs
6. **Document discoveries**: Record edge cases for future reference
7. **Automate generation**: Use scripts to create test matrices
8. **Monitor performance**: Track execution time across permutationsRelated in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.