How to use bigint class of io.kotest.property.arbitrary package

Best Kotest code snippet using io.kotest.property.arbitrary.bigint

StrictScalarModuleKotlinSpec.kt

Source:StrictScalarModuleKotlinSpec.kt Github

copy

Full Screen

1@file:Suppress("BlockingMethodInNonBlockingContext")2package io.github.portfoligno.jackson.scalar.test3import com.fasterxml.jackson.databind.ObjectMapper4import com.fasterxml.jackson.module.kotlin.readValue5import io.github.portfoligno.jackson.scalar.DiscreteFloatingPointRoundingMode6import io.github.portfoligno.jackson.scalar.StrictScalarModule7import io.kotest.core.spec.style.StringSpec8import io.kotest.matchers.shouldBe9import io.kotest.property.Arb10import io.kotest.property.arbitrary.*11import io.kotest.property.checkAll12import java.math.BigDecimal13import java.math.BigInteger14import java.util.concurrent.atomic.AtomicBoolean15import java.util.concurrent.atomic.AtomicInteger16import java.util.concurrent.atomic.AtomicLong17class StrictScalarModuleKotlinSpec : StringSpec({18 val mappers = Arb.element(DiscreteFloatingPointRoundingMode19 .values()20 .map { ObjectMapper().registerModule(StrictScalarModule(it)) })21 "Round-trip for `String` should work" {22 checkAll(mappers, Arb.string()) { m, v ->23 m.readValue<String>(m.writeValueAsString(v)) shouldBe v24 }25 }26 "Round-trip for `Char` should work" {27 checkAll(mappers, Arb.char()) { m, v ->28 m.readValue<Char>(m.writeValueAsString(v)) shouldBe v29 }30 }31 "Round-trip for `CharArray` should work" {32 checkAll(mappers, Arb.list(Arb.char()).map { it.toCharArray() }) { m, v ->33 m.readValue<CharArray>(m.writeValueAsString(v)) shouldBe v34 }35 }36 "Round-trip for `Boolean` should work" {37 checkAll(mappers, Arb.bool()) { m, v ->38 m.readValue<Boolean>(m.writeValueAsString(v)) shouldBe v39 }40 }41 "Round-trip for `BooleanArray` should work" {42 checkAll(mappers, Arb.list(Arb.bool()).map { it.toBooleanArray() }) { m, v ->43 m.readValue<BooleanArray>(m.writeValueAsString(v)) shouldBe v44 }45 }46 "Round-trip for `AtomicBoolean` should work" {47 checkAll(mappers, Arb.bool().map(::AtomicBoolean)) { m, v ->48 m.readValue<AtomicBoolean>(m.writeValueAsString(v)).get() shouldBe v.get()49 }50 }51 "Round-trip for `BigDecimal` should work" {52 checkAll(mappers, Arb.double().filter(Double::isFinite).map(::BigDecimal)) { m, v ->53 m.readValue<BigDecimal>(m.writeValueAsString(v)) shouldBe v54 }55 }56 "Round-trip for `BigInteger` should work" {57 checkAll(mappers, Arb.bigInt(256)) { m, v ->58 m.readValue<BigInteger>(m.writeValueAsString(v)) shouldBe v59 }60 }61 "Round-trip for `Double` should work" {62 checkAll(mappers, Arb.double().filter(Double::isFinite)) { m, v ->63 val result = m.readValue<Double>(m.writeValueAsString(v))64 (result == v) shouldBe true // `shouldBe` have issue with -0.065 }66 }67 "Round-trip for `DoubleArray` should work" {68 checkAll(mappers, Arb.list(Arb.double().filter(Double::isFinite)).map { it.toDoubleArray() }) { m, v ->69 val result = m.readValue<DoubleArray>(m.writeValueAsString(v))70 (result.zip(v).all { (a, b) -> a == b }) shouldBe true // `shouldBe` have issue with -0.071 }72 }73 "Round-trip for `Float` should work" {74 checkAll(mappers, Arb.float().filter(Float::isFinite)) { m, v ->75 m.readValue<Float>(m.writeValueAsString(v)) shouldBe v76 }77 }78 "Round-trip for `FloatArray` should work" {79 checkAll(mappers, Arb.list(Arb.float().filter(Float::isFinite)).map { it.toFloatArray() }) { m, v ->80 m.readValue<FloatArray>(m.writeValueAsString(v)) shouldBe v81 }82 }83 "Round-trip for `Long` should work" {84 checkAll(mappers, Arb.long()) { m, v ->85 m.readValue<Long>(m.writeValueAsString(v)) shouldBe v86 }87 }88 "Round-trip for `LongArray` should work" {89 checkAll(mappers, Arb.list(Arb.long()).map { it.toLongArray() }) { m, v ->90 m.readValue<LongArray>(m.writeValueAsString(v)) shouldBe v91 }92 }93 "Round-trip for `AtomicLong` should work" {94 checkAll(mappers, Arb.long().map(::AtomicLong)) { m, v ->95 m.readValue<AtomicLong>(m.writeValueAsString(v)).get() shouldBe v.get()96 }97 }98 "Round-trip for `Int` should work" {99 checkAll(mappers, Arb.int()) { m, v ->100 m.readValue<Int>(m.writeValueAsString(v)) shouldBe v101 }102 }103 "Round-trip for `IntArray` should work" {104 checkAll(mappers, Arb.list(Arb.int()).map { it.toIntArray() }) { m, v ->105 m.readValue<IntArray>(m.writeValueAsString(v)) shouldBe v106 }107 }108 "Round-trip for `AtomicInteger` should work" {109 checkAll(mappers, Arb.int().map(::AtomicInteger)) { m, v ->110 m.readValue<AtomicInteger>(m.writeValueAsString(v)).get() shouldBe v.get()111 }112 }113 "Round-trip for `Short` should work" {114 checkAll(mappers, Arb.short()) { m, v ->115 m.readValue<Short>(m.writeValueAsString(v)) shouldBe v116 }117 }118 "Round-trip for `ShortArray` should work" {119 checkAll(mappers, Arb.list(Arb.short()).map { it.toShortArray() }) { m, v ->120 m.readValue<ShortArray>(m.writeValueAsString(v)) shouldBe v121 }122 }123 "Round-trip for `Byte` should work" {124 checkAll(mappers, Arb.byte()) { m, v ->125 m.readValue<Byte>(m.writeValueAsString(v)) shouldBe v126 }127 }128})...

Full Screen

Full Screen

FibonacciKotestExampleBased.kt

Source:FibonacciKotestExampleBased.kt Github

copy

Full Screen

...28 row(0, zero),29 row(1, one),30 row(2, one),31 row(3, two),32 row(4, 3.bigint),33 row(5, 5.bigint),34 row(6, 8.bigint),35 row(7, 13.bigint),36 row(8, 21.bigint),37 row(9, 34.bigint),38 row(10, 55.bigint),39 row(11, 89.bigint),40 row(12, 144.bigint),41 row(13, 233.bigint),42 row(14, 377.bigint),43 row(15, 610.bigint),44 row(16, 987.bigint),45 row(17, 1597.bigint),46 row(18, 2584.bigint),47 row(19, 4181.bigint),48 row(20, 6765.bigint),49 ) { n, r ->50 "$name($n) == $r" {51 f(n) == r52 }53 }54 }55 }56 }57 "negative arguments throw IllegalArgumentException" - {58 forAll(functions) { name, f ->59 name - {60 checkAll(Arb.negativeInts()) { n ->61 shouldThrow<IllegalArgumentException> {62 f(n)...

Full Screen

Full Screen

targetDefaultForClassName.kt

Source:targetDefaultForClassName.kt Github

copy

Full Screen

1package io.kotest.property.arbitrary2import io.kotest.property.Arb3import java.lang.reflect.ParameterizedType4import java.lang.reflect.Type5import java.math.BigDecimal6import java.math.BigInteger7import java.time.Instant8import java.time.LocalDate9import java.time.LocalDateTime10import java.time.LocalTime11import java.time.Period12import kotlin.reflect.KClass13import kotlin.reflect.KType14import kotlin.reflect.full.isSubclassOf15import kotlin.reflect.full.superclasses16import kotlin.reflect.typeOf17@Suppress("UNCHECKED_CAST")18actual inline fun <reified A> targetDefaultForClass(): Arb<A>? = targetDefaultForType(type = typeOf<A>()) as Arb<A>?19fun targetDefaultForType(providedArbs: Map<KClass<*>, Arb<*>> = emptyMap(), type: KType): Arb<*>? {20 val clazz = type.classifier as? KClass<*>21 return when {22 clazz?.isSubclassOf(List::class) == true -> {23 val upperBound = type.arguments.first().type ?: error("No bound for List")24 Arb.list(Arb.forType(providedArbs, upperBound) as Arb<Any>)25 }26 clazz?.isSubclassOf(Set::class) == true -> {27 val upperBound = type.arguments.first().type ?: error("No bound for Set")28 Arb.set(Arb.forType(providedArbs, upperBound) as Arb<Any>)29 }30 clazz?.isSubclassOf(Pair::class) == true -> {31 val first = type.arguments[0].type ?: error("No bound for first type parameter of Pair")32 val second = type.arguments[1].type ?: error("No bound for second type parameter of Pair")33 Arb.pair(Arb.forType(providedArbs, first)!!, Arb.forType(providedArbs, second)!!)34 }35 clazz?.isSubclassOf(Map::class) == true -> {36 // map key type can have or have not variance37 val first = type.arguments[0].type ?: error("No bound for first type parameter of Map<K, V>")38 val second = type.arguments[1].type ?: error("No bound for second type parameter of Map<K, V>")39 Arb.map(Arb.forType(providedArbs, first)!!, Arb.forType(providedArbs, second)!!)40 }41 clazz?.isSubclassOf(Enum::class) == true -> {42 Arb.of(Class.forName(clazz.java.name).enumConstants.map { it as Enum<*> })43 }44 type == typeOf<Instant>() -> Arb.instant()45 type == typeOf<LocalDate>() -> Arb.localDate()46 type == typeOf<LocalDateTime>() -> Arb.localDateTime()47 type == typeOf<LocalTime>() -> Arb.localTime()48 type == typeOf<Period>() -> Arb.period()49 type == typeOf<BigDecimal>() -> Arb.bigDecimal()50 type == typeOf<BigInteger>() -> Arb.bigInt(maxNumBits = 256)51 clazz?.isData == true -> {52 val k = clazz as KClass<Any>53 Arb.bind(providedArbs, k)54 }55 else -> null56 }57}58// need some supertype that types a type param so it gets baked into the class file59abstract class TypeReference<T> : Comparable<TypeReference<T>> {60 // this is the type of T61 val type: Type = (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0]62 override fun compareTo(other: TypeReference<T>) = 063}...

Full Screen

Full Screen

FactorialKotestPropertyBased.kt

Source:FactorialKotestPropertyBased.kt Github

copy

Full Screen

...24 )25 "base case" - {26 forAll(functions) { name, f ->27 "$name(0) == 1" {28 f(0) == 1.bigint29 }30 }31 }32 "factorial recurrence relation is true for non-negative integer arguments" - {33 forAll(functions) { name, f ->34 name - {35 forAll(Arb.int(1, 2000)) { i ->36 f(i + 1) == (i + 1).bigint * f(i)37 }38 }39 }40 }41 "negative arguments result in IllegalArgumentException" - {42 forAll(functions) { name, f ->43 name - {44 checkAll(Arb.negativeInts()) { n ->45 shouldThrow<IllegalArgumentException> {46 f(n)47 }48 }49 }50 }...

Full Screen

Full Screen

BigIntArbTest.kt

Source:BigIntArbTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.property.arbitrary2import io.kotest.core.spec.style.ShouldSpec3import io.kotest.matchers.ints.shouldBeBetween4import io.kotest.matchers.ints.shouldBeGreaterThan5import io.kotest.property.Arb6import io.kotest.property.arbitrary.bigInt7import io.kotest.property.checkAll8import java.math.BigInteger9class BigIntArbTest : ShouldSpec({10 should("Generate different big ints") {11 val generated = mutableSetOf<BigInteger>()12 Arb.bigInt(100).checkAll { generated += it }13 generated.size shouldBeGreaterThan 50014 }15 should("Generate all big ints with the same probability") {16 val generated = hashMapOf<BigInteger, Int>()17 Arb.bigInt(4, 4).checkAll(100_000) {18 generated.merge(it, 1) { a, b -> a + b }19 }20 generated.forEach {21 // Each value should be generated 100_000/2^4 times, so ~625022 it.value.shouldBeBetween(5800, 6600)23 }24 }25})...

Full Screen

Full Screen

bigint.kt

Source:bigint.kt Github

copy

Full Screen

1package io.kotest.property.arbitrary2import io.kotest.property.Arb3import java.math.BigInteger4import kotlin.random.asJavaRandom5/**6 * Generates random BigIntegers from the [range]7 */8fun Arb.Companion.bigInt(range: IntRange) = int(range).map { it.toBigInteger() }9/**10 * Generate random BigIntegers with bits ranging from 0 to [maxNumBits]11 */12fun Arb.Companion.bigInt(maxNumBits: Int) = bigInt(0, maxNumBits)13/**14 * Generate random BigIntegers with bits ranging from [minNumBits] to [maxNumBits]15 */16fun Arb.Companion.bigInt(minNumBits: Int, maxNumBits: Int): Arb<BigInteger> {17 return arbitrary { rs ->18 val numBits = Arb.int(minNumBits, maxNumBits).next(rs)19 BigInteger(numBits, rs.random.asJavaRandom())20 }21}...

Full Screen

Full Screen

bigint

Using AI Code Generation

copy

Full Screen

1 import io.kotest.property.arbitrary.bigint2 import io.kotest.property.arbitrary.int3 import io.kotest.property.arbitrary.string4 import io.kotest.property.arbitrary.withEdgecases5 import io.kotest.property.checkAll6 import io.kotest.property.edgecases7 import io.kotest.property.exhaustive.ints8 import io.kotest.property.exhaustive.strings9 import io.kotest.property.exhaustive.withEdgecases10 import io.kotest.property.exhaustive.withNulls11 import io.kotest.property.exhaustive.withoutNulls12 import io.kotest.property.exhaustive.withoutValues13 import io.kotest.property.exhaustive

Full Screen

Full Screen

bigint

Using AI Code Generation

copy

Full Screen

1import io.kotest.property.arbitrary.bigInt2import io.kotest.property.arbitrary.filter3import io.kotest.property.arbitrary.int4import io.kotest.property.arbitrary.map5import io.kotest.property.arbitrary.take6import io.kotest.property.arbitrary.withEdgecases7import io.kotest.property.checkAll8fun main() {9 checkAll<Int> { n ->10 println(n)11 }12}13fun main() {14 checkAll<Int> { n ->15 println(n)16 }.withEdgecases(1, 2, 3, 4, 5)17}18fun main() {19 checkAll<Int> { n ->20 println(n)21 }.withEdgecases(1, 2, 3, 4, 5).take(10)22}23fun main() {24 checkAll<Int> { n ->25 println(n)26 }.withEdgecases(1, 2, 3, 4, 5).take(10).filter { it > 0 }27}28fun main() {29 checkAll<Int> { n ->30 println(n)31 }.withEdgecases(1, 2, 3, 4, 5).take(10).filter { it > 0 }.map { it.toString() }32}33fun main() {34 checkAll<Int> { n ->35 println(n)36 }.withEdgecases(1, 2, 3, 4, 5).take(10).filter { it > 0 }.map { it.toString() }.withEdgecases("a", "b", "c")37}38fun main() {39 checkAll<Int> { n ->40 println(n)41 }.withEdgecases(1, 2, 3, 4, 5).take(10).filter { it > 0 }.map { it.toString() }.withEdgecases("a", "b", "c").take(5)42}43fun main() {44 checkAll<Int> { n ->45 println(n)46 }.withEdgecases(1, 2, 3, 4, 5).take(10).filter { it > 0 }.map { it.toString() }.withEdgecases("a", "b", "c").take(5).withEdgecases("x", "y", "z")47}48fun main()

Full Screen

Full Screen

bigint

Using AI Code Generation

copy

Full Screen

1val bigInt = io.kotest.property.arbitrary.bigInt()2val bigDecimal = io.kotest.property.arbitrary.bigDecimal()3val char = io.kotest.property.arbitrary.char()4val charRange = io.kotest.property.arbitrary.charRange()5val charSequence = io.kotest.property.arbitrary.charSequence()6val constant = io.kotest.property.arbitrary.constant()7val date = io.kotest.property.arbitrary.date()8val double = io.kotest.property.arbitrary.double()9val doubleRange = io.kotest.property.arbitrary.doubleRange()10val float = io.kotest.property.arbitrary.float()11val floatRange = io.kotest.property.arbitrary.floatRange()12val int = io.kotest.property.arbitrary.int()

Full Screen

Full Screen

bigint

Using AI Code Generation

copy

Full Screen

1class PropertyTest : FunSpec({2 test("simple property test") {3 checkAll<Int> { a ->4 }5 }6 test("simple property test with two values") {7 checkAll<Int, Int> { a, b ->8 }9 }10 test("simple property test with three values") {11 checkAll<Int, Int, Int> { a, b, c ->12 }13 }14 test("property test with custom generator") {15 checkAll(Arb.ints(-1000..1000)) { a ->16 }17 }18 test("property test with custom generator and two values") {19 checkAll(Arb.ints(-1000..1000), Arb.ints(-1000..1000)) { a, b ->20 }21 }22 test("property test with custom generator and three values") {23 checkAll(Arb.ints(-1000..1000), Arb.ints(-1000..1000), Arb.ints(-1000..1000)) { a, b, c ->24 }25 }26 test("property test with custom generator and four values") {27 checkAll(Arb.ints(-1000..1000), Arb.ints(-1000..1000), Arb.ints(-1000..1000), Arb.ints(-1000..1000)) { a, b, c, d ->28 }29 }

Full Screen

Full Screen

bigint

Using AI Code Generation

copy

Full Screen

1val arbInt = Arb.bigint()2val arbLong = Arb.bigint(range = 1L..Long.MAX_VALUE)3val arbBigInteger = Arb.bigint(range = BigInteger.ONE..BigInteger.TEN)4val arbBigDecimal = Arb.bigdecimal()5val arbBigDecimal = Arb.bigdecimal(range = BigDecimal.ONE..BigDecimal.TEN)6val arbString = Arb.string()7val arbString = Arb.string(range = 1..10)8val arbString = Arb.string(range = 1..10, chars = CharRange('a', 'z'))9val arbString = Arb.string(range = 1..10, chars = CharRange('a', 'z'), alpha = false)10val arbString = Arb.string(range = 1..10, chars = CharRange('a', 'z'), alpha = false, numeric = false)11val arbString = Arb.string(range = 1..10, chars = CharRange('a', 'z'), alpha = false, numeric = false, whitespace = false)12val arbString = Arb.string(range = 1..10, chars = CharRange('a', 'z'), alpha = false, numeric = false, whitespace = false, punctuation = false)13val arbString = Arb.string(range = 1..10, chars = CharRange('a', 'z'), alpha = false, numeric = false, whitespace = false, punctuation = false, printables = false)14val arbString = Arb.string(range = 1..10, chars = CharRange('a', 'z'), alpha = false, numeric = false, whitespace = false, punctuation = false, printables = false, ascii = false)15val arbChar = Arb.char()16val arbChar = Arb.char(range = 'a'..'z')17val arbChar = Arb.char(range = 'a'..'z', alpha = false)18val arbChar = Arb.char(range = 'a'..'z', alpha = false, numeric = false)19val arbChar = Arb.char(range = 'a'..'z', alpha = false, numeric = false, whitespace = false)20val arbChar = Arb.char(range = 'a'..'z', alpha = false, numeric = false, whitespace = false, punctuation = false)

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 methods in bigint

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful