How to use Arb.Companion.negativeDoubles method of io.kotest.property.arbitrary.doubles class

Best Kotest code snippet using io.kotest.property.arbitrary.doubles.Arb.Companion.negativeDoubles

doubles.kt

Source:doubles.kt Github

copy

Full Screen

1package io.kotest.property.arbitrary2import io.kotest.property.Arb3import io.kotest.property.Gen4import io.kotest.property.Shrinker5import kotlin.math.absoluteValue6private val numericEdgeCases = listOf(-1.0, -Double.MIN_VALUE, -0.0, 0.0, Double.MIN_VALUE, 1.0)7private val nonFiniteEdgeCases = listOf(Double.NEGATIVE_INFINITY, Double.NaN, Double.POSITIVE_INFINITY)8object DoubleShrinker : Shrinker<Double> {9 private val pattern = Regex("""([+-]|)([0-9]*)(\.[0-9]*|)(e[+-]?[0-9]+|)""", RegexOption.IGNORE_CASE)10 override fun shrink(value: Double): List<Double> =11 if (value == 0.0 || !value.isFinite() || value.absoluteValue < 10 * Double.MIN_VALUE)12 emptyList()13 else14 listOfNotNull(shrink(value.toString())?.toDouble())15 fun shrink(value: String): String? {16 val matches = pattern.matchEntire(value) ?: return null17 val parts = matches.groupValues.drop(1)18 val (signPart, intPart, fracPart_, expPart) = parts19 val fracPart = fracPart_.trimEnd { it == '0' }20 val numberPart = if (fracPart.isNotEmpty() && fracPart.last().isDigit()) {21 "$intPart${fracPart.dropLast(1)}"22 } else {23 val length = intPart.length24 val index = intPart.indexOfLast { it != '0' }.let { if (it == -1) length else it }25 if (index == 0) {26 return null27 }28 val head = intPart.take(index)29 val tail = intPart.takeLast(length - index - 1)30 "${head}0$tail"31 }32 return "$signPart$numberPart$expPart"33 }34}35/**36 * Returns an [Arb] that produces [Double]s from [min] to [max] (inclusive).37 * The edge cases are [Double.NEGATIVE_INFINITY], [min], -1.0, -[Double.MIN_VALUE], -0.0, 0.0, [Double.MIN_VALUE], 1.0,38 * [max], [Double.POSITIVE_INFINITY] and [Double.NaN].39 *40 * Only values in the provided range are included.41 *42 * @see numericDouble to only produce numeric [Double]s43 */44fun Arb.Companion.double(45 min: Double = -Double.MAX_VALUE,46 max: Double = Double.MAX_VALUE47): Arb<Double> = double(min..max)48/**49 * Returns an [Arb] that produces [Double]s in [range].50 * The edge cases are [Double.NEGATIVE_INFINITY], [ClosedFloatingPointRange.start], -1.0, -[Double.MIN_VALUE], -0.0,51 * 0.0, [Double.MIN_VALUE], 1.0, [ClosedFloatingPointRange.endInclusive], [Double.POSITIVE_INFINITY] and [Double.NaN]52 * which are only included if they are in the provided range.53 */54fun Arb.Companion.double(55 range: ClosedFloatingPointRange<Double> = -Double.MAX_VALUE..Double.MAX_VALUE56): Arb<Double> = arbitrary(57 (numericEdgeCases.filter { it in range } + nonFiniteEdgeCases + listOf(range.start, range.endInclusive)).distinct(),58 DoubleShrinker59) {60 it.random.nextDouble(range.start, range.endInclusive)61}62/**63 * Returns an [Arb] that produces positive [Double]s from [Double.MIN_VALUE] to [max] (inclusive).64 * The edge cases are [Double.MIN_VALUE], 1.0, [max] and [Double.POSITIVE_INFINITY] which are only included if they are65 * in the provided range.66 */67fun Arb.Companion.positiveDouble(max: Double = Double.MAX_VALUE): Arb<Double> = double(Double.MIN_VALUE, max)68@Deprecated("use positiveDouble. Deprecated in 5.0.", ReplaceWith("positiveDouble()"))69fun Arb.Companion.positiveDoubles(): Arb<Double> = positiveDouble()70/**71 * Returns an [Arb] that produces negative [Double]s from [min] to -[Double.MIN_VALUE] (inclusive).72 * The edge cases are [Double.NEGATIVE_INFINITY], [min], -1.0 and -[Double.MIN_VALUE] which are only included if they73 * are in the provided range.74 */75fun Arb.Companion.negativeDouble(min: Double = -Double.MAX_VALUE): Arb<Double> = double(min, -Double.MIN_VALUE)76@Deprecated("use negativeDouble. Deprecated in 5.0.", ReplaceWith("negativeDouble()"))77fun Arb.Companion.negativeDoubles(): Arb<Double> = negativeDouble()78/**79 * Returns an [Arb] that produces numeric [Double]s from [min] to [max] (inclusive).80 * The edge cases are [min], -1.0, -[Double.MIN_VALUE], -0.0, 0.0, [Double.MIN_VALUE], 1.0 and [max] which are only81 * included if they are in the provided range.82 *83 * @see double to also have non-numeric [Double]s as edge cases.84 */85fun Arb.Companion.numericDouble(86 min: Double = -Double.MAX_VALUE,87 max: Double = Double.MAX_VALUE88): Arb<Double> = arbitrary(89 (numericEdgeCases.filter { it in (min..max) } + listOf(min, max)).distinct(), DoubleShrinker90) { it.random.nextDouble(min, max) }91@Deprecated("use numericDouble. Deprecated in 5.0.", ReplaceWith("numericDouble(from, to)"))92fun Arb.Companion.numericDoubles(from: Double = -Double.MAX_VALUE, to: Double = Double.MAX_VALUE): Arb<Double> =93 numericDouble(from, to)94/**95 * Returns an [Arb] that produces [DoubleArray]s where [length] produces the length of the arrays and96 * [content] produces the content of the arrays.97 */98fun Arb.Companion.doubleArray(length: Gen<Int>, content: Arb<Double>): Arb<DoubleArray> =99 toPrimitiveArray(length, content, Collection<Double>::toDoubleArray)...

Full Screen

Full Screen

Arb.Companion.negativeDoubles

Using AI Code Generation

copy

Full Screen

1 val arb = Arb.negativeDoubles()2 val arb = Arb.negativeDoubles()3 val arb = Arb.negativeDoubles()4 val arb = Arb.negativeDoubles()5 val arb = Arb.negativeDoubles()6 val arb = Arb.negativeDoubles()7 val arb = Arb.negativeDoubles()8 val arb = Arb.negativeDoubles()9 val arb = Arb.negativeDoubles()10 val arb = Arb.negativeDoubles()11 val arb = Arb.negativeDoubles()12 val arb = Arb.negativeDoubles()13 val arb = Arb.negativeDoubles()14 val arb = Arb.negativeDoubles()

Full Screen

Full Screen

Arb.Companion.negativeDoubles

Using AI Code Generation

copy

Full Screen

1 fun `should generate negative doubles`() {2 Arb.negativeDoubles().checkAll {3 }4 }5 fun `should generate positive doubles`() {6 Arb.positiveDoubles().checkAll {7 }8 }9 fun `should generate doubles`() {10 Arb.doubles().checkAll {11 }12 }13 fun `should generate doubles between 0 and 1`() {14 Arb.doubles(0.0, 1.0).checkAll {15 }16 }17 fun `should generate doubles between 1 and 10`() {18 Arb.doubles(1.0, 10.0).checkAll {19 }20 }21 fun `should generate doubles between -10 and -1`() {22 Arb.doubles(-10.0, -1.0).checkAll {23 }24 }25 fun `should generate doubles between -1 and 0`() {26 Arb.doubles(-1.0, 0.0).checkAll {27 }28 }

Full Screen

Full Screen

Arb.Companion.negativeDoubles

Using AI Code Generation

copy

Full Screen

1import io.kotest.property.arbitrary.doubles2import io.kotest.property.arbitrary.negativeDoubles3class NegativeDoublesTest : StringSpec({4 "negativeDoubles" {5 forAll(doubles().negativeDoubles()) {6 }7 }8})9import io.kotest.property.arbitrary.doubles10import io.kotest.property.arbitrary.positiveDoubles11class PositiveDoublesTest : StringSpec({12 "positiveDoubles" {13 forAll(doubles().positiveDoubles()) {14 }15 }16})17import io.kotest.property.arbitrary.floats18import io.kotest.property.arbitrary.negativeFloats19class NegativeFloatsTest : StringSpec({20 "negativeFloats" {21 forAll(floats().negativeFloats()) {22 }23 }24})25import io.kotest.property.arbitrary.floats26import io.kotest.property.arbitrary.positiveFloats27class PositiveFloatsTest : StringSpec({28 "positiveFloats" {29 forAll(floats().positiveFloats()) {30 }31 }32})33import io.kotest.property.arbitrary.ints34import io.kotest.property.arbitrary.positiveInts35class PositiveIntsTest : StringSpec({36 "positiveInts" {37 forAll(ints().positiveInts()) {38 }39 }40})41import io.kotest.property.arbitrary.ints42import io.kotest.property.arbitrary.negativeInts43class NegativeIntsTest : StringSpec({44 "negativeInts" {45 forAll(ints().negativeInts()) {46 }47 }48})

Full Screen

Full Screen

Arb.Companion.negativeDoubles

Using AI Code Generation

copy

Full Screen

1@ValueSource(doubles = *[-1.0, -0.5, 0.0, 0.5, 1.0])2fun `negative doubles with @ValueSource`(value: Double) {3 assertTrue(value < 0.0)4}5@ValueSource(doubles = *[1.0, 0.5, 0.0, -0.5, -1.0])6fun `positive doubles with @ValueSource`(value: Double) {7 assertTrue(value > 0.0)8}9@ValueSource(doubles = *[-1.0, -0.5, 0.0, 0.5, 1.0])10fun `doubles with @ValueSource`(value: Double) {11 assertTrue(value != 0.0)12}13@ValueSource(floats = *[-1.0f, -0.5f, 0.0f, 0.5f, 1.0f])14fun `floats with @ValueSource`(value: Float) {15 assertTrue(value != 0.0f)16}17@ValueSource(floats = *[-1.0f, -0.5f, 0.0f])18fun `negative floats with @ValueSource`(value: Float) {19 assertTrue(value < 0.0f)20}21@ValueSource(floats = *[1.0f, 0.5f, 0.0f])

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful