All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.net.jqwik.kotlin.api.ArbitraryExtensions.kt Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
package net.jqwik.kotlin.api

import net.jqwik.api.Arbitrary
import net.jqwik.api.arbitraries.ArrayArbitrary
import org.apiguardian.api.API

/**
 * Create a new arbitrary of the same type but inject null values with a probability of `nullProbability`.
 *
 * This is a type-safe version of [Arbitrary.injectNull()][Arbitrary.injectNull].
 *
 * @param nullProbability the probability. ≥ 0 and  ≤ 1.
 * @return a new arbitrary instance
 */
@API(status = API.Status.EXPERIMENTAL, since = "1.6.0")
fun  Arbitrary.orNull(nullProbability: Double): Arbitrary {
    return this.injectNull(nullProbability)
}

/**
 * Create a new arbitrary of type [SequenceArbitrary][SequenceArbitrary]
 * using the existing arbitrary for generating the elements of the sequence.
 *
 * @return a new arbitrary instance
 */
@API(status = API.Status.EXPERIMENTAL, since = "1.6.0")
fun  Arbitrary.sequence(): SequenceArbitrary {
    return SequenceArbitrary(this)
}

/**
 * Create a new arbitrary for type [Pair][Pair]
 * using the existing arbitrary for generating the elements of the pair.
 *
 * @return a new arbitrary instance
 */
@API(status = API.Status.EXPERIMENTAL, since = "1.6.0")
fun  Arbitrary.pair(): Arbitrary> {
    return anyPair(this, this)
}

/**
 * Create a new arbitrary for type [Triple][Triple]
 * using the existing arbitrary for generating the elements of the triple.
 *
 * @return a new arbitrary instance
 */
@API(status = API.Status.EXPERIMENTAL, since = "1.6.0")
fun  Arbitrary.triple(): Arbitrary> {
    return anyTriple(this, this, this)
}

/**
 * Create a new arbitrary of type [Array] using the existing arbitrary for generating the elements of the array.
 *
 * @param  Type of resulting array class
 * @return a new arbitrary instance
 */
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
@API(status = API.Status.EXPERIMENTAL, since = "1.6.0")
inline fun  Arbitrary.array(): ArrayArbitrary {
    return array(A::class.java)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy