
commonMain.io.kotest.properties.PropertyTestingAssertAll.kt Maven / Gradle / Ivy
@file:Suppress("RemoveExplicitTypeArguments")
package io.kotest.properties
import io.kotest.properties.shrinking.Shrinker
import io.kotest.properties.shrinking.shrink
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
data class Tuple4(val a: A, val b: B, val c: C, val d: D) {
override fun toString(): String {
return "($a, $b, $c, $d)"
}
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
data class Tuple5(val a: A, val b: B, val c: C, val d: D, val e: E) {
override fun toString(): String {
return "($a, $b, $c, $d, $e)"
}
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
data class Tuple6(val a: A, val b: B, val c: C, val d: D, val e: E, val f: F) {
override fun toString(): String {
return "($a, $b, $c, $d, $e, $f)"
}
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
inline fun assertAll(noinline fn: PropertyContext.(a: A) -> Unit) = assertAll(1000, fn)
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
inline fun assertAll(iterations: Int, noinline fn: PropertyContext.(a: A) -> Unit) {
assertAll(iterations, Gen.default(), fn)
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun assertAll(gena: Gen, fn: PropertyContext.(a: A) -> Unit) = assertAll(1000, gena, fn)
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun Gen.assertAll(iterations: Int = 1000, fn: PropertyContext.(a: A) -> Unit) = assertAll(iterations, this, fn)
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun Gen.assertAll(iterations: Int = 1000, fn: PropertyContext.(a0: A, a1: A) -> Unit) = assertAll(iterations, this, this, fn)
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun Gen.assertAll(iterations: Int = 1000, fn: PropertyContext.(a0: A, a1: A, a2: A) -> Unit) = assertAll(iterations, this, this, this, fn)
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun Gen.assertAll(iterations: Int = 1000, fn: PropertyContext.(a0: A, a1: A, a2: A, a3: A) -> Unit) = assertAll(iterations, this, this, this, this, fn)
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun Gen.assertAll(iterations: Int = 1000, fn: PropertyContext.(a0: A, a1: A, a2: A, a3: A, a4: A) -> Unit) = assertAll(iterations, this, this, this, this, this, fn)
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun Gen.assertAll(iterations: Int = 1000, fn: PropertyContext.(a0: A, a1: A, a2: A, a3: A, a4: A, a5: A) -> Unit) = assertAll(iterations, this, this, this, this, this, this, fn)
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun assertAll(iterations: Int, gena: Gen, fn: PropertyContext.(a: A) -> Unit) {
if (iterations <= 0) throw IllegalArgumentException("Iterations should be a positive number")
val values = gena.constants().asSequence() + gena.random()
_assertAll(iterations, values, gena.shrinker(), fn)
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun _assertAll(iterations: Int,
values: Sequence,
shrinkera: Shrinker?,
fn: PropertyContext.(a: A) -> Unit) {
if (iterations <= 0) throw IllegalArgumentException("Iterations should be a positive number")
val context = PropertyContext()
values.take(iterations).forEach { a ->
context.addValue(a)
testAndShrink(a, shrinkera, context, fn)
}
outputValues(context)
outputClassifications(context)
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
inline fun assertAll(noinline fn: PropertyContext.(a: A, b: B) -> Unit) = assertAll(1000, fn)
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
inline fun assertAll(iterations: Int, noinline fn: PropertyContext.(a: A, b: B) -> Unit) {
assertAll(iterations, Gen.default(), Gen.default(), fn)
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun assertAll(gena: Gen, genb: Gen, fn: PropertyContext.(a: A, b: B) -> Unit) = assertAll(1000, gena, genb, fn)
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun assertAll(iterations: Int, gena: Gen, genb: Gen, fn: PropertyContext.(a: A, b: B) -> Unit) {
val values = gena.constants().flatMap { a ->
genb.constants().map { b ->
Pair(a, b)
}
}.asSequence() + gena.random().zip(genb.random())
_assertAll(iterations, values, gena.shrinker(), genb.shrinker(), fn)
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun _assertAll(iterations: Int,
values: Sequence>,
shrinkera: Shrinker?,
shrinkerb: Shrinker?,
fn: PropertyContext.(a: A, b: B) -> Unit) {
if (iterations <= 0) throw IllegalArgumentException("Iterations should be a positive number")
val context = PropertyContext()
values.take(iterations).forEach {
context.addValue(it)
val (a, b) = it
testAndShrink(a, b, shrinkera, shrinkerb, context, fn)
}
outputValues(context)
outputClassifications(context)
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
inline fun assertAll(noinline fn: PropertyContext.(a: A, b: B, c: C) -> Unit) = assertAll(1000, fn)
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
inline fun assertAll(iterations: Int, noinline fn: PropertyContext.(a: A, b: B, c: C) -> Unit) {
assertAll(iterations, Gen.default(), Gen.default(), Gen.default(), fn)
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun assertAll(gena: Gen, genb: Gen, genc: Gen, fn: PropertyContext.(a: A, b: B, c: C) -> Unit) =
assertAll(1000, gena, genb, genc, fn)
fun assertAll(iterations: Int, gena: Gen, genb: Gen, genc: Gen, fn: PropertyContext.(a: A, b: B, c: C) -> Unit) {
if (iterations <= 0) throw IllegalArgumentException("Iterations should be a positive number")
val context = PropertyContext()
for (a in gena.constants()) {
for (b in genb.constants()) {
for (c in genc.constants()) {
context.addValue(Triple(a, b, c))
testAndShrink(a, b, c, gena, genb, genc, context, fn)
}
}
}
val avalues = gena.random().iterator()
val bvalues = genb.random().iterator()
val cvalues = genc.random().iterator()
while (context.attempts() < iterations) {
val a = avalues.next()
val b = bvalues.next()
val c = cvalues.next()
context.addValue(Triple(a, b, c))
testAndShrink(a, b, c, gena, genb, genc, context, fn)
}
outputValues(context)
outputClassifications(context)
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
inline fun assertAll(noinline fn: PropertyContext.(a: A, b: B, c: C, D) -> Unit) {
assertAll(1000, fn)
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
inline fun assertAll(iterations: Int, noinline fn: PropertyContext.(a: A, b: B, c: C, D) -> Unit) {
assertAll(iterations, Gen.default(), Gen.default(), Gen.default(), Gen.default(), fn)
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun assertAll(gena: Gen, genb: Gen, genc: Gen, gend: Gen, fn: PropertyContext.(a: A, b: B, c: C, d: D) -> Unit) =
assertAll(1000, gena, genb, genc, gend, fn)
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun assertAll(iterations: Int, gena: Gen, genb: Gen, genc: Gen, gend: Gen, fn: PropertyContext.(a: A, b: B, c: C, d: D) -> Unit) {
if (iterations <= 0) throw IllegalArgumentException("Iterations should be a positive number")
val context = PropertyContext()
for (a in gena.constants()) {
for (b in genb.constants()) {
for (c in genc.constants()) {
for (d in gend.constants()) {
context.addValue(Tuple4(a, b, c, d))
testAndShrink(a, b, c, d, gena, genb, genc, gend, context, fn)
}
}
}
}
val avalues = gena.random().iterator()
val bvalues = genb.random().iterator()
val cvalues = genc.random().iterator()
val dvalues = gend.random().iterator()
while (context.attempts() < iterations) {
val a = avalues.next()
val b = bvalues.next()
val c = cvalues.next()
val d = dvalues.next()
context.addValue(Tuple4(a, b, c, d))
testAndShrink(a, b, c, d, gena, genb, genc, gend, context, fn)
}
outputValues(context)
outputClassifications(context)
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
inline fun assertAll(noinline fn: PropertyContext.(a: A, b: B, c: C, d: D, e: E) -> Unit) {
assertAll(Gen.default(), Gen.default(), Gen.default(), Gen.default(), Gen.default(), fn)
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
inline fun assertAll(iterations: Int, noinline fn: PropertyContext.(a: A, b: B, c: C, d: D, e: E) -> Unit) {
assertAll(iterations, Gen.default(), Gen.default(), Gen.default(), Gen.default(), Gen.default(), fn)
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun assertAll(gena: Gen, genb: Gen, genc: Gen, gend: Gen, gene: Gen, fn: PropertyContext.(a: A, b: B, c: C, d: D, e: E) -> Unit) =
assertAll(1000, gena, genb, genc, gend, gene, fn)
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun assertAll(iterations: Int, gena: Gen, genb: Gen, genc: Gen, gend: Gen, gene: Gen, fn: PropertyContext.(a: A, b: B, c: C, d: D, e: E) -> Unit) {
if (iterations <= 0) throw IllegalArgumentException("Iterations should be a positive number")
val context = PropertyContext()
for (a in gena.constants()) {
for (b in genb.constants()) {
for (c in genc.constants()) {
for (d in gend.constants()) {
for (e in gene.constants()) {
context.addValue(Tuple5(a, b, c, d, e))
testAndShrink(a, b, c, d, e, gena, genb, genc, gend, gene, context, fn)
}
}
}
}
}
val avalues = gena.random().iterator()
val bvalues = genb.random().iterator()
val cvalues = genc.random().iterator()
val dvalues = gend.random().iterator()
val evalues = gene.random().iterator()
while (context.attempts() < iterations) {
val a = avalues.next()
val b = bvalues.next()
val c = cvalues.next()
val d = dvalues.next()
val e = evalues.next()
context.addValue(Tuple5(a, b, c, d, e))
testAndShrink(a, b, c, d, e, gena, genb, genc, gend, gene, context, fn)
}
outputValues(context)
outputClassifications(context)
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
inline fun assertAll(noinline fn: PropertyContext.(a: A, b: B, c: C, d: D, e: E, f: F) -> Unit) {
assertAll(1000, fn)
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
inline fun assertAll(iterations: Int, noinline fn: PropertyContext.(a: A, b: B, c: C, d: D, e: E, f: F) -> Unit) {
assertAll(iterations, Gen.default(), Gen.default(), Gen.default(), Gen.default(), Gen.default(), Gen.default(), fn)
}
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun assertAll(gena: Gen, genb: Gen, genc: Gen, gend: Gen, gene: Gen, genf: Gen, fn: PropertyContext.(a: A, b: B, c: C, d: D, e: E, f: F) -> Unit) =
assertAll(1000, gena, genb, genc, gend, gene, genf, fn)
@Deprecated("Deprecated and will be removed in 5.0. Migrate to the new property test classes in 4.0")
fun assertAll(iterations: Int, gena: Gen, genb: Gen, genc: Gen, gend: Gen, gene: Gen, genf: Gen,
fn: PropertyContext.(a: A, b: B, c: C, d: D, e: E, f: F) -> Unit) {
if (iterations <= 0) throw IllegalArgumentException("Iterations should be a positive number")
val context = PropertyContext()
fun test(a: A, b: B, c: C, d: D, e: E, f: F) {
context.inc()
try {
context.fn(a, b, c, d, e, f)
} catch (x: AssertionError) {
val smallestA = shrink(a, gena) { context.fn(it, b, c, d, e, f) }
val smallestB = shrink(b, genb) { context.fn(smallestA, it, c, d, e, f) }
val smallestC = shrink(c, genc) { context.fn(smallestA, smallestB, it, d, e, f) }
val smallestD = shrink(d, gend) { context.fn(smallestA, smallestB, smallestC, it, e, f) }
val smallestE = shrink(e, gene) { context.fn(smallestA, smallestB, smallestC, smallestD, it, f) }
val smallestF = shrink(f, genf) { context.fn(smallestA, smallestB, smallestC, smallestD, smallestE, it) }
val inputs = listOf(
PropertyFailureInput(a, smallestA),
PropertyFailureInput(b, smallestB),
PropertyFailureInput(c, smallestC),
PropertyFailureInput(d, smallestD),
PropertyFailureInput(e, smallestE),
PropertyFailureInput(f, smallestF)
)
throw propertyAssertionError(x, context.attempts(), inputs)
}
}
for (a in gena.constants()) {
for (b in genb.constants()) {
for (c in genc.constants()) {
for (d in gend.constants()) {
for (e in gene.constants()) {
for (f in genf.constants()) {
context.addValue(Tuple6(a, b, c, d, e, f))
test(a, b, c, d, e, f)
}
}
}
}
}
}
val avalues = gena.random().iterator()
val bvalues = genb.random().iterator()
val cvalues = genc.random().iterator()
val dvalues = gend.random().iterator()
val evalues = gene.random().iterator()
val fvalues = genf.random().iterator()
while (context.attempts() < iterations) {
val a = avalues.next()
val b = bvalues.next()
val c = cvalues.next()
val d = dvalues.next()
val e = evalues.next()
val f = fvalues.next()
context.addValue(Tuple6(a, b, c, d, e, f))
test(a, b, c, d, e, f)
}
outputValues(context)
outputClassifications(context)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy