1.3 KiB
1.3 KiB
Haskell QuickCheck
This note covers 26-haskell-quickcheck/, which normalizes overlapping maintenance windows and checks the implementation with QuickCheck
properties.
1. Why Properties Help Here
The function under test is not a single arithmetic helper. It sorts, merges, and preserves the covered time range of several windows.
That kind of behavior is a strong fit for property testing, because you care about broad rules:
- the result should be normalized,
- normalizing twice should not change the answer, and
- the normalized result should cover exactly the same minutes as the input.
Those are better teaching examples for QuickCheck than a one-line reverse . reverse property.
2. What the Generator Controls
The test suite generates windows within a bounded minute range.
That keeps the coverage property finite, because the test can compare membership across 0..60 directly.
The important point is not the numeric range itself. It is the workflow:
- generate realistic structured input,
- state invariant-like properties, and
- let QuickCheck search for counterexamples.
3. Commands to Try
cd 26-haskell-quickcheck
nix develop
cabal run
cabal run -- 0-10 8-14 20-24 24-30
cabal test
nix build
./result/bin/mini-windows 0-10 8-14 20-24 24-30
nix run . -- 0-10 8-14 20-24 24-30
nix flake check