<< All versions
Skill v1.0.1
currentAutomated scan100/100majiayu000/claude-skill-registry-data/property-testing-captjay98-gemini-livestockai-3
3 files
──Details
PublishedMay 22, 2026 at 03:18 PM
Content Hashsha256:6be2fad4034eed3d...
Git SHA0ba92201da41
Bump Typepatch
──Files
Files (1 file, 3.1 KB)
SKILL.md3.1 KBactive
SKILL.md · 138 lines · 3.1 KB
version: "1.0.1" name: Property Testing description: Property-based testing with fast-check for business logic validation
Property Testing
LivestockAI uses property-based testing (PBT) with fast-check to validate business logic invariants.
What is Property Testing?
Instead of testing specific examples, property tests verify that properties hold for ALL possible inputs:
typescript
// Example-based testit('calculates FCR correctly', () => {expect(calculateFCR(150, 100)).toBe(1.5)})// Property-based testit('FCR is always positive when inputs are positive', () => {fc.assert(fc.property(fc.float({ min: 0.1, max: 10000 }),fc.float({ min: 0.1, max: 10000 }),(feed, weight) => {const fcr = calculateFCR(feed, weight)return fcr === null || fcr > 0},),)})
fast-check Basics
typescript
import { describe, it, expect } from 'vitest'import * as fc from 'fast-check'describe('Property Tests', () => {it('property holds for all inputs', () => {fc.assert(fc.property(fc.integer({ min: 1, max: 100000 }), (quantity) => {// Property must return true or throwreturn quantity > 0}),{ numRuns: 100 },)})})
Common Arbitraries
typescript
// Integersfc.integer({ min: 1, max: 100000 })fc.nat() // Non-negative integer// Floatsfc.float({ min: 0, max: 10000 })// Stringsfc.string()fc.uuid()// Arraysfc.array(fc.integer(), { minLength: 0, maxLength: 20 })// Objectsfc.record({quantity: fc.integer({ min: 1, max: 1000 }),price: fc.float({ min: 0, max: 10000 }),})
Inventory Invariant Example
From tests/features/batches/batches.property.test.ts:
typescript
/*** Property 4: Inventory Invariant* For any batch, current_quantity SHALL always equal:* initial_quantity - sum(mortality) - sum(sales)*/describe('Property 4: Inventory Invariant', () => {it('current_quantity equals initial - mortalities - sales', () => {fc.assert(fc.property(fc.integer({ min: 1, max: 100000 }),fc.array(fc.integer({ min: 1, max: 1000 })),fc.array(fc.integer({ min: 1, max: 1000 })),(initial, mortalities, sales) => {const { constrained } = constrainQuantities(initial,mortalities,sales,)const current = calculateCurrentQuantity(initial, constrained)expect(current).toBeGreaterThanOrEqual(0)expect(current).toBeLessThanOrEqual(initial)},),{ numRuns: 100 },)})})
Linking to Requirements
Annotate tests with requirement links:
typescript
/*** **Validates: Requirements 3.2, 4.2, 8.2***/it('inventory invariant holds', () => {// ...})
When to Use Property Testing
- Mathematical calculations (FCR, mortality rate, profit)
- Invariants (quantity never negative, totals match)
- State transitions (batch status changes)
- Data transformations (currency conversion)
Related Skills
vitest-patterns- Unit testing basicsthree-layer-architecture- Service layer testing