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

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

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.negativeDouble

Using AI Code Generation

copy

Full Screen

1Arb.negativeDouble()2Arb.negativeFloat()3Arb.negativeInt()4Arb.negativeLong()5Arb.negativeShort()6Arb.negativeBigInteger()7Arb.negativeBigDecimal()8Arb.negativeLocalDate()9Arb.negativeLocalDateTime()10Arb.negativeLocalTime()11Arb.negativeMonthDay()12Arb.negativeOffsetDateTime()13Arb.negativeOffsetTime()14Arb.negativePeriod()15Arb.negativeYear()16Arb.negativeYearMonth()17Arb.negativeZonedDateTime()18Arb.negativeZoneOffset()

Full Screen

Full Screen

Arb.Companion.negativeDouble

Using AI Code Generation

copy

Full Screen

1 Arb.negativeDouble()2 Arb.string()3 Arb.string(10)4 Arb.string(10, 20)5 Arb.string(10, 20, "abc")6 Arb.string(10, 20, "abc", "def")7 Arb.string(10, 20, "abc", "def", "ghi")8 Arb.string(10, 20, "abc", "def", "ghi", "jkl")9 Arb.string(10, 20, "abc", "def", "ghi", "jkl", "mno")10 Arb.string(10, 20, "abc", "def", "ghi", "jkl", "mno", "pqr")11 Arb.string(10, 20, "abc", "def", "ghi", "jkl", "mno", "pqr", "stu")12 Arb.string(10, 20, "abc", "def", "ghi", "jkl", "mno", "pqr", "stu", "vwx")13 Arb.string(10, 20, "abc", "def", "ghi", "jkl", "mno", "p

Full Screen

Full Screen

Arb.Companion.negativeDouble

Using AI Code Generation

copy

Full Screen

1val arb = Arb.negativeDouble()2val arb = Arb.negativeFloat()3val arb = Arb.negativeInt()4val arb = Arb.negativeLong()5val arb = Arb.negativeShort()6val arb = Arb.nonEmptyList(Arb.int())7val arb = Arb.nonEmptySet(Arb.int())8val arb = Arb.nonEmptyString()9val arb = Arb.nonEmptyString(CharRange('a', 'z'))10val arb = Arb.nonEmptyString(10, 100)11val arb = Arb.nonEmptyString(10, 100, CharRange('a', 'z'))12val arb = Arb.nonEmptyString(10, 100, CharRange('a', 'z'), 10)13val arb = Arb.nonEmptyString(10, 100, CharRange('a', 'z'), 10, Arb.int())14val arb = Arb.nonEmptyString(10, 100, CharRange('a', 'z'), 10, Arb.int(), 10)

Full Screen

Full Screen

Arb.Companion.negativeDouble

Using AI Code Generation

copy

Full Screen

1val arbDouble = Arb.negativeDouble()2val arbFloat = Arb.negativeFloat()3val arbInt = Arb.negativeInt()4val arbLong = Arb.negativeLong()5val arbShort = Arb.negativeShort()6val arbBigInteger = Arb.negativeBigInteger()7val arbBigDecimal = Arb.negativeBigDecimal()8val arbLocalDate = Arb.negativeLocalDate()9val arbLocalTime = Arb.negativeLocalTime()10val arbLocalDateTime = Arb.negativeLocalDateTime()11val arbInstant = Arb.negativeInstant()12val arbDuration = Arb.negativeDuration()13val arbPeriod = Arb.negativePeriod()14val arbYear = Arb.negativeYear()15val arbYearMonth = Arb.negativeYearMonth()16val arbMonthDay = Arb.negativeMonthDay()

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