Best Kotest code snippet using io.kotest.matchers.ints.int.Int.shouldBeNonNegative
ByteBufByteTest.kt
Source:ByteBufByteTest.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.byte23import io.kotest.property.arbitrary.byteArray24import io.kotest.property.arbitrary.uByte25import io.kotest.property.arbitrary.uByteArray26import io.kotest.property.checkAll27import io.netty.buffer.ByteBuf28import io.netty.buffer.ByteBufAllocator29private suspend fun doByteGSTest(30 setter: ByteBuf.(Int, Int) -> ByteBuf,31 getter: ByteBuf.(Int) -> Byte32) = checkAll(Arb.byteArray(collectionSizeArb, Arb.byte())) { testData ->33 val buf = ByteBufAllocator.DEFAULT.buffer(testData.size * Byte.SIZE_BYTES)34 try {35 testData.forEachIndexed { i, expected -> buf.setter(i, expected.toInt()) }36 testData.forEachIndexed { i, expected ->37 val get = buf.getter(i)38 get shouldBe expected39 }40 } finally {41 buf.release()42 }43}44private suspend fun doByteRWTest(45 writer: ByteBuf.(Int) -> ByteBuf,46 reader: ByteBuf.() -> Byte47) = checkAll(Arb.byteArray(collectionSizeArb, Arb.byte())) { testData ->48 val buf = ByteBufAllocator.DEFAULT.buffer(testData.size * Byte.SIZE_BYTES)49 try {50 testData.forEach { expected -> buf.writer(expected.toInt()) }51 testData.forEach { expected ->52 val read = buf.reader()53 read shouldBe expected54 }55 } finally {56 buf.release()57 }58}59@ExperimentalUnsignedTypes60private suspend fun doUByteGSTest(61 setter: ByteBuf.(Int, Int) -> ByteBuf,62 getter: ByteBuf.(Int) -> Short63) = checkAll(Arb.uByteArray(collectionSizeArb, Arb.uByte())) { testData ->64 val buf = ByteBufAllocator.DEFAULT.buffer(testData.size * UByte.SIZE_BYTES)65 try {66 testData.forEachIndexed { i, expected -> buf.setter(i, expected.toInt()) }67 testData.forEachIndexed { i, expected ->68 val get = buf.getter(i)69 get.toInt().shouldBeNonNegative()70 get shouldBe expected.toShort()71 }72 } finally {73 buf.release()74 }75}76@ExperimentalUnsignedTypes77private suspend fun doUByteRWTest(78 writer: ByteBuf.(Int) -> ByteBuf,79 reader: ByteBuf.() -> Short80) = checkAll(Arb.uByteArray(collectionSizeArb, Arb.uByte())) { testData ->81 val buf = ByteBufAllocator.DEFAULT.buffer(testData.size * UByte.SIZE_BYTES)82 try {83 testData.forEach { expected -> buf.writer(expected.toInt()) }84 testData.forEach { expected ->85 val read = buf.reader()86 read.toInt().shouldBeNonNegative()87 read shouldBe expected.toShort()88 }89 } finally {90 buf.release()91 }92}93@ExperimentalUnsignedTypes94class ByteBufByteTest : StringSpec({95 "Get/Set Byte neg" { doByteGSTest(ByteBuf::setByteNeg, ByteBuf::getByteNeg) }96 "Read/Write Byte neg" { doByteRWTest(ByteBuf::writeByteNeg, ByteBuf::readByteNeg) }97 "Unsigned Get/Set Byte neg" { doUByteGSTest(ByteBuf::setByteNeg, ByteBuf::getUnsignedByteNeg) }98 "Unsigned Read/Write Byte neg" { doUByteRWTest(ByteBuf::writeByteNeg, ByteBuf::readUnsignedByteNeg) }99 "Get/Set Byte add" { doByteGSTest(ByteBuf::setByteAdd, ByteBuf::getByteAdd) }100 "Read/Write Byte add" { doByteRWTest(ByteBuf::writeByteAdd, ByteBuf::readByteAdd) }101 "Unsigned Get/Set Byte add" { doUByteGSTest(ByteBuf::setByteAdd, ByteBuf::getUnsignedByteAdd) }102 "Unsigned Read/Write Byte add" { doUByteRWTest(ByteBuf::writeByteAdd, ByteBuf::readUnsignedByteAdd) }103 "Get/Set Byte sub" { doByteGSTest(ByteBuf::setByteSub, ByteBuf::getByteSub) }104 "Read/Write Byte sub" { doByteRWTest(ByteBuf::writeByteSub, ByteBuf::readByteSub) }105 "Unsigned Get/Set Byte sub" { doUByteGSTest(ByteBuf::setByteSub, ByteBuf::getUnsignedByteSub) }106 "Unsigned Read/Write Byte sub" { doUByteRWTest(ByteBuf::writeByteSub, ByteBuf::readUnsignedByteSub) }107})...
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})...
ByteBufShortTest.kt
Source:ByteBufShortTest.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 doShortGSTest(27 setter: ByteBuf.(Int, Int) -> ByteBuf,28 getter: ByteBuf.(Int) -> Short29) = checkAll(Arb.shortArray(collectionSizeArb, Arb.short())) { testData ->30 val buf = ByteBufAllocator.DEFAULT.buffer(testData.size * Short.SIZE_BYTES)31 try {32 testData.forEachIndexed { i, expected -> buf.setter(i * Short.SIZE_BYTES, expected.toInt()) }33 testData.forEachIndexed { i, expected ->34 val get = buf.getter(i * Short.SIZE_BYTES)35 get shouldBe expected36 }37 } finally {38 buf.release()39 }40}41private suspend fun doShortRWTest(42 writer: ByteBuf.(Int) -> ByteBuf,43 reader: ByteBuf.() -> Short44) = checkAll(Arb.shortArray(collectionSizeArb, Arb.short())) { testData ->45 val buf = ByteBufAllocator.DEFAULT.buffer(testData.size * Short.SIZE_BYTES)46 try {47 testData.forEach { expected -> buf.writer(expected.toInt()) }48 testData.forEach { expected ->49 val read = buf.reader()50 read shouldBe expected51 }52 } finally {53 buf.release()54 }55}56@ExperimentalUnsignedTypes57private suspend fun doUShortGSTest(58 setter: ByteBuf.(Int, Int) -> ByteBuf,59 getter: ByteBuf.(Int) -> Int60) = checkAll(Arb.uShortArray(collectionSizeArb, Arb.uShort())) { testData ->61 val buf = ByteBufAllocator.DEFAULT.buffer(testData.size * UShort.SIZE_BYTES)62 try {63 testData.forEachIndexed { i, expected -> buf.setter(i * UShort.SIZE_BYTES, expected.toInt()) }64 testData.forEachIndexed { i, expected ->65 val get = buf.getter(i * UShort.SIZE_BYTES)66 get.shouldBeNonNegative()67 get shouldBe expected.toInt()68 }69 } finally {70 buf.release()71 }72}73@ExperimentalUnsignedTypes74private suspend fun doUShortRWTest(75 writer: ByteBuf.(Int) -> ByteBuf,76 reader: ByteBuf.() -> Int77) = checkAll(Arb.uShortArray(collectionSizeArb, Arb.uShort())) { testData ->78 val buf = ByteBufAllocator.DEFAULT.buffer(testData.size * UShort.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 ByteBufShortTest : StringSpec({92 "Get/Set Short add" { doShortGSTest(ByteBuf::setShortAdd, ByteBuf::getShortAdd) }93 "Read/Write Short add" { doShortRWTest(ByteBuf::writeShortAdd, ByteBuf::readShortAdd) }94 "Unsigned Get/Set Short add" { doUShortGSTest(ByteBuf::setShortAdd, ByteBuf::getUnsignedShortAdd) }95 "Unsigned Read/Write Short add" { doUShortRWTest(ByteBuf::writeShortAdd, ByteBuf::readUnsignedShortAdd) }96 "Get/Set Short LE add" { doShortGSTest(ByteBuf::setShortLEAdd, ByteBuf::getShortLEAdd) }97 "Read/Write Short LE add" { doShortRWTest(ByteBuf::writeShortLEAdd, ByteBuf::readShortLEAdd) }98 "Unsigned Get/Set Short LE add" { doUShortGSTest(ByteBuf::setShortLEAdd, ByteBuf::getUnsignedShortLEAdd) }99 "Unsigned Read/Write Short LE add" { doUShortRWTest(ByteBuf::writeShortLEAdd, ByteBuf::readUnsignedShortLEAdd) }100})...
int.kt
Source:int.kt
1package io.kotest.matchers.ints2import io.kotest.matchers.comparables.gt3import io.kotest.matchers.comparables.gte4import io.kotest.matchers.comparables.lt5import io.kotest.matchers.comparables.lte6import io.kotest.matchers.Matcher7import io.kotest.matchers.MatcherResult8import io.kotest.matchers.should9import io.kotest.matchers.shouldBe10import io.kotest.matchers.shouldNot11import io.kotest.matchers.shouldNotBe12fun Int.shouldBePositive(): Int {13 this shouldBe positive()14 return this15}16fun positive() = object : Matcher<Int> {17 override fun test(value: Int) = MatcherResult(18 value > 0,19 { "$value should be > 0" },20 { "$value should not be > 0" })21}22fun Int.shouldBeNonNegative(): Int {23 this shouldBe nonNegative()24 return this25}26fun nonNegative() = object : Matcher<Int> {27 override fun test(value: Int) =28 MatcherResult(29 value >= 0,30 { "$value should be >= 0" },31 { "$value should not be >= 0" })32}33fun Int.shouldBeNegative(): Int {34 this shouldBe negative()35 return this36}37fun negative() = object : Matcher<Int> {38 override fun test(value: Int) = MatcherResult(39 value < 0,40 { "$value should be < 0" },41 { "$value should not be < 0" })42}43fun Int.shouldBeNonPositive(): Int {44 this shouldBe nonPositive()45 return this46}47fun nonPositive() = object : Matcher<Int> {48 override fun test(value: Int) =49 MatcherResult(50 value <= 0,51 { "$value should be <= 0" },52 { "$value should not be <= 0" })53}54fun Int.shouldBeEven(): Int {55 this should beEven()56 return this57}58fun Int.shouldNotBeEven(): Int {59 this shouldNot beEven()60 return this61}62fun beEven() = object : Matcher<Int> {63 override fun test(value: Int): MatcherResult =64 MatcherResult(65 value % 2 == 0,66 { "$value should be even" },67 { "$value should be odd" })68}69fun Int.shouldBeOdd(): Int {70 this should beOdd()71 return this72}73fun Int.shouldNotBeOdd(): Int {74 this shouldNot beOdd()75 return this76}77fun beOdd() = object : Matcher<Int> {78 override fun test(value: Int): MatcherResult =79 MatcherResult(80 value % 2 == 1,81 { "$value should be odd" },82 { "$value should be even" })83}84infix fun Int.shouldBeLessThan(x: Int): Int {85 this shouldBe lt(x)86 return this87}88infix fun Int.shouldNotBeLessThan(x: Int): Int {89 this shouldNotBe lt(x)90 return this91}92infix fun Int.shouldBeLessThanOrEqual(x: Int): Int {93 this shouldBe lte(x)94 return this95}96infix fun Int.shouldNotBeLessThanOrEqual(x: Int): Int {97 this shouldNotBe lte(x)98 return this99}100infix fun Int.shouldBeGreaterThan(x: Int): Int {101 this shouldBe gt(x)102 return this103}104infix fun Int.shouldNotBeGreaterThan(x: Int): Int {105 this shouldNotBe gt(x)106 return this107}108infix fun Int.shouldBeGreaterThanOrEqual(x: Int): Int {109 this shouldBe gte(x)110 return this111}112infix fun Int.shouldNotBeGreaterThanOrEqual(x: Int): Int {113 this shouldNotBe gte(x)114 return this115}116infix fun Int.shouldBeExactly(x: Int): Int {117 this shouldBe exactly(x)118 return this119}120infix fun Int.shouldNotBeExactly(x: Int): Int {121 this shouldNotBe exactly(x)122 return this123}124fun Int.shouldBeZero(): Int {125 this shouldBeExactly 0126 return this127}128fun Int.shouldNotBeZero(): Int {129 this shouldNotBeExactly 0130 return this131}...
ByteBufShortSmart.kt
Source:ByteBufShortSmart.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 doShortSmartRWTest(27 writer: ByteBuf.(Int) -> ByteBuf,28 reader: ByteBuf.() -> Short29) = checkAll(30 Arb.shortArray(collectionSizeArb, Arb.short(Smart.MIN_SHORT_VALUE.toShort(), Smart.MAX_SHORT_VALUE.toShort()))31) { testData ->32 val buf = ByteBufAllocator.DEFAULT.buffer(testData.size * Short.SIZE_BYTES)33 try {34 testData.forEach { expected -> buf.writer(expected.toInt()) }35 testData.forEach { expected ->36 val read = buf.reader()37 read shouldBe expected38 }39 } finally {40 buf.release()41 }42}43@ExperimentalUnsignedTypes44private suspend fun doUShortSmartRWTest(45 writer: ByteBuf.(Int) -> ByteBuf,46 reader: ByteBuf.() -> Short47) = checkAll(48 Arb.uShortArray(collectionSizeArb, Arb.uShort(USmart.MIN_SHORT_VALUE.toUShort(), USmart.MAX_SHORT_VALUE.toUShort()))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.toInt().shouldBeNonNegative()56 read shouldBe expected.toInt()57 }58 } finally {59 buf.release()60 }61}62@ExperimentalUnsignedTypes63private suspend fun doIncrShortSmartRWTest(64 writer: ByteBuf.(Int) -> ByteBuf,65 reader: ByteBuf.() -> Int66) = checkAll(Arb.intArray(collectionSizeArb, Arb.int(0, 100_000))) { testData ->67 val buf = ByteBufAllocator.DEFAULT.buffer()68 try {69 testData.forEach { expected -> buf.writer(expected) }70 testData.forEach { expected ->71 val read = buf.reader()72 read.shouldBeNonNegative()73 read shouldBe expected74 }75 } finally {76 buf.release()77 }78}79@ExperimentalUnsignedTypes80class ByteBufShortSmartTest : StringSpec({81 "Read/Write Short Smart" { doShortSmartRWTest(ByteBuf::writeShortSmart, ByteBuf::readShortSmart) }82 "Unsigned Read/Write Short Smart" {83 doUShortSmartRWTest(ByteBuf::writeUnsignedShortSmart, ByteBuf::readUnsignedShortSmart)84 }85 "Unsigned Read/Write Incr Short Smart" {86 doIncrShortSmartRWTest(ByteBuf::writeIncrShortSmart, ByteBuf::readIncrShortSmart)87 }88})...
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})...
Int.shouldBeNonNegative
Using AI Code Generation
1 import io.kotest.matchers.ints.shouldBeNonNegative2 import io.kotest.matchers.ints.shouldBePositive3 import io.kotest.matchers.ints.shouldBeZero4 import io.kotest.matchers.ints.shouldNotBeNegative5 import io.kotest.matchers.ints.shouldNotBePositive6 import io.kotest.matchers.ints.shouldNotBeZero7 import io.kotest.matchers.ints.shouldNotBeIn8 import io.kotest.matchers.ints.shouldBeIn9 import io.kotest.matchers.ints.shouldBeBetween10 import io.kotest.matchers.ints.shouldBeLessThan11 import io.kotest.matchers.ints.shouldBeGreaterThan12 import io.kotest.matchers.ints.shouldBeLessThanOrEqual13 import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual14 import io.kotest.matchers.ints.should
Int.shouldBeNonNegative
Using AI Code Generation
1 io.kotest.matchers.ints.int.shouldBeNonNegative()2 io.kotest.matchers.ints.int.shouldBeNegative()3 io.kotest.matchers.ints.int.shouldBePositive()4 io.kotest.matchers.ints.int.shouldBeZero()5 io.kotest.matchers.ints.int.shouldBeBetween(0, 0)6 io.kotest.matchers.ints.int.shouldBeBetweenClosed(0, 0)7 io.kotest.matchers.ints.int.shouldBeBetweenClosedInclusive(0, 0)8 io.kotest.matchers.ints.int.shouldBeBetweenInclusive(0, 0)9 io.kotest.matchers.ints.int.shouldBeBetweenOpen(0, 0)10 io.kotest.matchers.ints.int.shouldBeBetweenOpenInclusive(0, 0)11 io.kotest.matchers.ints.int.shouldBeBetweenOrEqual(0, 0)12 io.kotest.matchers.ints.int.shouldBeBetweenOrEqualClosed(0, 0)
Int.shouldBeNonNegative
Using AI Code Generation
1 io.kotest.matchers.ints.int.shouldBeNonNegative(1)2 io.kotest.matchers.ints.int.shouldBePositive(1)3 io.kotest.matchers.ints.int.shouldBeZero(0)4 io.kotest.matchers.ints.int.shouldBeInRange(1..10, 5)5 io.kotest.matchers.ints.int.shouldBeBetween(1, 10, 5)6 io.kotest.matchers.ints.int.shouldBeGreaterThan(1, 2)7 io.kotest.matchers.ints.int.shouldBeGreaterThanOrEqual(1, 1)8 io.kotest.matchers.ints.int.shouldBeLessThan(10, 5)9 io.kotest.matchers.ints.int.shouldBeLessThanOrEqual(10, 10)10 io.kotest.matchers.ints.int.shouldBeBetweenInclusive(1, 10, 5)11 io.kotest.matchers.ints.int.shouldBeBetweenExclusive(1, 10, 5)12 io.kotest.matchers.ints.int.shouldBeMultipleOf(2, 10)
Int.shouldBeNonNegative
Using AI Code Generation
1int a = -1;2a.shouldBeNonNegative();3int a = -1;4a.shouldBePositive();5int a = 1;6a.shouldBeZero();7int a = 1;8a.shouldBeInRange(1, 5);9int a = 1;10a.shouldBeInRangeClosed(1, 5);11int a = 1;12a.shouldBeNegative();13int a = 1;14a.shouldBeNonPositive();15int a = 1;16a.shouldBePositive();17int a = 1;18a.shouldBeZero();19int a = 1;20a.shouldBeInRange(1, 5);21int a = 1;22a.shouldBeInRangeClosed(1, 5);23int a = 1;24a.shouldBeNegative();25int a = 1;26a.shouldBeNonPositive();27int a = 1;28a.shouldBePositive();29int a = 1;30a.shouldBeZero();
Int.shouldBeNonNegative
Using AI Code Generation
1Int . shouldBeNonNegative ( 5 )2Int . shouldBeNonNegative ( - 5 )3Int . shouldBeNonNegative ( 0 )4Int . shouldBeNonNegative ( - 0 )5Int . shouldBeNonNegative ( 0 )6Int . shouldBeNonNegative ( - 0 )7Int . shouldBeNonNegative ( 0 )8Int . shouldBeNonNegative ( - 0 )9Int . shouldBeNonNegative ( 0 )10Int . shouldBeNonNegative ( - 0 )11Int . shouldBeNonNegative ( 0 )12Int . shouldBeNonNegative ( - 0 )13Int . shouldBeNonNegative ( 0 )14Int . shouldBeNonNegative ( - 0 )15Int . shouldBeNonNegative ( 0 )16Int . shouldBeNonNegative ( - 0 )
Int.shouldBeNonNegative
Using AI Code Generation
1 int shouldBeNonNegative = 5;2 shouldBeNonNegative.shouldBeNonNegative()3 }4 fun add(a: Int, b: Int): Int {5 }6 fun `add two numbers`() {7 add(1, 2).shouldBe(3)8 }
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!!