Best Kotest code snippet using io.kotest.matchers.ints.uint
ContractRequirementsUnitTest.kt
Source:ContractRequirementsUnitTest.kt
1package io.provenance.scope.loan.utility2import io.kotest.assertions.throwables.shouldNotThrow3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.core.spec.style.WordSpec5import io.kotest.core.test.TestCaseOrder6import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual7import io.kotest.matchers.ints.shouldBeInRange8import io.kotest.matchers.ints.shouldBeLessThan9import io.kotest.matchers.shouldBe10import io.kotest.matchers.string.shouldContainIgnoringCase11import io.kotest.matchers.types.shouldBeTypeOf12import io.kotest.property.Arb13import io.kotest.property.arbitrary.list14import io.kotest.property.checkAll15import io.provenance.scope.loan.test.LoanPackageArbs16import io.provenance.scope.loan.test.shouldHaveViolationCount17class ContractRequirementsUnitTest : WordSpec({18 /* Helpers */19 fun getExpectedViolationCount(enforcements: List<ContractEnforcement>) =20 enforcements.fold(21 emptyMap<ContractViolation, UInt>() to 0U22 ) { (violationMap, overallCount), (rule, violationReport) ->23 if (!rule) {24 violationMap.getOrDefault(violationReport, 0U).let { currentIndividualCount ->25 if (currentIndividualCount == 0U) {26 violationMap.plus(violationReport to 1U) to overallCount + 1U27 } else {28 violationMap.plus(violationReport to currentIndividualCount + 1U) to overallCount29 }30 }31 } else {32 violationMap to overallCount33 }34 }.second35 /* Tests */36 "validateRequirements" When {37 "accepting a list of enforcements" should {38 "accept infix syntax" {39 checkAll<Boolean, ContractViolation> { rule, violationReport ->40 (rule orError violationReport).shouldBeTypeOf<ContractEnforcement>()41 (rule orError violationReport) shouldBe ContractEnforcement(rule, violationReport)42 }43 }44 "return state violations only for failed conditions" {45 checkAll(Arb.list(LoanPackageArbs.anyContractEnforcement)) { enforcementList ->46 val expectedOverallViolationCount = getExpectedViolationCount(enforcementList)47 if (expectedOverallViolationCount > 0U) {48 shouldThrow<IllegalContractStateException> {49 validateRequirements(ContractRequirementType.LEGAL_SCOPE_STATE, *enforcementList.toTypedArray())50 }.let { exception ->51 exception.message shouldContainIgnoringCase "state was invalid" // TODO: Make better check52 }53 } else {54 shouldNotThrow<IllegalContractStateException> {55 validateRequirements(ContractRequirementType.LEGAL_SCOPE_STATE, *enforcementList.toTypedArray())56 }57 }58 }59 }60 "return input violations only for failed conditions" {61 checkAll(Arb.list(LoanPackageArbs.anyContractEnforcement)) { enforcementList ->62 val expectedOverallViolationCount = getExpectedViolationCount(enforcementList)63 if (expectedOverallViolationCount > 0U) {64 shouldThrow<ContractViolationException> {65 validateRequirements(ContractRequirementType.VALID_INPUT, *enforcementList.toTypedArray())66 }.let { exception ->67 exception shouldHaveViolationCount expectedOverallViolationCount68 }69 } else {70 shouldNotThrow<ContractViolationException> {71 validateRequirements(ContractRequirementType.VALID_INPUT, *enforcementList.toTypedArray())72 }73 }74 }75 }76 }77 "invoked with a function body" should {78 "return state violations only for failed conditions" {79 checkAll(80 Arb.list(LoanPackageArbs.anyContractEnforcement),81 Arb.list(LoanPackageArbs.anyContractEnforcement),82 ) { enforcementListA, enforcementListB ->83 val expectedOverallViolationCount = getExpectedViolationCount(enforcementListA + enforcementListB)84 if (expectedOverallViolationCount > 0U) {85 shouldThrow<IllegalContractStateException> {86 validateRequirements(ContractRequirementType.LEGAL_SCOPE_STATE) {87 5 shouldBeGreaterThanOrEqual 488 requireThat(*enforcementListA.toTypedArray())89 3 shouldBeLessThan 490 requireThat(*enforcementListB.toTypedArray())91 2 shouldBeInRange 0..992 }93 }.let { exception ->94 exception.message shouldContainIgnoringCase "state was invalid" // TODO: Make better check95 }96 } else {97 shouldNotThrow<ContractViolationException> {98 validateRequirements(ContractRequirementType.VALID_INPUT) {99 2 shouldBeInRange 0..9100 requireThat(*enforcementListB.toTypedArray())101 5 shouldBeGreaterThanOrEqual 4102 requireThat(*enforcementListA.toTypedArray())103 3 shouldBeLessThan 4104 }105 }106 }107 }108 }109 "return input violations only for failed conditions" {110 checkAll(111 Arb.list(LoanPackageArbs.anyContractEnforcement),112 Arb.list(LoanPackageArbs.anyContractEnforcement),113 ) { enforcementListA, enforcementListB ->114 val expectedOverallViolationCount = getExpectedViolationCount(enforcementListA + enforcementListB)115 if (expectedOverallViolationCount > 0U) {116 shouldThrow<ContractViolationException> {117 validateRequirements(ContractRequirementType.VALID_INPUT) {118 5 shouldBeGreaterThanOrEqual 4119 requireThat(*enforcementListB.toTypedArray())120 3 shouldBeLessThan 4121 requireThat(*enforcementListA.toTypedArray())122 2 shouldBeInRange 0..9123 }124 }.let { exception ->125 exception shouldHaveViolationCount expectedOverallViolationCount126 }127 } else {128 shouldNotThrow<ContractViolationException> {129 validateRequirements(ContractRequirementType.VALID_INPUT) {130 2 shouldBeInRange 0..9131 requireThat(*enforcementListA.toTypedArray())132 5 shouldBeGreaterThanOrEqual 4133 requireThat(*enforcementListB.toTypedArray())134 3 shouldBeLessThan 4135 }136 }137 }138 }139 }140 }141 }142}) {143 override fun testCaseOrder() = TestCaseOrder.Random144}...
ByteBufIntSmart.kt
Source:ByteBufIntSmart.kt
1/*2 * Copyright 2018-2021 Guthix3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package io.guthix.buffer.bytebuf17import io.guthix.buffer.*18import io.kotest.core.spec.style.StringSpec19import io.kotest.matchers.ints.shouldBeNonNegative20import io.kotest.matchers.shouldBe21import io.kotest.property.Arb22import io.kotest.property.Shrinker23import io.kotest.property.arbitrary.*24import io.kotest.property.checkAll25import io.netty.buffer.ByteBuf26import io.netty.buffer.ByteBufAllocator27import kotlin.random.nextUInt28private suspend fun doIntSmartRWTest(29 writer: ByteBuf.(Int) -> ByteBuf,30 reader: ByteBuf.() -> Int31) = checkAll(Arb.intArray(collectionSizeArb, Arb.int(Smart.MIN_INT_VALUE, Smart.MAX_INT_VALUE))) { testData ->32 val buf = ByteBufAllocator.DEFAULT.buffer(testData.size * Short.SIZE_BYTES)33 try {34 testData.forEach { expected -> buf.writer(expected) }35 testData.forEach { expected ->36 val read = buf.reader()37 read shouldBe expected38 }39 } finally {40 buf.release()41 }42}43@ExperimentalUnsignedTypes44private suspend fun doUIntSmartRWTest(45 writer: ByteBuf.(Int) -> ByteBuf,46 reader: ByteBuf.() -> Int47) = checkAll(48 Arb.uIntArray(collectionSizeArb, Arb.uInt(USmart.MIN_INT_VALUE.toUInt(), USmart.MAX_INT_VALUE.toUInt()))49) { testData ->50 val buf = ByteBufAllocator.DEFAULT.buffer(testData.size * Short.SIZE_BYTES)51 try {52 testData.forEach { expected -> buf.writer(expected.toInt()) }53 testData.forEach { expected ->54 val read = buf.reader()55 read.shouldBeNonNegative()56 read shouldBe expected.toInt()57 }58 } finally {59 buf.release()60 }61}62fun Arb.Companion.nullableUInt(min: UInt = UInt.MIN_VALUE, max: UInt = UInt.MAX_VALUE) = nullableUInt(min..max)63fun Arb.Companion.nullableUInt(range: UIntRange = UInt.MIN_VALUE..UInt.MAX_VALUE): Arb<UInt?> {64 val edges = listOf(range.first, 1u, range.last).filter { it in range }.distinct()65 return arbitrary(edges, NullableUIntShrinker(range)) {66 if (it.random.nextFloat() < 0.40) null else it.random.nextUInt(range)67 }68}69class NullableUIntShrinker(private val range: UIntRange) : Shrinker<UInt?> {70 override fun shrink(value: UInt?): List<UInt?> = when (value) {71 null -> emptyList()72 0u -> emptyList()73 1u -> listOf(0u).filter { it in range }74 else -> {75 val a = listOf(0u, 1u, value / 3u, null, value / 2u, value * 2u / 3u)76 val b = (1u..5u).map { value - it }.reversed().filter { it > 0u }77 (a + b).distinct().filterNot { it == value }.filter { it in range }78 }79 }80}81@ExperimentalUnsignedTypes82private suspend fun doNullableUIntSmartRWTest(83 writer: ByteBuf.(Int?) -> ByteBuf,84 reader: ByteBuf.() -> Int?85) = checkAll(86 Arb.list(Arb.nullableUInt(USmart.MIN_INT_VALUE.toUInt(), USmart.MAX_INT_VALUE.toUInt()))87) { testData ->88 val buf = ByteBufAllocator.DEFAULT.buffer(testData.size * Short.SIZE_BYTES)89 try {90 testData.forEach { expected -> buf.writer(expected?.toInt()) }91 testData.forEach { expected ->92 val read = buf.reader()93 read?.shouldBeNonNegative()94 read shouldBe expected?.toInt()95 }96 } finally {97 buf.release()98 }99}100@ExperimentalUnsignedTypes101class ByteBufIntSmartTest : StringSpec({102 "Read/Write Int Smart" { doIntSmartRWTest(ByteBuf::writeIntSmart, ByteBuf::readIntSmart) }103 "Unsigned Read/Write Int Smart" {104 doUIntSmartRWTest(ByteBuf::writeUnsignedIntSmart, ByteBuf::readUnsignedIntSmart)105 }106 "Unsigned Read/Write Nullable Int Smart" {107 doNullableUIntSmartRWTest(ByteBuf::writeNullableUnsignedIntSmart, ByteBuf::readNullableUnsignedIntSmart)108 }109})...
ByteBufMediumTest.kt
Source:ByteBufMediumTest.kt
1/*2 * Copyright 2018-2021 Guthix3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package io.guthix.buffer.bytebuf17import io.guthix.buffer.*18import io.kotest.core.spec.style.StringSpec19import io.kotest.matchers.ints.shouldBeNonNegative20import io.kotest.matchers.shouldBe21import io.kotest.property.Arb22import io.kotest.property.arbitrary.*23import io.kotest.property.checkAll24import io.netty.buffer.ByteBuf25import io.netty.buffer.ByteBufAllocator26private suspend fun doMediumGSTest(27 setter: ByteBuf.(Int, Int) -> ByteBuf,28 getter: ByteBuf.(Int) -> Int29) = checkAll(Arb.intArray(collectionSizeArb, Arb.int(Medium.MIN_VALUE, Medium.MAX_VALUE))) { testData ->30 val buf = ByteBufAllocator.DEFAULT.buffer(testData.size * Medium.SIZE_BYTES)31 try {32 testData.forEachIndexed { i, expected -> buf.setter(i * Medium.SIZE_BYTES, expected) }33 testData.forEachIndexed { i, expected ->34 val get = buf.getter(i * Medium.SIZE_BYTES)35 get shouldBe expected36 }37 } finally {38 buf.release()39 }40}41private suspend fun doMediumRWTest(42 writer: ByteBuf.(Int) -> ByteBuf,43 reader: ByteBuf.() -> Int44) = checkAll(Arb.intArray(collectionSizeArb, Arb.int(Medium.MIN_VALUE, Medium.MAX_VALUE))) { testData ->45 val buf = ByteBufAllocator.DEFAULT.buffer(testData.size * Medium.SIZE_BYTES)46 try {47 testData.forEach { expected -> buf.writer(expected) }48 testData.forEach { expected ->49 val read = buf.reader()50 read shouldBe expected51 }52 } finally {53 buf.release()54 }55}56@ExperimentalUnsignedTypes57private suspend fun doUMediumGSTest(58 setter: ByteBuf.(Int, Int) -> ByteBuf,59 getter: ByteBuf.(Int) -> Int60) = checkAll(Arb.uIntArray(collectionSizeArb, Arb.uInt(UMedium.MIN_VALUE, UMedium.MAX_VALUE))) { testData ->61 val buf = ByteBufAllocator.DEFAULT.buffer(testData.size * UMedium.SIZE_BYTES)62 try {63 testData.forEachIndexed { i, expected -> buf.setter(i * UMedium.SIZE_BYTES, expected.toInt()) }64 testData.forEachIndexed { i, expected ->65 val get = buf.getter(i * UMedium.SIZE_BYTES)66 get.shouldBeNonNegative()67 get shouldBe expected.toInt()68 }69 } finally {70 buf.release()71 }72}73@ExperimentalUnsignedTypes74private suspend fun doUMediumRWTest(75 writer: ByteBuf.(Int) -> ByteBuf,76 reader: ByteBuf.() -> Int77) = checkAll(Arb.uIntArray(collectionSizeArb, Arb.uInt(UMedium.MIN_VALUE, UMedium.MAX_VALUE))) { testData ->78 val buf = ByteBufAllocator.DEFAULT.buffer(testData.size * UMedium.SIZE_BYTES)79 try {80 testData.forEach { expected -> buf.writer(expected.toInt()) }81 testData.forEach { expected ->82 val read = buf.reader()83 read.shouldBeNonNegative()84 read shouldBe expected.toInt()85 }86 } finally {87 buf.release()88 }89}90@ExperimentalUnsignedTypes91class ByteBufMediumTest : StringSpec({92 "Get/Set Medium LME" { doMediumGSTest(ByteBuf::setMediumLME, ByteBuf::getMediumLME) }93 "Read/Write Medium LME" { doMediumRWTest(ByteBuf::writeMediumLME, ByteBuf::readMediumLME) }94 "Unsigned Get/Set Medium LME" { doUMediumGSTest(ByteBuf::setMediumLME, ByteBuf::getUnsignedMediumLME) }95 "Unsigned Read/Write Medium LME" { doUMediumRWTest(ByteBuf::writeMediumLME, ByteBuf::readUnsignedMediumLME) }96 "Get/Set Medium RME" { doMediumGSTest(ByteBuf::setMediumRME, ByteBuf::getMediumRME) }97 "Read/Write Medium RME" { doMediumRWTest(ByteBuf::writeMediumRME, ByteBuf::readMediumRME) }98 "Unsigned Get/Set Medium RME" { doUMediumGSTest(ByteBuf::setMediumRME, ByteBuf::getUnsignedMediumRME) }99 "Unsigned Read/Write Medium RME" { doUMediumRWTest(ByteBuf::writeMediumRME, ByteBuf::readUnsignedMediumRME) }100})...
test.kt
Source:test.kt
1package unsigned2import io.kotest.core.spec.style.StringSpec3import io.kotest.matchers.ints.shouldBeLessThan4import io.kotest.matchers.shouldBe5import java.math.BigInteger6/**7 * Created by elect on 15/10/16.8 */9val Int.b10 get() = toByte()11val Int.s12 get() = toShort()13val Long.b14 get() = toByte()15val Long.s16 get() = toShort()17val Long.i18 get() = toInt()19val BigInteger.L20 get() = toLong()21/**22 * BUG, 0xffffffffffffffff is outside Long range23 * https://youtrack.jetbrains.com/issue/KT-474924 */25val String.hL: Long26 get() = java.lang.Long.parseUnsignedLong(filter { it != '_' && it != '\'' }, 16)27val String.L: Long28 get() = java.lang.Long.parseUnsignedLong(filter { it != '_' && it != '\'' })29val String.bL: Long30 get() = java.lang.Long.parseUnsignedLong(filter { it != '_' && it != '\'' }, 2)31class Unsigned : StringSpec() {32 init {33 "primitive" {34 250.b udiv 50.b shouldBe 5.b35 250.b urem 200.b shouldBe 50.b36 250.b ucmp 251.b shouldBeLessThan 137 250.b ucmp 250.b shouldBe 038 0b1010_1010.b ushr 4 shouldBe 0b1010.b39 65500.s udiv 500.s shouldBe 131.s40 65500.s urem 65000.s shouldBe 500.s41 65500.s ucmp 65501.s shouldBeLessThan 142 65500.s ucmp 65500.s shouldBe 043 0b0100_1100_0011_1101.s ushr 8 shouldBe 0b100_1100.s44 4_000_000_000.i udiv 2 shouldBe 2_000_000_00045 2_750_000_000.i urem 2_000_000_000 shouldBe 750_000_00046 4_000_000_000.i ucmp 4_000_000_001.i shouldBeLessThan 147 4_000_000_000.i ucmp 4_000_000_000.i shouldBe 048 "18_000_000_000_000_000_000".L udiv 2L shouldBe "9'000'000'000'000'000'000".L49 "17'000'000'000'000'000'000".L urem "9'000'000'000'000'000'000".L shouldBe "8'000'000'000'000'000'000".L50 "18'000'000'000'000'000'000".L ucmp "18'000'000'000'000'000'001".L shouldBeLessThan 151 "18'000'000'000'000'000'001".L ucmp "18'000'000'000'000'000'001".L shouldBe 052 }53 "string format" {54 Ubyte(0xff).v.toString() shouldBe "-1"55 Ubyte(0xff).toString() shouldBe "255"56 Ushort(0xffff).v.toString() shouldBe "-1"57 Ushort(0xffff).toString() shouldBe "65535"58 Uint(0xffff_ffff).v.toString() shouldBe "-1"59 Uint(0xffff_ffff).toString() shouldBe "4294967295"60 Ulong(Ulong.MAX_VALUE).v.toString() shouldBe "-1"61 Ulong(Ulong.MAX_VALUE).toString() shouldBe "18446744073709551615"62 Ubyte.MIN.toString(16) shouldBe "0"63 Ubyte.MAX.toString(16) shouldBe "ff"64 Ushort.MIN.toString(16) shouldBe "0"65 Ushort.MAX.toString(16) shouldBe "ffff"66 Uint.MIN.toString(16) shouldBe "0"67 Uint.MAX.toString(16) shouldBe "ffffffff"68 Ulong.MIN.toString(16) shouldBe "0"69 Ulong.MAX.toString(16) shouldBe "ffffffffffffffff"70 Ubyte.MAX.toString("%08x") shouldBe "000000ff"71// (-71777214294589696L).toBinaryString() shouldBe "1111111100000000111111110000000011111111000000001111111100000000"72 }73 }74}...
MapTest.kt
Source:MapTest.kt
1import io.kotest.matchers.shouldBe2import io.kotest.property.Arb3import io.kotest.property.Exhaustive4import io.kotest.property.arbitrary.int5import io.kotest.property.checkAll6import io.kotest.property.exhaustive.ints7import io.harmor.msgpack.internal.MessageType.MAP168import io.harmor.msgpack.internal.MessageType.MAP329import io.harmor.msgpack.IntegerValue10import io.harmor.msgpack.MapValue11import io.harmor.msgpack.ByteArraySink12import io.harmor.msgpack.msgpack13import utils.MessagePackerFactory14import utils.MessageUnpackerFactory15import utils.TypedElement16import utils.with17class MapTest : AbstractMessagePackTest() {18 init {19 "Packer" should {20 "use fixmap" {21 checkAll(Exhaustive.ints(0..15)) {22 it with packer shouldBe fixmap(it)23 }24 }25 "use map16" {26 checkAll(Arb.int(16..Short.MAX_VALUE)) {27 it with packer shouldBe map16(it)28 }29 }30 "use map32" {31 checkAll(Arb.int(65536..Int.MAX_VALUE)) {32 it with packer shouldBe map32(it)33 }34 }35 "encode null key" {36 val m = msgpack { nill() with "string" }37 m with packer shouldBe fixmap(m)38 }39 "encode null value" {40 val m = msgpack { "key" with null }41 m with packer shouldBe fixmap(m)42 }43 }44 "Unpacker" should {45 "decode fixmap" {46 checkAll(Exhaustive.ints(0..15)) {47 it with unpacker shouldBe fixmap(it)48 }49 }50 "decode map16" {51 checkAll(Arb.int(16..Short.MAX_VALUE)) {52 it with unpacker shouldBe map16(it)53 }54 }55 "decode map32" {56 checkAll(Arb.int(65536..Int.MAX_VALUE)) {57 it with unpacker shouldBe map32(it)58 }59 }60 }61 }62}63private fun fixmap(element: MapValue) = TypedElement((0x80 or element.size).toByte(), element)64private fun fixmap(size: Int) = TypedElement((0x80 or size).toByte(), IntegerValue.from(size))65private fun map16(size: Int) = TypedElement(MAP16, IntegerValue.from(size))66private fun map32(size: Int) = map32(size.toUInt())67private fun map32(size: UInt) = TypedElement(MAP32, IntegerValue.from(size))68private infix fun Int.with(packer: MessagePackerFactory): TypedElement =69 packer().let {70 it.beginMap(toUInt())71 (it.sink as ByteArraySink).toByteArray()72 }.let {73 val unpacker = org.msgpack.core.MessagePack.newDefaultUnpacker(it)74 TypedElement(it[0], IntegerValue.from(unpacker.unpackMapHeader()))75 }76private infix fun Int.with(unpacker: MessageUnpackerFactory) =77 org.msgpack.core.MessagePack.newDefaultBufferPacker().use { packer ->78 packer.packMapHeader(this) // FIXME: maximum size is Int.MAX_VALUE79 packer80 }.toByteArray().let {81 TypedElement(it[0], msgpack.int(unpacker(it).nextMapSize()))82 }83 ...
IntTest.kt
Source:IntTest.kt
1package com.sksamuel.kotest.property.arbitrary2import io.kotest.core.spec.style.FunSpec3import io.kotest.data.blocking.forAll4import io.kotest.data.row5import io.kotest.inspectors.forAll6import io.kotest.matchers.ints.*7import io.kotest.matchers.shouldBe8import io.kotest.property.Arb9import io.kotest.property.PropTest10import io.kotest.property.arbitrary.*11import io.kotest.property.checkAll12import io.kotest.property.checkCoverage13class IntTest : FunSpec({14 test("<Int, Int> should give values between min and max inclusive") {15 // Test parameters include the test for negative bounds16 forAll(17 row(-10, -1),18 row(1, 3),19 row(-100, 100),20 row(Int.MAX_VALUE - 10, Int.MAX_VALUE),21 row(Int.MIN_VALUE, Int.MIN_VALUE + 10)22 ) { vMin, vMax ->23 val expectedValues = (vMin..vMax).toSet()24 val actualValues = (1..100_000).map { Arb.int(vMin, vMax).single() }.toSet()25 actualValues shouldBe expectedValues26 }27 }28 test("Arb.int edge cases should respect min and max bounds") {29 checkCoverage("run", 25.0) {30 PropTest(iterations = 1000).checkAll<Int, Int> { min, max ->31 if (min < max) {32 classify("run")33 Arb.int(min..max).edgecases().forAll {34 it.shouldBeBetween(min, max)35 }36 }37 }38 }39 }40 test("Arb.positiveInts should return positive ints only") {41 val numbers = Arb.positiveInt().take(1000).toSet()42 numbers.forAll { it.shouldBePositive() }43 }44 test("Arb.nonNegativeInts should return non negative ints only") {45 val numbers = Arb.nonNegativeInt().take(1000).toSet()46 numbers.forAll { it.shouldBeNonNegative() }47 }48 test("Arb.negativeInts should return negative ints only") {49 val numbers = Arb.negativeInt().take(1000).toSet()50 numbers.forAll { it.shouldBeNegative() }51 }52 test("Arb.nonPositiveInts should return non positive ints only") {53 val numbers = Arb.nonPositiveInt().take(1000).toSet()54 numbers.forAll { it.shouldBeNonPositive() }55 }56})57class UIntTest : FunSpec({58 test("<UInt, UInt> should give values between min and max inclusive") {59 forAll(60 row(1u, 3u),61 row(0u, 100u),62 row(UInt.MAX_VALUE - 10u, UInt.MAX_VALUE),63 row(UInt.MIN_VALUE, UInt.MIN_VALUE + 10u)64 ) { vMin, vMax ->65 val expectedValues = (vMin..vMax).toSet()66 val actualValues = (1..100_000).map { Arb.uInt(vMin, vMax).single() }.toSet()67 actualValues shouldBe expectedValues68 }69 }70 test("Arb.uInt edge cases should respect min and max bounds") {71 checkCoverage("run", 25.0) {72 PropTest(iterations = 1000).checkAll<UInt, UInt> { min, max ->73 if (min < max) {74 classify("run")75 Arb.uInt(min..max).edgecases().forAll {76 it.shouldBeBetween(min, max)77 }78 }79 }80 }81 }82})...
ArrayTest.kt
Source:ArrayTest.kt
1import io.harmor.msgpack.IntegerValue2import io.harmor.msgpack.ByteArraySink3import io.harmor.msgpack.internal.MessageType.ARRAY164import io.harmor.msgpack.internal.MessageType.ARRAY325import io.harmor.msgpack.msgpack6import io.kotest.matchers.shouldBe7import io.kotest.property.Arb8import io.kotest.property.Exhaustive9import io.kotest.property.arbitrary.int10import io.kotest.property.checkAll11import io.kotest.property.exhaustive.ints12import utils.MessagePackerFactory13import utils.MessageUnpackerFactory14import utils.TypedElement15class ArrayTest : AbstractMessagePackTest() {16 init {17 "Packer" should {18 "use fixarray" {19 checkAll(Exhaustive.ints(0..15)) {20 it with packer shouldBe fixarray(it)21 }22 }23 "use array16" {24 checkAll(Arb.int(16..Short.MAX_VALUE)) {25 it with packer shouldBe array16(it)26 }27 }28 "use array32" {29 checkAll(Arb.int(65536..Int.MAX_VALUE)) {30 it with packer shouldBe array32(it)31 }32 }33 }34 "Unpacker" should {35 "decode fixarray" {36 checkAll(Exhaustive.ints(0..15)) {37 it with unpacker shouldBe fixarray(it)38 }39 }40 "decode array16" {41 checkAll(Arb.int(16..Short.MAX_VALUE)) {42 it with unpacker shouldBe array16(it)43 }44 }45 "decode array32" {46 checkAll(Arb.int(65536..Int.MAX_VALUE)) {47 it with unpacker shouldBe array32(it)48 }49 }50 }51 }52}53private fun fixarray(size: Int) = TypedElement((0x90 or size).toByte(), IntegerValue.from(size))54private fun array16(size: Int) = TypedElement(ARRAY16, IntegerValue.from(size))55private fun array32(size: Int) = array32(size.toUInt())56private fun array32(size: UInt) = TypedElement(ARRAY32, IntegerValue.from(size))57private infix fun Int.with(packer: MessagePackerFactory): TypedElement =58 packer().let {59 it.beginArray(toUInt())60 (it.sink as ByteArraySink).toByteArray()61 }.let {62 val unpacker = org.msgpack.core.MessagePack.newDefaultUnpacker(it)63 TypedElement(it[0], IntegerValue.from(unpacker.unpackArrayHeader()))64 }65private infix fun Int.with(unpacker: MessageUnpackerFactory) =66 org.msgpack.core.MessagePack.newDefaultBufferPacker().use { packer ->67 packer.packArrayHeader(this) // FIXME: maximum size is Int.MAX_VALUE68 packer69 }.toByteArray().let {70 TypedElement(it[0], msgpack.int(unpacker(it).nextArraySize()))71 }72 ...
uint.kt
Source:uint.kt
1package io.kotest.matchers.ints2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.shouldBe5fun UInt.shouldBeBetween(lower: UInt, upper: UInt): UInt {6 this shouldBe between(lower, upper)7 return this8}9fun between(lower: UInt, upper: UInt) = object : Matcher<UInt> {10 override fun test(value: UInt) = MatcherResult(11 value in lower..upper,12 { "$value should be between ($lower, $upper) inclusive" },13 {14 "$value should not be between ($lower, $upper) inclusive"15 })16}...
uint
Using AI Code Generation
1import io.kotest.matchers.ints.*2import io.kotest.matchers.longs.*3import io.kotest.matchers.floats.*4import io.kotest.matchers.doubles.*5import io.kotest.matchers.booleans.*6import io.kotest.matchers.string.*7import io.kotest.matchers.charsequence.*8import io.kotest.matchers.collections.*9import io.kotest.matchers.collections.*10import io.kotest.matchers.collections.*11import io.kotest.matchers.collections.*12import io.kotest.matchers.bytes.*13import io.kotest.matchers.shorts.*14import io.kotest.matchers.floats.*15import io.kotest.matchers.doubles.*16import io.kotest.matchers.booleans.*17import io.kotest.matchers.throwable.*18import io.kotest.matchers.date.*19import io.kotest.matchers.date.*20import io.kotest.matchers.date.*21import io.kotest.matchers
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!!