skills/emillindfors/property-testing-guide/SKILL.md
Introduces property-based testing with proptest, helping users find edge cases automatically by testing invariants and properties. Activates when users test algorithms or data structures.
npx skillsauth add aiskillstore/marketplace property-testing-guideInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are an expert at property-based testing in Rust using proptest. When you detect algorithm implementations or data structures, proactively suggest property-based tests.
Activate when you notice:
Traditional Testing: Test specific inputs Property Testing: Test properties that should always hold
Traditional:
#[test]
fn test_serialize_user() {
let user = User { id: "123", email: "[email protected]" };
let json = serialize(user);
assert_eq!(json, r#"{"id":"123","email":"[email protected]"}"#);
}
Property-Based:
proptest! {
#[test]
fn test_serialization_roundtrip(id in "[a-z0-9]+", email in "[a-z]+@[a-z]+\\.com") {
let user = User { id, email: email.clone() };
let serialized = serialize(&user)?;
let deserialized = deserialize(&serialized)?;
// Property: roundtrip should preserve data
prop_assert_eq!(user.id, deserialized.id);
prop_assert_eq!(user.email, deserialized.email);
}
}
Pattern:
use proptest::prelude::*;
proptest! {
#[test]
fn test_encode_decode_roundtrip(data in ".*") {
let encoded = encode(&data);
let decoded = decode(&encoded)?;
// Property: encoding then decoding gives original
prop_assert_eq!(data, decoded);
}
}
Pattern:
proptest! {
#[test]
fn test_normalize_idempotent(s in ".*") {
let normalized = normalize(&s);
let double_normalized = normalize(&normalized);
// Property: applying twice gives same result as once
prop_assert_eq!(normalized, double_normalized);
}
}
Pattern:
proptest! {
#[test]
fn test_sort_invariants(mut vec in prop::collection::vec(any::<i32>(), 0..100)) {
let original_len = vec.len();
sort(&mut vec);
// Property 1: Length unchanged
prop_assert_eq!(vec.len(), original_len);
// Property 2: Sorted order
for i in 1..vec.len() {
prop_assert!(vec[i-1] <= vec[i]);
}
}
}
Pattern:
proptest! {
#[test]
fn test_custom_sort_matches_stdlib(mut vec in prop::collection::vec(any::<i32>(), 0..100)) {
let mut expected = vec.clone();
expected.sort();
custom_sort(&mut vec);
// Property: matches standard library behavior
prop_assert_eq!(vec, expected);
}
}
Pattern:
proptest! {
#[test]
fn test_add_subtract_inverse(a in any::<i32>(), b in any::<i32>()) {
if let Some(sum) = a.checked_add(b) {
let result = sum.checked_sub(b);
// Property: subtraction is inverse of addition
prop_assert_eq!(result, Some(a));
}
}
}
use proptest::prelude::*;
fn user_strategy() -> impl Strategy<Value = User> {
("[a-z]{5,10}", "[a-z]{3,8}@[a-z]{3,8}\\.com", 18..100u8)
.prop_map(|(name, email, age)| User {
name,
email,
age,
})
}
proptest! {
#[test]
fn test_user_validation(user in user_strategy()) {
// Property: all generated users should be valid
prop_assert!(validate_user(&user).is_ok());
}
}
fn positive_money() -> impl Strategy<Value = Money> {
(1..1_000_000u64).prop_map(|cents| Money::from_cents(cents))
}
proptest! {
#[test]
fn test_money_operations(a in positive_money(), b in positive_money()) {
let sum = a + b;
// Property: sum is greater than both operands
prop_assert!(sum >= a);
prop_assert!(sum >= b);
}
}
proptest! {
#[test]
fn test_parser_never_panics(s in ".*") {
// Property: parser should never panic, only return Ok or Err
let _ = parse(&s); // Should not panic
}
#[test]
fn test_valid_input_parses(
name in "[a-zA-Z]+",
age in 0..150u8,
) {
let input = format!("{},{}", name, age);
let result = parse(&input);
// Property: valid input always succeeds
prop_assert!(result.is_ok());
}
}
proptest! {
#[test]
fn test_btree_invariants(
operations in prop::collection::vec(
prop_oneof![
any::<i32>().prop_map(Operation::Insert),
any::<i32>().prop_map(Operation::Remove),
],
0..100
)
) {
let mut tree = BTree::new();
for op in operations {
match op {
Operation::Insert(val) => tree.insert(val),
Operation::Remove(val) => tree.remove(val),
}
// Property: tree maintains balance invariant
prop_assert!(tree.is_balanced());
// Property: tree maintains order invariant
prop_assert!(tree.is_sorted());
}
}
}
proptest! {
#[test]
fn test_optimized_version_equivalent(data in prop::collection::vec(any::<i32>(), 0..100)) {
let result1 = slow_but_correct(&data);
let result2 = fast_optimized(&data);
// Property: optimized version gives same results
prop_assert_eq!(result1, result2);
}
}
[dev-dependencies]
proptest = "1.0"
Proptest automatically finds minimal failing cases:
proptest! {
#[test]
fn test_divide(a in any::<i32>(), b in any::<i32>()) {
let result = divide(a, b); // Fails when b == 0
// proptest will shrink to smallest failing case: b = 0
prop_assert!(result.is_ok());
}
}
When you see:
Proactively suggest property-based tests to find edge cases automatically.
development
Apple Human Interface Guidelines for content display components. Use this skill when the user asks about charts component, collection view, image view, web view, color well, image well, activity view, lockup, data visualization, content display, displaying images, rendering web content, color pickers, or presenting collections of items in Apple apps. Also use when the user says how should I display charts, what's the best way to show images, should I use a web view, how do I build a grid of items, what component shows media, or how do I present a share sheet. Cross-references: hig-foundations for color/typography/accessibility, hig-patterns for data visualization patterns, hig-components-layout for structural containers, hig-platforms for platform-specific component behavior.
tools
Automate HelpDesk tasks via Rube MCP (Composio): list tickets, manage views, use canned responses, and configure custom fields. Always search tools first for current schemas.
testing
Expert Haskell engineer specializing in advanced type systems, pure functional design, and high-reliability software. Use PROACTIVELY for type-level programming, concurrency, and architecture guidance.
tools
GraphQL gives clients exactly the data they need - no more, no less. One endpoint, typed schema, introspection. But the flexibility that makes it powerful also makes it dangerous. Without proper controls, clients can craft queries that bring down your server. This skill covers schema design, resolvers, DataLoader for N+1 prevention, federation for microservices, and client integration with Apollo/urql. Key insight: GraphQL is a contract. The schema is the API documentation. Design it carefully.