moonbitlang/quickcheck/gen does not have a README file
test {
let g = pure(0).array_with_size(4)
@debug.assert_eq(g.sample(), [0, 0, 0, 0])
}test {
// Use bind to sequence generators: first pick `n`, then draw an
// `n`-element list of the fixed value 0.
let g = pure(3).bind(n => pure(0).list_with_size(n))
debug_inspect(
g.sample(),
content=(
#|<List: [0, 0, 0]>
),
)
}test {
let doubled = pure(21).fmap(x => x * 2)
assert_eq(doubled.sample(), 42)
}test {
let g = pure(42).list_with_size(3)
debug_inspect(
g.sample(),
content=(
#|<List: [42, 42, 42]>
),
)
}test {
// 90% chance of "common", 10% chance of "rare". With a fixed seed
// the draws are deterministic — over 10 samples we expect mostly
// "common".
let g = frequency([(9U, pure("common")), (1U, pure("rare"))])
for x in g.samples() {
assert_true(x == "common" || x == "rare")
}
}test {
for x in int_bound(100).samples() {
assert_true(x >= 0 && x < 100)
}
}test {
let g = int_range(10, 20)
for x in g.samples() {
assert_true(x >= 10 && x < 20)
}
}test {
let g = one_of([pure(1), pure(2), pure(3)])
for x in g.samples() {
assert_true(x == 1 || x == 2 || x == 3)
}
}test {
// A pure generator ignores size and rng and always yields the value.
assert_eq(pure(42).sample(), 42)
assert_eq(pure("hi").sample(), "hi")
}Automatic testing of MoonBit programs