quickcheck

Property-based testing for Kit inspired by QuickCheck

Files

FileDescription
.editorconfigEditor formatting configuration
.gitignoreGit ignore rules for build artifacts and dependencies
.tool-versionsasdf tool versions (Zig, Kit)
LICENSEMIT license file
README.mdThis file
docs/.keepPlaceholder for generated documentation output
examples/basic.kitBasic usage example
kit.tomlPackage manifest with metadata, tasks, and dependency declarations
src/main.kitQuickCheck generators, combinators, property checking, and shrinking helpers
tests/quickcheck.test.kitTests for generator, shrinking, and property-checking behavior

Dependencies

No Kit package dependencies.

Installation

kit add gitlab.com/kit-lang/packages/kit-quickcheck.git

Usage

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:

HelperDescription
gen-int, gen-nat, gen-int-rangeInteger generators
gen-bool?, gen-float, gen-float-rangeBoolean and floating-point generators
gen-char, gen-alpha-num, gen-lower, gen-upperCharacter generators
gen-string, gen-alpha-num-stringString generators
gen-list, gen-non-empty-list, gen-list-of-lengthList generators
gen-option, gen-tuple2, gen-tuple3Composite value generators
gen-one-of, gen-frequency, gen-const, gen-map, gen-such-thatGenerator combinators

Property helpers:

HelperDescription
sampleGenerate one value at default size 10
sample-sizedGenerate one value with an explicit size
samplesGenerate multiple values at increasing sizes
checkRun a property with the default number of tests
check-nRun a property with an explicit test count
check-allRun several named properties

Shrinking helpers:

HelperDescription
shrink-intShrink an integer toward zero
shrink-listShrink a list by removing elements
shrink-strShrink a string by removing characters

Development

Running Examples

Run examples with the interpreter:

kit run examples/basic.kit

Compile examples to a native binary:

kit build examples/basic.kit && ./basic

Check interpreter/compiler parity for examples:

kit parity --no-spinner --failures-only

Running Tests

Run the test suite:

kit test

Run the test suite with coverage:

kit test --coverage

Running kit dev

Run the standard development workflow (format, check, test):

kit dev

This will:

  1. Format and check source files in src/
  2. Run tests in tests/ with coverage

Generating Documentation

Generate API documentation from doc comments:

kit doc

Note: Kit sources with doc comments (##) will generate HTML documents in docs/*.html

Cleaning Build Artifacts

Remove generated files, caches, and build artifacts:

kit task clean

Note: 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 install

This 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]