quickcheck
| Kind | kit |
|---|---|
| Categories | testing development-tools |
| Keywords | testing property-based quickcheck generators |
Property-based testing for Kit inspired by QuickCheck
Files
| File | Description |
|---|---|
.editorconfig | Editor formatting configuration |
.gitignore | Git ignore rules for build artifacts and dependencies |
.tool-versions | asdf tool versions (Zig, Kit) |
LICENSE | MIT license file |
README.md | This file |
docs/.keep | Placeholder for generated documentation output |
examples/basic.kit | Basic usage example |
kit.toml | Package manifest with metadata, tasks, and dependency declarations |
src/main.kit | QuickCheck generators, combinators, property checking, and shrinking helpers |
tests/quickcheck.test.kit | Tests for generator, shrinking, and property-checking behavior |
Dependencies
No Kit package dependencies.
Installation
kit add gitlab.com/kit-lang/packages/kit-quickcheck.gitUsage
import Kit.Quickcheck as QC
# Generate sample data
print (QC.sample QC.gen-int)
print (QC.sample QC.gen-bool?)
print (QC.sample (QC.gen-list QC.gen-int))
# Build custom generators
small-positive-int = QC.gen-int-range 1 10
pair-gen = QC.gen-tuple2 small-positive-int small-positive-int
# Check a property with the default 100 test cases
QC.check "addition is commutative" pair-gen (fn(pair) =>
match pair
| (a, b) -> a + b == b + a
)
# Check list properties
QC.check "reverse reverse = id" (QC.gen-list QC.gen-int) (fn(xs) =>
List.reverse (List.reverse xs) == xs
)
# Generate constrained values
non-zero = QC.gen-such-that (fn(n) => n != 0) QC.gen-int
print (QC.sample non-zero)
# Inspect basic shrink candidates
print (QC.shrink-int 100)
print (QC.shrink-list [1, 2, 3, 4])
print (QC.shrink-str "hello")Available generator helpers include:
| Helper | Description |
|---|---|
gen-int, gen-nat, gen-int-range | Integer generators |
gen-bool?, gen-float, gen-float-range | Boolean and floating-point generators |
gen-char, gen-alpha-num, gen-lower, gen-upper | Character generators |
gen-string, gen-alpha-num-string | String generators |
gen-list, gen-non-empty-list, gen-list-of-length | List generators |
gen-option, gen-tuple2, gen-tuple3 | Composite value generators |
gen-one-of, gen-frequency, gen-const, gen-map, gen-such-that | Generator combinators |
Property helpers:
| Helper | Description |
|---|---|
sample | Generate one value at default size 10 |
sample-sized | Generate one value with an explicit size |
samples | Generate multiple values at increasing sizes |
check | Run a property with the default number of tests |
check-n | Run a property with an explicit test count |
check-all | Run several named properties |
Shrinking helpers:
| Helper | Description |
|---|---|
shrink-int | Shrink an integer toward zero |
shrink-list | Shrink a list by removing elements |
shrink-str | Shrink a string by removing characters |
Development
Running Examples
Run examples with the interpreter:
kit run examples/basic.kitCompile examples to a native binary:
kit build examples/basic.kit && ./basicCheck interpreter/compiler parity for examples:
kit parity --no-spinner --failures-onlyRunning Tests
Run the test suite:
kit testRun the test suite with coverage:
kit test --coverageRunning kit dev
Run the standard development workflow (format, check, test):
kit devThis will:
- Format and check source files in
src/ - Run tests in
tests/with coverage
Generating Documentation
Generate API documentation from doc comments:
kit docNote: Kit sources with doc comments (##) will generate HTML documents in docs/*.html
Cleaning Build Artifacts
Remove generated files, caches, and build artifacts:
kit task cleanNote: Defined in kit.toml.
Developer Notes
The generator implementation is deterministic so examples and parity checks produce stable output across kit run and compiled binaries. This makes failures reproducible while preserving the generator/combinator API shape used by property tests.
The package has no external Kit dependencies. Keep examples in examples/ self-contained and keep tests in tests/quickcheck.test.kit focused on generator bounds, combinator behavior, property results, and shrink output.
Local Installation
To install this package locally for development:
kit installThis installs the package to ~/.kit/packages/@kit/quickcheck/, making it available for import as Kit.Quickcheck in other projects.
License
This package is released under the MIT License - see LICENSE for details.
Exported Functions & Types
gen-int
Int -> Int
gen-int-range
Int -> Int -> Int -> Int
gen-nat
Int -> Int
gen-bool?
Int -> Bool
gen-float
Int -> Float
gen-float-range
Float -> Float -> Int -> Float
gen-char
Int -> Char
gen-alpha-num
Int -> String
gen-lower
Int -> Char
gen-upper
Int -> Char
gen-string
Int -> String
gen-alpha-num-string
Int -> String
gen-list
(Int -> a) -> Int -> [a]
gen-non-empty-list
(Int -> a) -> Int -> [a]
gen-list-of-length
Int -> (Int -> a) -> Int -> [a]
gen-option
(Int -> a) -> Int -> Option a
gen-tuple2
(Int -> a) -> (Int -> b) -> Int -> (a, b)
gen-tuple3
(Int -> a) -> (Int -> b) -> (Int -> c) -> Int -> (a, b, c)
gen-one-of
[(Int -> a)] -> Int -> a
gen-frequency
[(Int, Int -> a)] -> Int -> a
gen-const
a -> Int -> a
gen-map
(a -> b) -> (Int -> a) -> Int -> b
gen-such-that
(a -> Bool) -> (Int -> a) -> Int -> a
sample
(Int -> a) -> a
sample-sized
Int -> (Int -> a) -> a
samples
(Int -> a) -> Int -> [a]
check
NonEmptyString -> (Int -> a) -> (a -> Bool) -> Result Int {tests: Int, value: a}
check-n
NonEmptyString -> Int -> (Int -> a) -> (a -> Bool) -> Result Int {tests: Int, value: a}
check-all
[(String, ((Int -> a), a -> Bool))] -> Result Int Int
shrink-int
Int -> [Int]
shrink-list
[a] -> [[a]]
shrink-str
String -> [String]