How to use Arb.Companion.bigDecimal method of io.kotest.property.arbitrary.bigdecimal class

Best Kotest code snippet using io.kotest.property.arbitrary.bigdecimal.Arb.Companion.bigDecimal

DistanceSpec.kt

Source:DistanceSpec.kt Github

copy

Full Screen

1package io.mehow.ruler2import io.kotest.assertions.throwables.shouldNotThrowAny3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.core.spec.style.DescribeSpec5import io.kotest.matchers.comparables.shouldBeEqualComparingTo6import io.kotest.matchers.shouldBe7import io.kotest.property.Arb8import io.kotest.property.arbitrary.filterNot9import io.kotest.property.arbitrary.long10import io.kotest.property.arbitrary.numericDoubles11import io.kotest.property.checkAll12import io.mehow.ruler.test.DistanceGenerator13import java.math.BigDecimal14import kotlin.Long.Companion.MAX_VALUE15import kotlin.Long.Companion.MIN_VALUE16internal class DistanceSpec : DescribeSpec({17 describe("zero distance") {18 val zeroDistance = Distance.Zero19 it("does not have any meters") {20 zeroDistance.meters shouldBeEqualComparingTo BigDecimal.ZERO21 }22 }23 describe("min distance") {24 val minDistance = Distance.Min25 it("has smallest possible meters") {26 minDistance.meters shouldBeEqualComparingTo MIN_VALUE.toBigDecimal() + 1.toBigDecimal().movePointLeft(9)27 }28 it("cannot be subtracted from") {29 shouldThrow<ArithmeticException> { minDistance - Distance.ofNanometers(1) }30 }31 it("can be added to") {32 checkAll(DistanceGenerator.create(min = Distance.Zero)) { distance ->33 shouldNotThrowAny { minDistance + distance }34 }35 }36 it("cannot have smaller distance") {37 shouldThrow<ArithmeticException> { minDistance - Distance.Epsilon }38 }39 it("absolute value is equal to max distance") {40 minDistance.abs() shouldBe Distance.Max41 }42 }43 describe("max distance") {44 val maxDistance = Distance.Max45 it("has largest possible meters") {46 maxDistance.meters shouldBe MAX_VALUE.toBigDecimal() + 999_999_999.toBigDecimal().movePointLeft(9)47 }48 it("cannot be added to") {49 shouldThrow<ArithmeticException> { maxDistance + Distance.ofNanometers(1) }50 }51 it("can be subtracted from") {52 checkAll(DistanceGenerator.create(min = Distance.Zero)) { distance ->53 shouldNotThrowAny { maxDistance - distance }54 }55 }56 it("cannot have larger distance") {57 shouldThrow<ArithmeticException> { maxDistance + Distance.Epsilon }58 }59 }60 describe("distance") {61 val distanceGenerator = DistanceGenerator.create(62 min = Distance.ofGigameters(-1),63 max = Distance.ofGigameters(1),64 )65 // Filter small values to avoid division explosion.66 val wholeGenerator = Arb.long(-500_000, 500_000).filterNot { it == 0L }67 val realGenerator = Arb.numericDoubles(-500_000.0, 500_000.0).filterNot { it in -0.000_001..0.000_001 }68 context("can be multiplied") {69 it("by a whole number") {70 checkAll(distanceGenerator, wholeGenerator) { distance, multiplier ->71 distance * multiplier shouldBe Distance.create(distance.meters * multiplier.toBigDecimal())72 }73 }74 it("by a real number") {75 checkAll(distanceGenerator, realGenerator) { distance, multiplier ->76 distance * multiplier shouldBe Distance.create(distance.meters * multiplier.toBigDecimal())77 }78 }79 }80 context("can be divided") {81 it("by a whole number") {82 checkAll(distanceGenerator, wholeGenerator) { distance, multiplier ->83 distance / multiplier shouldBe Distance.create(distance.meters / multiplier.toBigDecimal())84 }85 }86 it("by a real number") {87 checkAll(distanceGenerator, realGenerator) { distance, multiplier ->88 distance / multiplier shouldBe Distance.create(distance.meters / multiplier.toBigDecimal())89 }90 }91 }92 it("can have absolute value computed") {93 checkAll(distanceGenerator) { distance ->94 distance.abs() shouldBe Distance.create(distance.meters.abs())95 }96 }97 }98 describe("two distances") {99 val generator = DistanceGenerator.create(100 min = Distance.ofGigameters(-1),101 max = Distance.ofGigameters(1),102 )103 it("can be added") {104 checkAll(generator, generator) { first, second ->105 first + second shouldBe Distance.create(first.meters + second.meters)106 }107 }108 it("can be subtracted") {109 checkAll(generator, generator) { first, second ->110 first - second shouldBe Distance.create(first.meters - second.meters)111 }112 }113 it("can be compared") {114 checkAll(generator, generator) { first, second ->115 first.compareTo(second) shouldBe first.meters.compareTo(second.meters)116 }117 }118 }119})...

Full Screen

Full Screen

jvmbind.kt

Source:jvmbind.kt Github

copy

Full Screen

1package io.kotest.property.arbitrary2import io.kotest.property.Arb3import kotlin.reflect.KClass4import kotlin.reflect.KType5import kotlin.reflect.full.primaryConstructor6/**7 * Returns an [Arb] where each value is a randomly created instance of [T].8 * These instances are created by selecting the primaryConstructor of T and then9 * auto-detecting a generator for each parameter of that constructor.10 * T must be a class type.11 *12 * [providedArbs] allows you to provide a mapping of [KClass] to [Arb], for any given class [T].13 * This can be used to control parts of the data generation, as well as including non-data classes in the14 * hierarchies for which an [Arb] is being derived.15 *16 * Note: This method only supports parameters the following kind of parameter:17 * - Data classes, where all properties also fall into this category18 * - Pair, where 1st and 2nd fall into this category19 * - Primitives20 * - LocalDate, LocalDateTime, LocalTime, Period21 * - BigDecimal22 * - Collections (Set, List, Map)23 * - Classes for which an [Arb] has been provided through [providedArbs]24 */25inline fun <reified T : Any> Arb.Companion.bind(providedArbs: Map<KClass<*>, Arb<*>> = emptyMap()): Arb<T> =26 bind(providedArbs, T::class)27/**28 * Alias for [Arb.Companion.bind]29 *30 * Returns an [Arb] where each value is a randomly created instance of [T].31 * These instances are created by selecting the primaryConstructor of T and then32 * auto-detecting a generator for each parameter of that constructor.33 * T must be a class type.34 *35 * [providedArbs] allows you to provide a mapping of [KClass] to [Arb], for any given class [T].36 * This can be used to control parts of the data generation, as well as including non-data classes in the37 * hierarchies for which an [Arb] is being derived.38 *39 * Note: This method only supports parameters the following kind of parameter:40 * - Data classes, where all properties also fall into this category41 * - Pair, where 1st and 2nd fall into this category42 * - Primitives43 * - LocalDate, LocalDateTime, LocalTime, Period44 * - BigDecimal45 * - Collections (Set, List, Map)46 */47inline fun <reified T : Any> Arb.Companion.data(providedArbs: Map<KClass<*>, Arb<*>> = emptyMap()): Arb<T> =48 Arb.bind(providedArbs)49/**50 * Returns an [Arb] where each value is a randomly created instance of [T].51 * These instances are created by selecting the primaryConstructor of T and then52 * auto-detecting a generator for each parameter of that constructor.53 * T must be a class type.54 *55 * [providedArbs] allows you to provide a mapping of [KClass] to [Arb], for any given class [T].56 * This can be used to control parts of the data generation, as well as including non-data classes in the57 * hierarchies for which an [Arb] is being derived.58 *59 * Note: This method only supports parameters the following kind of parameter:60 * - Data classes, where all properties also fall into this category61 * - Pair, where 1st and 2nd fall into this category62 * - Primitives63 * - Enums64 * - LocalDate, LocalDateTime, LocalTime, Period, Instant65 * - BigDecimal, BigInteger66 * - Collections (Set, List, Map)67 */68fun <T : Any> Arb.Companion.bind(providedArbs: Map<KClass<*>, Arb<*>>, kclass: KClass<T>): Arb<T> {69 val constructor = kclass.primaryConstructor ?: error("could not locate a primary constructor")70 check(constructor.parameters.isNotEmpty()) { "${kclass.qualifiedName} constructor must contain at least 1 parameter" }71 val arbs: List<Arb<*>> = constructor.parameters.map { param ->72 val arb = Arb.forType(providedArbs, param.type)73 ?: error("Could not locate generator for parameter ${kclass.qualifiedName}.${param.name}")74 if (param.type.isMarkedNullable) arb.orNull() else arb75 }76 return Arb.bind(arbs) { params -> constructor.call(*params.toTypedArray()) }77}78internal fun Arb.Companion.forType(providedArbs: Map<KClass<*>, Arb<*>>, type: KType): Arb<*>? {79 return (type.classifier as? KClass<*>)?.let { providedArbs[it] ?: defaultForClass(it) }80 ?: targetDefaultForType(providedArbs, type)81}...

Full Screen

Full Screen

bigdecimal.kt

Source:bigdecimal.kt Github

copy

Full Screen

1package io.kotest.property.arbitrary2import io.kotest.property.Arb3import java.math.BigDecimal4import java.math.RoundingMode5internal val bigDecimalDefaultEdgecases = listOf(6 BigDecimal(0.0),7 // BigDecimal compareTo and equals are not consistent8 BigDecimal("0.00"),9 BigDecimal(1.0),10 BigDecimal(-1.0),11 BigDecimal("1e-300"),12 BigDecimal("-1e-300"),13)14fun Arb.Companion.bigDecimal(): Arb<BigDecimal> {15 return arbitrary(bigDecimalDefaultEdgecases) {16 if (it.random.nextInt() % 2 == 0) {17 BigDecimal(it.random.nextLong()) * BigDecimal(it.random.nextDouble())18 } else {19 BigDecimal(it.random.nextInt()) * BigDecimal(it.random.nextDouble())20 }21 }22}23fun Arb.Companion.bigDecimal(scale: Int, roundingMode: RoundingMode) =24 bigDecimal().map { it.setScale(scale, roundingMode) }25fun Arb.Companion.bigDecimal(min: BigDecimal, max: BigDecimal): Arb<BigDecimal> {26 val boundedEdgecases = bigDecimalDefaultEdgecases27 .filter { min <= it && it < max }28 .plus(min)29 return arbitrary(boundedEdgecases) {30 min.add(BigDecimal(it.random.nextDouble()).multiply(max.subtract(min)))31 }32}...

Full Screen

Full Screen

Arb.Companion.bigDecimal

Using AI Code Generation

copy

Full Screen

1val arbBigDecimal = Arb.bigDecimal()2val arbBigDecimal = Arb.bigDecimal()3val arbBigDecimal = Arb.bigDecimal()4val arbBigDecimal = Arb.bigDecimal()5val arbBigDecimal = Arb.bigDecimal()6val arbBigDecimal = Arb.bigDecimal()7val arbBigDecimal = Arb.bigDecimal()8val arbBigDecimal = Arb.bigDecimal()9val arbBigDecimal = Arb.bigDecimal()10val arbBigDecimal = Arb.bigDecimal()11val arbBigDecimal = Arb.bigDecimal()12val arbBigDecimal = Arb.bigDecimal()13val arbBigDecimal = Arb.bigDecimal()14val arbBigDecimal = Arb.bigDecimal()15val arbBigDecimal = Arb.bigDecimal()16val arbBigDecimal = Arb.bigDecimal()17val arbBigDecimal = Arb.bigDecimal()18val arbBigDecimal = Arb.bigDecimal()19val arbBigDecimal = Arb.bigDecimal()20val arbBigDecimal = Arb.bigDecimal()21val arbBigDecimal = Arb.bigDecimal()22val arbBigDecimal = Arb.bigDecimal()23val arbBigDecimal = Arb.bigDecimal()24val arbBigDecimal = Arb.bigDecimal()25val arbBigDecimal = Arb.bigDecimal()26val arbBigDecimal = Arb.bigDecimal()27val arbBigDecimal = Arb.bigDecimal()28val arbBigDecimal = Arb.bigDecimal()

Full Screen

Full Screen

Arb.Companion.bigDecimal

Using AI Code Generation

copy

Full Screen

1val arbBigDecimal = Arb.bigDecimal()2val arbBigDecimal = Arb.bigDecimal(scale = 5, range = BigDecimal.ZERO..BigDecimal.TEN)3val arbBigDecimal = Arb.bigDecimal(scale = 5, range = BigDecimal.ZERO..BigDecimal.TEN, precision = 10)4val arbBigDecimal = Arb.bigDecimal(precision = 10)5val arbBigDecimal = Arb.bigDecimal(scale = 5)6val arbBigDecimal = Arb.bigDecimal(range = BigDecimal.ZERO..BigDecimal.TEN)7val arbBigInt = Arb.bigInt()8val arbBigInt = Arb.bigInt(range = BigInteger.ZERO..BigInteger.TEN)9val arbBigInt = Arb.bigInt(precision = 10)10val arbBoolean = Arb.boolean()11val arbByte = Arb.byte()12val arbByte = Arb.byte(range = Byte.MIN_VALUE..Byte.MAX_VALUE)13val arbChar = Arb.char()14val arbChar = Arb.char(range = Char.MIN_VALUE..Char.MAX_VALUE)

Full Screen

Full Screen

Arb.Companion.bigDecimal

Using AI Code Generation

copy

Full Screen

1 arb.bigDecimal(10, 2, BigDecimal.valueOf(100), BigDecimal.valueOf(1000))2 arb.bigDecimal(10, 2, BigDecimal.valueOf(100), BigDecimal.valueOf(1000))3 arb.bigDecimal(10, 2, BigDecimal.valueOf(100), BigDecimal.valueOf(1000))4 arb.bigDecimal(10, 2, BigDecimal.valueOf(100), BigDecimal.valueOf(1000))5 arb.bigDecimal(10, 2, BigDecimal.valueOf(100), BigDecimal.valueOf(1000))6 arb.bigDecimal(10, 2, BigDecimal.valueOf(100), BigDecimal.valueOf(1000))7 arb.bigDecimal(10, 2, BigDecimal.valueOf(100), BigDecimal.valueOf(1000))8 arb.bigDecimal(10, 2, BigDecimal.valueOf(100), BigDecimal.valueOf(1000))9 arb.bigDecimal(10, 2, BigDecimal.valueOf(100), BigDecimal.valueOf(1000))10 arb.bigDecimal(10, 2, BigDecimal.valueOf(100), BigDecimal.valueOf(1000))11 arb.bigDecimal(10, 2, BigDecimal.valueOf(100), BigDecimal.valueOf(1000))12 arb.bigDecimal(10, 2, BigDecimal.valueOf(100), BigDecimal.valueOf(1000))

Full Screen

Full Screen

Arb.Companion.bigDecimal

Using AI Code Generation

copy

Full Screen

1val arbBigDecimal = Arb.bigDecimal()2val arbBigDecimalRange = Arb.bigDecimal(BigDecimal.valueOf(0.5), BigDecimal.valueOf(1.5))3val arbBigDecimalRangeAndScale = Arb.bigDecimal(BigDecimal.valueOf(0.5), BigDecimal.valueOf(1.5), 2)4val arbBigDecimalRangeAndScaleAndMode = Arb.bigDecimal(BigDecimal.valueOf(0.5), BigDecimal.valueOf(1.5), 2, RoundingMode.HALF_EVEN)5val arbBigDecimalRangeAndScaleAndModeAndStep = Arb.bigDecimal(BigDecimal.valueOf(0.5), BigDecimal.valueOf(1.5), 2, RoundingMode.HALF_EVEN, BigDecimal.valueOf(0.1))6val arbBigDecimalRangeAndScaleAndModeAndStepAndPrecision = Arb.bigDecimal(BigDecimal.valueOf(0.5), BigDecimal.valueOf(1.5), 2, RoundingMode.HALF_EVEN, BigDecimal.valueOf(0.1), 4)7val arbBigDecimal = Arb.bigDecimal()8val arbBigDecimalRange = Arb.bigDecimal(BigDecimal.valueOf(0.5), BigDecimal.valueOf(1.5))9val arbBigDecimalRangeAndScale = Arb.bigDecimal(BigDecimal.valueOf(0.5), BigDecimal.valueOf(1.5), 2)10val arbBigDecimalRangeAndScaleAndMode = Arb.bigDecimal(BigDecimal.valueOf(0.5), BigDecimal.valueOf(1.5), 2, RoundingMode.HALF_EVEN)11val arbBigDecimalRangeAndScaleAndModeAndStep = Arb.bigDecimal(BigDecimal.valueOf(0.5), BigDecimal.valueOf(1.5), 2, RoundingMode.HALF_EVEN, BigDecimal.valueOf(0.1))12val arbBigDecimalRangeAndScaleAndModeAndStepAndPrecision = Arb.bigDecimal(BigDecimal.valueOf(0.5), BigDecimal.valueOf(1.5), 2, RoundingMode.HALF_EVEN, BigDecimal.valueOf(0.1), 4)13val arbBigDecimal = Arb.bigDecimal()14val arbBigDecimalRange = Arb.bigDecimal(BigDecimal.valueOf(0.5), BigDecimal.valueOf(1.5))15val arbBigDecimalRangeAndScale = Arb.bigDecimal(BigDecimal.valueOf(0.5), BigDecimal.valueOf(1.5), 2)

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.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in bigdecimal

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful