test: property-based tests for Result/Option/Arrays/pipe laws#10
Merged
Conversation
Add fast-check properties that verify the algebraic laws the library implicitly claims. Each property runs ~100 random cases (fast-check's default), so this is ~2500 additional check cases on top of the existing example-based tests — cheap insurance against whole classes of future regressions. Covered: - `result/laws.prop.test.ts` - Functor identity: map(r, id) === r - Functor composition: map(map(r, f), g) === map(r, g ∘ f) - Monad left identity: flatMap(ok(x), f) === f(x) - Monad right identity: flatMap(r, ok) === r - Monad associativity - `option/laws.prop.test.ts` — same five laws for Option/flatMap/some - `arrays/transform.prop.test.ts` - Functor identity + composition for Arrays.map - filter length never exceeds input - filter idempotence: filter(p)(filter(p)(xs)) === filter(p)(xs) - filter(true) === xs, filter(false) === [] - flatMap(xs, x => [x]) === xs (singleton lift) - flatMap(xs, x => []) === [] - reduce(xs, 0, +) matches xs.reduce - `pipe.prop.test.ts` - Identity: pipe(x) === x - Single-arg: pipe(x, f) === f(x) - Two-step composition: pipe(x, f, g) === g(f(x)) - Associativity: pipe(pipe(x, f), g) === pipe(x, f, g) - flow/pipe equivalence: flow(f, g)(x) === pipe(x, f, g) - flow(id) is the identity function Adds `fast-check@4.6.0` as a plainfp devDep. No runtime impact — these are test-only. All 249 tests still pass, typecheck clean.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10 +/- ##
==========================================
+ Coverage 88.41% 89.16% +0.75%
==========================================
Files 23 23
Lines 397 397
Branches 90 90
==========================================
+ Hits 351 354 +3
+ Misses 15 13 -2
+ Partials 31 30 -1
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Batch #4 of the post-launch polish. Add fast-check properties that verify the algebraic laws the library implicitly claims. Each property runs ~100 random cases by default, so this PR adds roughly 2,500 automated check cases on top of the existing example-based tests — cheap insurance against entire classes of regressions.
What gets verified
Result (`result/laws.prop.test.ts`)
Option (`option/laws.prop.test.ts`)
Same five laws with `flatMap` + `some`.
Arrays (`arrays/transform.prop.test.ts`)
pipe + flow (`pipe.prop.test.ts`)
Implementation
Results
Test plan