Property-based testing checks a general statement about a function across many generated inputs instead of relying only on a few fixed examples. It works especially well for pure, referentially transparent functions because their results depend clearly on their inputs and have no surrounding side effects. section 6.4 section 6.0
You describe the required property, choose generators for valid inputs, and let a testing library exercise many randomized cases. Haskell’s QuickCheck provides the canonical model; JavaScript uses JSCheck for the same style of specification-driven testing. section 6.4
A practical property-based test usually combines these parts:
- A property states what the function’s output must satisfy. section 6.4
- A generator produces many inputs, such as arrays of numbers or structured identifiers. section 6.4
- A verdict function converts each result into a pass or fail decision, while reports show the generated cases. section 6.4
Testing grade calculations
A JSCheck test can assert that generated arrays containing numbers from 90 to 100 always produce an A grade. The framework reports 100 generated cases and their pass or fail results. A custom generator can similarly create formatted Social Security numbers and test a length-checking function across many inputs. section 6.4
Listing 6.4. Property-based test for computeAverageGrade
JSC.clear(); #1
JSC.on_report((str) => console.log(str));
JSC.test(
'Compute Average Grade', #2
function (verdict, grades, grade) { #3
return verdict(computeAverageGrade(grades) === grade);
},
[
JSC.array(JSC.integer(20), JSC.number(90,100)), #4
'A'
],
function (grades, grade) { #5
return 'Testing for an ' + grade + ' on grades: ' + grades;
}
);
The listing shows the core JSCheck shape: clear the runner, define a verdict function, generate input arrays, and classify each test. section 6.4







