Generates **property-based tests** that use randomized input generation to validate invariants and contracts (rather than hand-picked examples). Triggers when the conversation involves: PBT frameworks (Hypothesis library for Python, fast-check for TypeScript, proptest for Rust, rapid for Go, RapidCheck for C++); concepts like invariants, contracts, round-trip symmetry, encode/decode, serialize/deserialize, generative testing, or shrinking; or requests to find edge cases that example-based tests miss — e.g., "find edge cases automatically", "test all possible inputs", "verify this property holds". Does NOT trigger for: writing regular example-based unit tests, debugging, CI/CD setup, UI/component testing, or integration/E2E testing. Identifies up to 7 property patterns (round-trip, idempotence, invariance, metamorphic, inverse, ordering, no-crash), designs input generators, writes property tests, and extracts regression tests from failures.
91
90%
Does it follow best practices?
Impact
94%
1.11xAverage score across 5 eval scenarios
Passed
No known issues
A Rust library stores service configuration as JSON. Most current tests serialize one hand-written config, but support has seen unusual feature names, absent optional limits, and boundary port values. The maintainers want broader tests around serialization contracts before changing defaults.
Write a test module for the code below. Include any helper strategy code needed to generate representative configurations and a short explanation of what to run locally.
Produce config_properties.rs containing tests suitable for a Cargo project, and NOTES.md with setup/run notes and failure-handling guidance.
=============== FILE: lib.rs ===============
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Config {
pub host: String,
pub port: u16,
pub timeout_secs: u64,
pub features: Vec<String>,
pub retry_on_failure: bool,
pub max_connections: Option<u32>,
}
pub fn to_json(config: &Config) -> serde_json::Result<String> {
serde_json::to_string(config)
}
pub fn from_json(input: &str) -> serde_json::Result<Config> {
serde_json::from_str(input)
}