Best Kotest code snippet using io.kotest.property.arbitrary.floats.Arb.Companion.numericFloat
floats.kt
Source:floats.kt
1package io.kotest.property.arbitrary2import io.kotest.property.Arb3import io.kotest.property.Gen4import io.kotest.property.Shrinker5import kotlin.math.absoluteValue6private val numericEdgeCases = listOf(-1.0F, -Float.MIN_VALUE, -0.0F, 0.0F, Float.MIN_VALUE, 1.0F)7private val nonFiniteEdgeCases = listOf(Float.NEGATIVE_INFINITY, Float.NaN, Float.POSITIVE_INFINITY)8object FloatShrinker : Shrinker<Float> {9 override fun shrink(value: Float): List<Float> =10 if (value == 0f || !value.isFinite() || value.absoluteValue < 10 * Float.MIN_VALUE)11 emptyList()12 else13 listOfNotNull(DoubleShrinker.shrink(value.toString())?.toFloat())14}15/**16 * Returns an [Arb] that produces [Float]s from [min] to [max] (inclusive).17 * The edge cases are [Float.NEGATIVE_INFINITY], [min], -1.0, -[Float.MIN_VALUE], -0.0, 0.0, [Float.MIN_VALUE], 1.0,18 * [max], [Float.POSITIVE_INFINITY] and [Float.NaN] which are only included if they are in the provided range.19 *20 * @see numericFloat to only produce numeric [Float]s21 */22fun Arb.Companion.float(min: Float = -Float.MAX_VALUE, max: Float = Float.MAX_VALUE): Arb<Float> = float(min..max)23/**24 * Returns an [Arb] that produces [Float]s in [range].25 * The edge cases are [Float.NEGATIVE_INFINITY], [ClosedFloatingPointRange.start], -1.0, -[Float.MIN_VALUE], -0.0,26 * 0.0, [Float.MIN_VALUE], 1.0, [ClosedFloatingPointRange.endInclusive], [Float.POSITIVE_INFINITY] and [Float.NaN] which27 * are only included if they are in the provided range.28 */29fun Arb.Companion.float(range: ClosedFloatingPointRange<Float> = -Float.MAX_VALUE..Float.MAX_VALUE): Arb<Float> =30 arbitrary(31 (numericEdgeCases.filter { it in range } +32 listOf(-1.0F, -0.0F, 0.0F, 1.0F).filter { it in range }.map { it / 0.0F } +33 listOf(range.start, range.endInclusive)34 ).distinct(),35 FloatShrinker36 ) {37 it.random.nextDouble(range.start.toDouble(), range.endInclusive.toDouble()).toFloat()38 }39/**40 * Returns an [Arb] that produces positive [Float]s from [Float.MIN_VALUE] to [max] (inclusive).41 * The edge cases are [Float.MIN_VALUE], 1.0, [max] and [Float.POSITIVE_INFINITY] which are only included if they are42 * in the provided range.43 */44fun Arb.Companion.positiveFloat(): Arb<Float> = float(Float.MIN_VALUE, Float.MAX_VALUE)45/**46 * Returns an [Arb] that produces negative [Float]s from [min] to -[Float.MIN_VALUE] (inclusive).47 * The edge cases are [Float.NEGATIVE_INFINITY], [min], -1.0 and -[Float.MIN_VALUE] which are only included if they48 * are in the provided range.49 */50fun Arb.Companion.negativeFloat(): Arb<Float> = float(-Float.MAX_VALUE, -Float.MIN_VALUE)51/**52 * Returns an [Arb] that produces numeric [Float]s from [min] to [max] (inclusive).53 * The edge cases are [min], -1.0, -[Float.MIN_VALUE], -0.0, 0.0, [Float.MIN_VALUE], 1.0 and [max] which are only54 * included if they are in the provided range.55 *56 * @see float to also have non numeric [Float]s as edge cases.57 */58fun Arb.Companion.numericFloat(59 min: Float = -Float.MAX_VALUE,60 max: Float = Float.MAX_VALUE61): Arb<Float> = arbitrary((numericEdgeCases.filter { it in min..max } + listOf(min, max)).distinct(), FloatShrinker) {62 it.random.nextDouble(min.toDouble(), max.toDouble()).toFloat()63}64@Deprecated("use numericFloat", ReplaceWith("numericFloat(from, to)"))65fun Arb.Companion.numericFloats(from: Float = -Float.MAX_VALUE, to: Float = Float.MAX_VALUE): Arb<Float> =66 numericFloat(from, to)67/**68 * Returns an [Arb] that produces [FloatArray]s where [length] produces the length of the arrays and69 * [content] produces the content of the arrays.70 */71fun Arb.Companion.floatArray(length: Gen<Int>, content: Arb<Float>): Arb<FloatArray> =72 toPrimitiveArray(length, content, Collection<Float>::toFloatArray)...
Arb.Companion.numericFloat
Using AI Code Generation
1println( Arb.numericFloat().next(RandomSource.Default) )2println( Arb.numericDouble().next(RandomSource.Default) )3println( Arb.numericBigDecimal().next(RandomSource.Default) )4println( Arb.numericBigInteger().next(RandomSource.Default) )5println( Arb.numericLong().next(RandomSource.Default) )6println( Arb.numericInt().next(RandomSource.Default) )7println( Arb.numericShort().next(RandomSource.Default) )8println( Arb.numericByte().next(RandomSource.Default) )9println( Arb.numericChar().next(RandomSource.Default) )10println( Arb.numericBoolean().next(RandomSource.Default) )11println( Arb.numericString().next(RandomSource.Default) )12println( Arb.numericCharSequence().next(RandomSource.Default) )13println( Arb.numericDate().next(RandomSource.Default) )14println( Arb.numericInstant().next(RandomSource.Default) )15println( Arb.numeric
Arb.Companion.numericFloat
Using AI Code Generation
1Arb . Companion . numericFloat ( 0.1f , 0.2f ) . edgecases ( 0.1f , 0.2f )2Arb . Companion . numericFloat ( 0.1f , 0.2f ) . edgecases ( 0.1f , 0.2f )3Arb . Companion . numericFloat ( 0.1f , 0.2f ) . edgecases ( 0.1f , 0.2f )4Arb . Companion . numericFloat ( 0.1f , 0.2f ) . edgecases ( 0.1f , 0.2f )5Arb . Companion . numericFloat ( 0.1f , 0.2f ) . edgecases ( 0.1f , 0.2f )6Arb . Companion . numericFloat ( 0.1f , 0.2f ) . edgecases ( 0.1f , 0.2f )7Arb . Companion . numericFloat ( 0.1f , 0.2f ) . edgecases ( 0.1f , 0.2f )8Arb . Companion . numericFloat ( 0.1f , 0.2f ) . edgecases ( 0.1f , 0.2f )9Arb . Companion . numericFloat ( 0.1f , 0.2f ) . edgecases ( 0.1f , 0.2
Arb.Companion.numericFloat
Using AI Code Generation
1 val arbFloat = Arb.numericFloat()2 arbFloat.generateSample()3 val arbDouble = Arb.numericDouble()4 arbDouble.generateSample()5 val arbBigDecimal = Arb.numericBigDecimal()6 arbBigDecimal.generateSample()7 val arbBigInteger = Arb.numericBigInteger()8 arbBigInteger.generateSample()9 val arbChar = Arb.numericChar()10 arbChar.generateSample()11 val arbString = Arb.numericString()12 arbString.generateSample()13 val arbLocalDate = Arb.numericLocalDate()14 arbLocalDate.generateSample()15 val arbLocalDateTime = Arb.numericLocalDateTime()16 arbLocalDateTime.generateSample()17 val arbLocalTime = Arb.numericLocalTime()18 arbLocalTime.generateSample()19 val arbOffsetDateTime = Arb.numericOffsetDateTime()20 arbOffsetDateTime.generateSample()21 val arbOffsetTime = Arb.numericOffsetTime()22 arbOffsetTime.generateSample()23 val arbZonedDateTime = Arb.numericZonedDateTime()24 arbZonedDateTime.generateSample()
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!