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 Go scheduling package merges overlapping busy intervals before computing availability. Existing tests cover a couple of calendar examples, but imported calendars contain duplicate intervals, reversed ordering, zero-length entries, and large ranges. The team wants generated tests that validate broad behavioral contracts without depending on a handful of examples.
Write tests for the function below. The production code may be copied into a temporary package if needed; the important deliverable is the test code and a short note explaining the properties.
Produce intervals_property_test.go with Go tests and any helper generators or checking functions. Produce NOTES.md covering setup, how to run the tests, and how to preserve future failures.
=============== FILE: intervals.go ===============
package intervals
import "sort"
type Interval struct { Start, End int }
func MergeIntervals(xs []Interval) []Interval {
ys := make([]Interval, 0, len(xs))
for _, x := range xs {
if x.End < x.Start { x.Start, x.End = x.End, x.Start }
ys = append(ys, x)
}
sort.Slice(ys, func(i, j int) bool { return ys[i].Start < ys[j].Start })
out := make([]Interval, 0, len(ys))
for _, cur := range ys {
if len(out) == 0 || cur.Start > out[len(out)-1].End {
out = append(out, cur)
} else if cur.End > out[len(out)-1].End {
out[len(out)-1].End = cur.End
}
}
return out
}