How to use ints class of io.kotest.property.exhaustive package

Best Kotest code snippet using io.kotest.property.exhaustive.ints

SectionTest.kt

Source:SectionTest.kt Github

copy

Full Screen

...38import io.kotest.property.arbitrary.int39import io.kotest.property.arbitrary.list40import io.kotest.property.arbitrary.string41import io.kotest.property.checkAll42import io.kotest.property.exhaustive.ints43class SectionTest : StringSpec(44 {45 val ledStrip = createNewEmulatedStrip(50)46 afterSpec {47 ledStrip.renderer.close()48 }49 "construction" {50 val section = Section()51 section.sections.shouldBeEmpty()52 section.subSections.shouldBeEmpty()53 section.name shouldBe ""54 section.numLEDs shouldBe 055 section.pixels.shouldHaveSize(0)56 shouldThrow<UninitializedPropertyAccessException> {57 section.stripManager58 }59 }60 "get physical index" {61 checkAll(Exhaustive.ints(0 until 49)) { s ->62 val section = LEDStripSectionManager(ledStrip).createSection("test:$s", s, 49)63 checkAll(Exhaustive.ints(0 until 49 - s)) { p ->64 section.getPhysicalIndex(p) shouldBe p + s65 }66 checkAll(Exhaustive.ints(0 until 49 - s)) { s2 ->67 val section2 = section.createSection("test:$s:$s2", s2, section.pixels.lastIndex)68 checkAll(Exhaustive.ints(0 until 49 - s - s2)) { p ->69 section2.getPhysicalIndex(p) shouldBe p + s + s270 }71 }72 checkAll(Arb.int().filter { it !in section.pixels.indices }) { p ->73 shouldThrow<IllegalArgumentException> {74 section.getPhysicalIndex(p)75 }76 }77 }78 }79 "get section" {80 val section = LEDStripSectionManager(ledStrip).fullStripSection81 section.getSection("test1") shouldBeSameInstanceAs section82 val sec = section.createSection("test1", 0, 15)...

Full Screen

Full Screen

RoomsKtTest.kt

Source:RoomsKtTest.kt Github

copy

Full Screen

...12import io.kotest.property.arbitrary.arbitrary13import io.kotest.property.arbitrary.enum14import io.kotest.property.arbitrary.set15import io.kotest.property.checkAll16import io.kotest.property.exhaustive.ints17import io.kotest.property.exhaustive.map18import io.kotest.property.forAll19import org.jetbrains.exposed.sql.insert20import org.jetbrains.exposed.sql.select21import org.jetbrains.exposed.sql.selectAll22import org.jetbrains.exposed.sql.transactions.transaction23import kotlin.random.nextInt24val directionSets = Arb.set(Arb.enum<Direction>(), 0..Direction.values().size)25val rotations = Exhaustive.ints(0..3).map { it.toShort() }26val invalidRotationValues = (Short.MIN_VALUE..Short.MAX_VALUE) - (0..3)27val invalidRotations = arbitrary(listOf(Short.MIN_VALUE, -1, 4, Short.MAX_VALUE), ShortShrinker) {28 it.random.nextInt(invalidRotationValues.indices).let { i -> invalidRotationValues[i] }.toShort()29}30class RoomsKtTest : DescribeSpec({31 useDatabase()32 describe("returnRoomToStack") {33 it("returns to empty stack") {34 transaction {35 val gameId = "ABCDEF"36 val stackId =37 RoomStacks.insert {38 it[this.gameId] = gameId39 it[curIndex] = null...

Full Screen

Full Screen

ExtensionsTest.kt

Source:ExtensionsTest.kt Github

copy

Full Screen

...5import io.kotest.assertions.throwables.shouldNotThrow6import io.kotest.assertions.throwables.shouldThrow7import io.kotest.core.spec.style.StringSpec8import io.kotest.matchers.comparables.shouldBeEqualComparingTo9import io.kotest.matchers.ints.shouldBeExactly10import io.kotest.matchers.longs.shouldBeExactly11import io.kotest.matchers.throwable.shouldHaveMessage12import io.kotest.property.Arb13import io.kotest.property.Exhaustive14import io.kotest.property.arbitrary.int15import io.kotest.property.arbitrary.long16import io.kotest.property.arbitrary.string17import io.kotest.property.checkAll18import io.kotest.property.exhaustive.ints19import java.nio.ByteBuffer20import java.nio.ByteOrder21import java.util.UUID22class ExtensionsTest : StringSpec() {23 init {24 // ByteArray.readAsUInt16()25 "Parsing bytes as UInt16 requires array of length 2" {26 checkAll(Exhaustive.ints(0 until 10)) { size ->27 when (size) {28 2 -> shouldNotThrow<IllegalArgumentException> { ByteArray(size).readAsUInt16() }29 else -> shouldThrow<IllegalArgumentException> {30 ByteArray(size).readAsUInt16()31 } shouldHaveMessage "Expected an unsigned 2 byte integer"32 }33 }34 }35 "Parsing bytes as UInt16 works" {36 checkAll(Arb.int(0, (1 shl 16) - 1)) { value ->37 val arr = ByteBuffer38 .allocate(4)39 .putInt(value)40 .order(ByteOrder.BIG_ENDIAN)41 .array()42 .takeLast(2)43 .toByteArray()44 arr.readAsUInt16() shouldBeExactly value45 }46 }47 // ByteArray.readAsUInt32()48 "Parsing bytes as UInt32 requires array of length 4" {49 checkAll(Exhaustive.ints(0 until 10)) { size ->50 when (size) {51 4 -> shouldNotThrow<IllegalArgumentException> { ByteArray(size).readAsUInt32() }52 else -> shouldThrow<IllegalArgumentException> {53 ByteArray(size).readAsUInt32()54 } shouldHaveMessage "Expected an unsigned 4 byte integer"55 }56 }57 }58 "Parsing bytes as UInt32 works" {59 checkAll(Arb.long(0L, (1L shl 32) - 1)) { value ->60 val arr = ByteBuffer61 .allocate(8)62 .putLong(value)63 .order(ByteOrder.BIG_ENDIAN)64 .array()65 .takeLast(4)66 .toByteArray()67 arr.readAsUInt32() shouldBeExactly value68 }69 }70 // ByteArray.toUUID()71 "Parsing bytes as UUID requires array of maximum length 16" {72 checkAll(Exhaustive.ints(0 until 32)) { size ->73 when {74 size <= 16 -> shouldNotThrow<IllegalArgumentException> { ByteArray(size).toUUID() }75 else -> shouldThrow<IllegalArgumentException> {76 ByteArray(size).toUUID()77 } shouldHaveMessage "Byte array must not contain more than 16 bytes"78 }79 }80 }81 "Parsing bytes as UUID works" {82 checkAll(Arb.string()) { value ->83 val uuid = UUID.nameUUIDFromBytes(value.toByteArray())84 val arr = uuid.let {85 ByteBuffer.allocate(16)86 .putLong(it.mostSignificantBits)...

Full Screen

Full Screen

GeneratorTests.kt

Source:GeneratorTests.kt Github

copy

Full Screen

...5import io.kotest.property.RandomSource6import io.kotest.property.arbitrary.*7import io.kotest.property.exhaustive.enum8import io.kotest.property.exhaustive.exhaustive9import io.kotest.property.exhaustive.ints10import io.kotest.property.forAll11import java.time.LocalDateTime12enum class Season { Winter, Fall, Spring, Summer }13data class Person(val name: String, val age: Int)14class GeneratorTests : StringSpec({15 //根据类型自动选择合适的generator16 "use forAll" {17 forAll<Int, Double, Boolean, String, LocalDateTime, Season>(10) { a, b, c, d, e, f ->18 println("$a $b $c $d $e $f")19 true20 }21 }22 //使用底层生成器Arbitrary 无限随机生成器23 "use generator" {24 Arb.int(1, 200).take(10).toList().run(::println)25 Arb.intArray(Arb.int(2, 8), Arb.int(200..400)).take(10).map { it.toList() }.toList().run(::println)26 Arb.char('a'..'z').take(10).toList().run(::println)27 Arb.stringPattern("\\w+[0-9]").take(10).toList().run(::println)28 Arb.list(Arb.int(), 1..5).take(10).toList().run(::println)29 }30 //使用有限生成器 Exhaustive31 "use exhaustive" {32 Exhaustive.enum<Season>().values.run(::println)33 Exhaustive.ints(1..10).values.run(::println)34 }35 //使用组合生成器36 "use complex operation" {37 Arb.choice(Arb.int(1..10), Arb.double(20.0..50.0)).take(10).toList().run(::println)38 Arb.bind(Arb.string(), Arb.int()) { name, age ->39 Person(name, age).run(::println)40 }41 Arb.choose(1 to Arb.int(1, 10), 2 to Arb.double(1.0, 5.0)).take(10).toList().run(::println)42 Arb.shuffle(listOf(1, 2, 3, 4, 5, 6)).take(10).toList().run(::println)43 Arb.subsequence(listOf(1, 2, 3, 4, 5, 6)).take(10).toList().run(::println)44 }45 //自定义生成器46 "custom generator" {47 val arb = arbitrary { rs: RandomSource ->...

Full Screen

Full Screen

BindActionTest.kt

Source:BindActionTest.kt Github

copy

Full Screen

...8import io.kotest.matchers.shouldBe9import io.kotest.property.Exhaustive10import io.kotest.property.checkAll11import io.kotest.property.exhaustive.boolean12import io.kotest.property.exhaustive.ints13import io.mockk.clearAllMocks14import io.mockk.confirmVerified15import io.mockk.every16import io.mockk.mockk17import io.mockk.verify18class BindActionTest : ShuffleboardWordSpec({19 val binding: InputBinding<InputAction, Any?> = mockk(relaxed = true)20 // These are lazy so that they don't get created until after HAL.initialize has been called21 val xboxController by lazy { XboxController(0) }22 val ps4Controller by lazy { PS4Controller(1) }23 val oi by lazy { OISubsystem(xboxController, ps4Controller) }24 val command by lazy { BindAction(binding, oi) }25 beforeTest {26 clearAllMocks()27 }28 "BindAction" should {29 "require the oi subsystem" {30 command.requirements shouldContain oi31 }32 "run when disabled" {33 command.runsWhenDisabled() shouldBe true34 }35 "bind to largest axis" {36 checkAll(Exhaustive.ints(0..1), Exhaustive.ints(1..6)) { port, channel ->37 every { binding.getSelectedChannel(any()) } returns null38 every { binding.getSelectedChannel(oi.joysticks[port]) } returns channel39 command.initialize()40 command.execute()41 command.isFinished shouldBe true42 verify { binding.bindTo(oi.joysticks[port], channel) }43 verify { binding.getSelectedChannel(any()) }44 confirmVerified(binding)45 }46 }47 "not bind before an axis is selected" {48 every { binding.getSelectedChannel(any()) } returns null49 command.initialize()50 repeat(10) {...

Full Screen

Full Screen

Exhaustive.kt

Source:Exhaustive.kt Github

copy

Full Screen

...6import io.kotest.property.arbitrary.byte7import io.kotest.property.arbitrary.next8import io.kotest.property.exhaustive.exhaustive9import io.kotest.property.exhaustive.filter10import io.kotest.property.exhaustive.ints11import io.kotest.property.exhaustive.map12fun <N : Number> Exhaustive<N>.toInt() = map { it.toInt() }13fun <N : Number> Exhaustive<N>.toShort() = map { it.toShort() }14fun Exhaustive.Companion.shorts(min: Short = Short.MIN_VALUE, max: Short = Short.MAX_VALUE) =15 Exhaustive.ints(min..max).map { it.toShort() }16fun Exhaustive.Companion.ubytes(min: UByte = UByte.MIN_VALUE, max: UByte = UByte.MAX_VALUE): Exhaustive<UByte> =17 Exhaustive.ints(min.toInt()..max.toInt()).map { it.toUByte() }18fun Exhaustive.Companion.ushorts(min: UShort = UShort.MIN_VALUE, max: UShort = UShort.MAX_VALUE): Exhaustive<UShort> =19 Exhaustive.ints(min.toInt()..max.toInt()).map { it.toUShort() }20fun Exhaustive.Companion.byteArrays(length: IntRange, byte: Gen<Byte> = Arb.byte()): Exhaustive<ByteArray> {21 val generator = byte.generate(RandomSource.Default).iterator()22 return length.map { ByteArray(it) { generator.next().value } }.exhaustive()23}24operator fun <A> Exhaustive<A>.minus(other: Exhaustive<A>) =25 filter { it !in other.values }26inline fun <reified T> Exhaustive.Companion.arrayOf(value: Arb<T>, length: IntRange): Exhaustive<Array<T>> {27 return length.map { Array(it) { value.next() } }.exhaustive()28}...

Full Screen

Full Screen

GeneratorSpec.kt

Source:GeneratorSpec.kt Github

copy

Full Screen

...3import io.kotest.property.Arb4import io.kotest.property.Exhaustive5import io.kotest.property.arbitrary.*6import io.kotest.property.exhaustive.enum7import io.kotest.property.exhaustive.ints8import io.kotest.property.exhaustive.merge9import io.kotest.property.exhaustive.times10import org.slf4j.event.Level11/** For string generator with leading zero */12/*1*/val numberCodepoint: Arb<Codepoint> = Arb.int(0x0030..0x0039)13 .map { Codepoint(it) }14/** For english string generator */15/*2*/val engCodepoint: Arb<Codepoint> = Arb.int('a'.toInt()..'z'.toInt())16 .merge(Arb.int('A'.toInt()..'Z'.toInt()))17 .map { Codepoint(it) }18class GeneratorSpec : FreeSpec() {19 init {20 "/*3*/ random number supported leading zero" {21 Arb.string(10, numberCodepoint).next()22 .also(::println)23 }24 "/*4*/ random english string" {25 Arb.string(10, engCodepoint).orNull(0.5).next()26 .also(::println)27 }28 "/*5*/ random russian mobile number" {29 Arb.stringPattern("+7\\(\\d{3}\\)\\d{3}-\\d{2}-\\d{2}").next()30 .also(::println)31 }32 "/*6*/ exhaustive collection and enum multiply" {33 Exhaustive.ints(1..5).times(Exhaustive.enum<Level>()).values34 .also(::println)35 }36 "/*7*/ exhaustive collection and enum merge" {37 Exhaustive.ints(1..5).merge(Exhaustive.enum<Level>()).values38 .also(::println)39 }40 }41}...

Full Screen

Full Screen

PropertyBasedWithGenerators.kt

Source:PropertyBasedWithGenerators.kt Github

copy

Full Screen

1package com.tsongkha.max2import io.kotest.assertions.withClue3import io.kotest.core.spec.style.StringSpec4import io.kotest.matchers.ints.shouldNotBeGreaterThan5import io.kotest.property.Arb6import io.kotest.property.PropertyTesting7import io.kotest.property.arbitrary.default8import io.kotest.property.arbitrary.filter9import io.kotest.property.checkAll10import io.kotest.property.exhaustive.exhaustive11import io.kotest.property.forAll12class PropertyBasedWithGenerators : StringSpec() {13 private val nonEmptyLists = Arb.default<List<Int>>().filter { it.isNotEmpty() }14 private val emptyLists = listOf(emptyList<Int>()).exhaustive()15 init {16 PropertyTesting.shouldPrintShrinkSteps = true17 PropertyTesting.shouldPrintGeneratedValues = true18 "no elements greater than myMax" {19 checkAll(nonEmptyLists) { ints ->20 val myMax = ints.myMax()!!21 ints.forEach {22 withClue("Element of list should not be greater than myMax") {23 it shouldNotBeGreaterThan myMax24 }25 }26 }27 }28 "myMax is in the collection" {29 forAll(nonEmptyLists) { ints ->30 val myMax = ints.myMax()!!31 ints.contains(myMax)32 }33 }34 "empty is null" {35 forAll(emptyLists) { ints ->36 ints.myMax() == null37 }38 }39 }40}

Full Screen

Full Screen

ints

Using AI Code Generation

copy

Full Screen

1val ints = ints()2val longs = longs()3val shorts = shorts()4val strings = strings()5val uuids = uuids()6val booleans = booleans()7val chars = chars()8val doubles = doubles()9val floats = floats()10val ints = ints()11val longs = longs()12val shorts = shorts()13val strings = strings()14val uuids = uuids()15val booleans = booleans()16val chars = chars()17val doubles = doubles()18val floats = floats()19val ints = ints()20val longs = longs()21val shorts = shorts()22val strings = strings()

Full Screen

Full Screen

ints

Using AI Code Generation

copy

Full Screen

1val ints = ints()2val longs = longs()3val booleans = booleans()4val strings = strings()5val charSequences = charSequences()6val chars = chars()7val doubles = doubles()8val floats = floats()9val bigIntegers = bigIntegers()10val bigDecimals = bigDecimals()11val dates = dates()12val localDates = localDates()13val localTimes = localTimes()14val localDateTimes = localDateTimes()15val instants = instants()16val durations = durations()17val periods = periods()18val uuids = uuids()19val enums = enums()20val arrays = arrays()21val lists = lists()

Full Screen

Full Screen

ints

Using AI Code Generation

copy

Full Screen

1val ints = ints()2val longs = longs()3val strings = strings()4val chars = chars()5val booleans = booleans()6val lists = lists()7val sets = sets()8val maps = maps()9val pairs = pairs()10val triples = triples()11val tuples = tuples()12val bigDecimals = bigDecimals()13val bigIntegers = bigIntegers()14val dates = dates()15val durations = durations()16val localDates = localDates()17val localTimes = localTimes()18val localDateTimes = localDateTimes()19val offsets = offsets()20val offsetsTime = offsetsTime()21val offsetsDateTime = offsetsDateTime()

Full Screen

Full Screen

ints

Using AI Code Generation

copy

Full Screen

1val ints = ints(10, 20)2val longs = longs(10L, 20L)3val booleans = booleans()4val chars = chars('a', 'z')5val strings = strings(5, 10, chars)6val doubles = doubles(10.5, 20.5)7val floats = floats(10.5f, 20.5f)8val bigDecimals = bigDecimals(10.5, 20.5)9val bigInts = bigInts(10, 20)10val dates = dates(10, 20)11val localDates = localDates(10, 20)12val localTimes = localTimes(10, 20)13val localDateTimes = localDateTimes(10, 20)14val instants = instants(10, 20)15val zonedDateTimes = zonedDateTimes(10, 20)16val durations = durations(10, 20)17val periods = periods(10, 20)

Full Screen

Full Screen

ints

Using AI Code Generation

copy

Full Screen

1val ints = ints()2val ints = ints(0, 100)3val ints = ints(Int.MIN_VALUE, Int.MAX_VALUE)4val ints = ints(0, 100, 10)5val ints = ints(0, 100, 10, 50)6val ints = ints(0, 100, 10, 50, 100)7val longs = longs()8val longs = longs(0, 100)9val longs = longs(Long.MIN_VALUE, Long.MAX_VALUE)10val longs = longs(0, 100, 10)11val longs = longs(0, 100, 10, 50)12val longs = longs(0, 100, 10, 50, 100)13val doubles = doubles()14val doubles = doubles(0.0, 100.0)15val doubles = doubles(Double.MIN_VALUE, Double.MAX_VALUE)16val doubles = doubles(0.0, 100.0, 10.0)17val doubles = doubles(0.0, 100.0, 10.0, 50.0)18val doubles = doubles(0.0, 100.0, 10.0, 50.0, 100.0)19val floats = floats()20val floats = floats(0.0f, 100.0f)21val floats = floats(Float.MIN_VALUE, Float.MAX_VALUE)22val floats = floats(0.0f, 100.0f, 10.0f)23val floats = floats(0.0f, 100.0f, 10.0f, 50.0f)24val floats = floats(0.0f, 100.0f, 10.0f, 50.0f, 100.0f)25val chars = chars()26val chars = chars('a', 'z')27val chars = chars(Char.MIN_VALUE, Char.MAX_VALUE)28val chars = chars('a', 'z', 10)29val chars = chars('a',

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful