How to use ubyte class of io.kotest.matchers.bytes package

Best Kotest code snippet using io.kotest.matchers.bytes.ubyte

ZeropageTests.kt

Source:ZeropageTests.kt Github

copy

Full Screen

1package prog8tests2import com.github.michaelbull.result.expectError3import com.github.michaelbull.result.getOrElse4import com.github.michaelbull.result.onFailure5import io.kotest.assertions.fail6import io.kotest.assertions.throwables.shouldThrow7import io.kotest.assertions.withClue8import io.kotest.core.spec.style.FunSpec9import io.kotest.matchers.collections.shouldBeIn10import io.kotest.matchers.collections.shouldNotBeIn11import io.kotest.matchers.comparables.shouldBeGreaterThan12import io.kotest.matchers.shouldBe13import io.kotest.matchers.shouldNotBe14import prog8.code.core.*15import prog8.code.target.C64Target16import prog8.code.target.Cx16Target17import prog8.code.target.c64.C64Zeropage18import prog8.code.target.cx16.CX16Zeropage19import prog8tests.helpers.DummyCompilationTarget20import prog8tests.helpers.ErrorReporterForTests21class TestAbstractZeropage: FunSpec({22 class DummyZeropage(options: CompilationOptions) : Zeropage(options) {23 override val SCRATCH_B1 = 0x10u24 override val SCRATCH_REG = 0x11u25 override val SCRATCH_W1 = 0x20u26 override val SCRATCH_W2 = 0x30u27 init {28 free.addAll(0u..255u)29 removeReservedFromFreePool()30 }31 }32 test("testAbstractZeropage") {33 val zp = DummyZeropage(34 CompilationOptions(35 OutputType.RAW,36 CbmPrgLauncherType.NONE,37 ZeropageType.FULL,38 listOf((0x50u..0x5fu)),39 floats = false,40 noSysInit = false,41 compTarget = DummyCompilationTarget,42 loadAddress = 999u43 )44 )45 zp.free.size shouldBe 256-6-1646 }47})48class TestC64Zeropage: FunSpec({49 val errors = ErrorReporterForTests()50 val c64target = C64Target()51 test("testNames") {52 val zp = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(),53 floats = false,54 noSysInit = false,55 compTarget = c64target, loadAddress = 999u56 ))57 var result = zp.allocate(emptyList(), DataType.UBYTE, null, null, errors)58 result.onFailure { fail(it.toString()) }59 result = zp.allocate(emptyList(), DataType.UBYTE, null, null, errors)60 result.onFailure { fail(it.toString()) }61 result = zp.allocate(listOf("varname"), DataType.UBYTE, null, null, errors)62 result.onFailure { fail(it.toString()) }63 shouldThrow<IllegalArgumentException> { zp.allocate(listOf("varname"), DataType.UBYTE,null, null, errors) }64 result = zp.allocate(listOf("varname2"), DataType.UBYTE, null, null, errors)65 result.onFailure { fail(it.toString()) }66 }67 test("testZpFloatEnable") {68 val zp = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, c64target, 999u))69 var result = zp.allocate(emptyList(), DataType.FLOAT, null, null, errors)70 result.expectError { "should be allocation error due to disabled floats" }71 val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.DONTUSE, emptyList(), true, false, c64target, 999u))72 result = zp2.allocate(emptyList(), DataType.FLOAT, null, null, errors)73 result.expectError { "should be allocation error due to disabled ZP use" }74 val zp3 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), true, false, c64target, 999u))75 zp3.allocate(emptyList(), DataType.FLOAT, null, null, errors)76 }77 test("testZpModesWithFloats") {78 C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, c64target, 999u))79 C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), false, false, c64target, 999u))80 C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), false, false, c64target, 999u))81 C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), false, false, c64target, 999u))82 C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, false, c64target, 999u))83 C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), true, false, c64target, 999u))84 shouldThrow<InternalCompilerException> {85 C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), true, false, c64target, 999u))86 }87 shouldThrow<InternalCompilerException> {88 C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), true, false, c64target, 999u))89 }90 }91 test("testZpDontuse") {92 val zp = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.DONTUSE, emptyList(), false, false, c64target, 999u))93 println(zp.free)94 zp.availableBytes() shouldBe 095 val result = zp.allocate(emptyList(), DataType.BYTE, null, null, errors)96 result.expectError { "expected error due to disabled ZP use" }97 }98 test("testFreeSpacesBytes") {99 val zp1 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, false, c64target, 999u))100 zp1.availableBytes() shouldBe 18101 val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FLOATSAFE, emptyList(), false, false, c64target, 999u))102 zp2.availableBytes() shouldBe 85103 val zp3 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), false, false, c64target, 999u))104 zp3.availableBytes() shouldBe 125105 val zp4 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, c64target, 999u))106 zp4.availableBytes() shouldBe 239107 zp4.allocate(listOf("test"), DataType.UBYTE, null, null, errors)108 zp4.availableBytes() shouldBe 238109 zp4.allocate(listOf("test2"), DataType.UBYTE, null, null, errors)110 zp4.availableBytes() shouldBe 237111 }112 test("testReservedSpace") {113 val zp1 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, c64target, 999u))114 zp1.availableBytes() shouldBe 239115 50u shouldBeIn zp1.free116 100u shouldBeIn zp1.free117 49u shouldBeIn zp1.free118 101u shouldBeIn zp1.free119 200u shouldBeIn zp1.free120 255u shouldBeIn zp1.free121 199u shouldBeIn zp1.free122 val zp2 = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, listOf(50u .. 100u, 200u..255u), false, false, c64target, 999u))123 zp2.availableBytes() shouldBe 139124 50u shouldNotBeIn zp2.free125 100u shouldNotBeIn zp2.free126 49u shouldBeIn zp2.free127 101u shouldBeIn zp2.free128 200u shouldNotBeIn zp2.free129 255u shouldNotBeIn zp2.free130 199u shouldBeIn zp2.free131 }132 test("testBasicsafeAllocation") {133 val zp = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, false, c64target, 999u))134 zp.availableBytes() shouldBe 18135 zp.hasByteAvailable() shouldBe true136 zp.hasWordAvailable() shouldBe true137 var result = zp.allocate(emptyList(), DataType.FLOAT, null, null, errors)138 result.expectError { "expect allocation error: in regular zp there aren't 5 sequential bytes free" }139 for (i in 0 until zp.availableBytes()) {140 val alloc = zp.allocate(emptyList(), DataType.UBYTE, null, null, errors)141 alloc.getOrElse { throw it }142 }143 zp.availableBytes() shouldBe 0144 zp.hasByteAvailable() shouldBe false145 zp.hasWordAvailable() shouldBe false146 result = zp.allocate(emptyList(), DataType.UBYTE, null, null, errors)147 result.expectError { "expected allocation error" }148 result = zp.allocate(emptyList(), DataType.UWORD, null, null, errors)149 result.expectError { "expected allocation error" }150 }151 test("testFullAllocation") {152 val zp = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, c64target, 999u))153 zp.availableBytes() shouldBe 239154 zp.hasByteAvailable() shouldBe true155 zp.hasWordAvailable() shouldBe true156 var result = zp.allocate(emptyList(), DataType.UWORD, null, null, errors)157 val loc = result.getOrElse { throw it } .first158 loc shouldBeGreaterThan 3u159 loc shouldNotBeIn zp.free160 val num = zp.availableBytes() / 2161 for(i in 0..num-3) {162 zp.allocate(emptyList(), DataType.UWORD, null, null, errors)163 }164 zp.availableBytes() shouldBe 5165 // can't allocate because no more sequential bytes, only fragmented166 result = zp.allocate(emptyList(), DataType.UWORD, null, null, errors)167 result.expectError { "should give allocation error" }168 for(i in 0..4) {169 zp.allocate(emptyList(), DataType.UBYTE, null, null, errors)170 }171 zp.availableBytes() shouldBe 0172 zp.hasByteAvailable() shouldBe false173 zp.hasWordAvailable() shouldBe false174 result = zp.allocate(emptyList(), DataType.UBYTE, null, null, errors)175 result.expectError { "should give allocation error" }176 }177 test("testEfficientAllocation") {178 val zp = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, false, c64target, 999u))179 zp.availableBytes() shouldBe 18180 zp.allocate(emptyList(), DataType.WORD, null, null, errors).getOrElse{throw it}.first shouldBe 0x04u181 zp.allocate(emptyList(), DataType.UBYTE, null, null, errors).getOrElse{throw it}.first shouldBe 0x06u182 zp.allocate(emptyList(), DataType.UBYTE, null, null, errors).getOrElse{throw it}.first shouldBe 0x0au183 zp.allocate(emptyList(), DataType.UWORD, null, null, errors).getOrElse{throw it}.first shouldBe 0x9bu184 zp.allocate(emptyList(), DataType.UWORD, null, null, errors).getOrElse{throw it}.first shouldBe 0x9eu185 zp.allocate(emptyList(), DataType.UWORD, null, null, errors).getOrElse{throw it}.first shouldBe 0xa5u186 zp.allocate(emptyList(), DataType.UWORD, null, null, errors).getOrElse{throw it}.first shouldBe 0xb0u187 zp.allocate(emptyList(), DataType.UWORD, null, null, errors).getOrElse{throw it}.first shouldBe 0xbeu188 zp.allocate(emptyList(), DataType.UBYTE, null, null, errors).getOrElse{throw it}.first shouldBe 0x0eu189 zp.allocate(emptyList(), DataType.UBYTE, null, null, errors).getOrElse{throw it}.first shouldBe 0x92u190 zp.allocate(emptyList(), DataType.UBYTE, null, null, errors).getOrElse{throw it}.first shouldBe 0x96u191 zp.allocate(emptyList(), DataType.UBYTE, null, null, errors).getOrElse{throw it}.first shouldBe 0xf9u192 zp.availableBytes() shouldBe 0193 }194 test("testReservedLocations") {195 val zp = C64Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), false, false, c64target, 999u))196 withClue("zp _B1 and _REG must be next to each other to create a word") {197 zp.SCRATCH_B1 + 1u shouldBe zp.SCRATCH_REG198 }199 }200})201class TestCx16Zeropage: FunSpec({202 val errors = ErrorReporterForTests()203 val cx16target = Cx16Target()204 test("testReservedLocations") {205 val zp = CX16Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), false, false, cx16target, 999u))206 withClue("zp _B1 and _REG must be next to each other to create a word") {207 zp.SCRATCH_B1 + 1u shouldBe zp.SCRATCH_REG208 }209 }210 test("testFreeSpacesBytes") {211 val zp1 = CX16Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.BASICSAFE, emptyList(), true, false, cx16target, 999u))212 zp1.availableBytes() shouldBe 88213 val zp2 = CX16Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.KERNALSAFE, emptyList(), false, false, cx16target, 999u))214 zp2.availableBytes() shouldBe 175215 val zp3 = CX16Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, cx16target, 999u))216 zp3.availableBytes() shouldBe 216217 zp3.allocate(listOf("test"), DataType.UBYTE, null, null, errors)218 zp3.availableBytes() shouldBe 215219 zp3.allocate(listOf("test2"), DataType.UBYTE, null, null, errors)220 zp3.availableBytes() shouldBe 214221 }222 test("testReservedSpace") {223 val zp1 = CX16Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, cx16target, 999u))224 zp1.availableBytes() shouldBe 216225 0x22u shouldBeIn zp1.free226 0x80u shouldBeIn zp1.free227 0xffu shouldBeIn zp1.free228 0x02u shouldNotBeIn zp1.free229 0x21u shouldNotBeIn zp1.free230 }231 test("preallocated zp vars") {232 val zp1 = CX16Zeropage(CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), false, false, cx16target, 999u))233 zp1.allocatedVariables[listOf("test")] shouldBe null234 zp1.allocatedVariables[listOf("cx16", "r0")] shouldNotBe null235 zp1.allocatedVariables[listOf("cx16", "r15")] shouldNotBe null236 zp1.allocatedVariables[listOf("cx16", "r0L")] shouldNotBe null237 zp1.allocatedVariables[listOf("cx16", "r15L")] shouldNotBe null238 zp1.allocatedVariables[listOf("cx16", "r0sH")] shouldNotBe null239 zp1.allocatedVariables[listOf("cx16", "r15sH")] shouldNotBe null240 }241})...

Full Screen

Full Screen

TestTypecasts.kt

Source:TestTypecasts.kt Github

copy

Full Screen

...34 %import floats35 36 main {37 sub start() {38 ubyte @shared bb39 bb = 5555 as ubyte40 routine(5555 as ubyte)41 }42 43 sub routine(ubyte bb) {44 bb++45 }46 }47 """48 val errors = ErrorReporterForTests()49 compileText(C64Target(), false, text, writeAssembly = true, errors=errors) shouldBe null50 errors.errors.size shouldBe 251 errors.errors[0] shouldContain "can't cast"52 errors.errors[1] shouldContain "can't cast"53 }54 test("refuse to round float literal 1") {55 val text = """56 %option enable_floats57 main {58 sub start() {59 float @shared fl = 3.456 as uword60 fl = 1.234 as uword61 }62 }"""63 val errors = ErrorReporterForTests()64 compileText(C64Target(), false, text, errors=errors) shouldBe null65 errors.errors.size shouldBe 266 errors.errors[0] shouldContain "can't cast"67 errors.errors[1] shouldContain "can't cast"68 }69 test("refuse to round float literal 2") {70 val text = """71 %option enable_floats72 main {73 sub start() {74 float @shared fl = 3.45675 fl++76 fl = fl as uword77 }78 }"""79 val errors = ErrorReporterForTests()80 compileText(C64Target(), false, text, errors=errors) shouldBe null81 errors.errors.size shouldBe 182 errors.errors[0] shouldContain "in-place makes no sense"83 }84 test("refuse to round float literal 3") {85 val text = """86 %option enable_floats87 main {88 sub start() {89 uword @shared ww = 3.456 as uword90 ww++91 ww = 3.456 as uword92 }93 }"""94 val errors = ErrorReporterForTests()95 compileText(C64Target(), false, text, errors=errors) shouldBe null96 errors.errors.size shouldBe 297 errors.errors[0] shouldContain "can't cast"98 errors.errors[1] shouldContain "can't cast"99 }100 test("correct implicit casts of signed number comparison and logical expressions") {101 val text = """102 %import floats103 104 main {105 sub start() {106 byte bb = -10107 word ww = -1000108 109 if bb>0 {110 bb++111 }112 if bb < 0 {113 bb ++114 }115 if bb & 1 {116 bb++117 }118 if bb & 128 {119 bb++120 }121 if bb & 255 {122 bb++123 }124 if ww>0 {125 ww++126 }127 if ww < 0 {128 ww ++129 }130 if ww & 1 {131 ww++132 }133 if ww & 32768 {134 ww++135 }136 if ww & 65535 {137 ww++138 }139 }140 }141 """142 val result = compileText(C64Target(), false, text, writeAssembly = true)!!143 printProgram(result.program)144 val statements = result.program.entrypoint.statements145 statements.size shouldBe 27146 }147 test("cast to unsigned in conditional") {148 val text = """149 main {150 sub start() {151 byte bb152 word ww153 154 ubyte iteration_in_progress155 uword num_bytes156 if not iteration_in_progress or not num_bytes {157 num_bytes++158 }159 160 if bb as ubyte {161 bb++162 }163 if ww as uword {164 ww++165 }166 }167 }"""168 val result = compileText(C64Target(), false, text, writeAssembly = true)!!169 val statements = result.program.entrypoint.statements170 statements.size shouldBe 14171 }172 test("no infinite typecast loop in assignment asmgen") {173 val text = """174 main {175 sub start() {176 word @shared qq = calculate(33)177 }178 179 sub calculate(ubyte row) -> word {180 return (8-(row as byte))181 }182 }183 """184 compileText(C64Target(), false, text, writeAssembly = true) shouldNotBe null185 }186 test("(u)byte extend to word parameters") {187 val text = """188 main {189 sub start() {190 byte ub1 = -50191 byte ub2 = -51192 byte ub3 = -52193 byte ub4 = 100...

Full Screen

Full Screen

ByteBufByteTest.kt

Source:ByteBufByteTest.kt Github

copy

Full Screen

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})...

Full Screen

Full Screen

JagMessageSerializationByteTest.kt

Source:JagMessageSerializationByteTest.kt Github

copy

Full Screen

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.buffer17import io.kotest.core.spec.style.StringSpec18import io.kotest.matchers.shouldBe19import io.kotest.property.checkAll20import io.netty.buffer.ByteBufAllocator21import kotlinx.serialization.ExperimentalSerializationApi22import kotlinx.serialization.Serializable23@ExperimentalSerializationApi24@Serializable25private data class ByteTest(26 @JByte(JByteType.DEFAULT) val default: Byte,27 @JByte(JByteType.NEG) val neg: Byte,28 @JByte(JByteType.ADD) val add: Byte,29 @JByte(JByteType.SUB) val sub: Byte,30)31@ExperimentalSerializationApi32@Serializable33private data class UByteTest(34 @JByte(JByteType.DEFAULT) val default: UByte,35 @JByte(JByteType.NEG) val neg: UByte,36 @JByte(JByteType.ADD) val add: UByte,37 @JByte(JByteType.SUB) val sub: UByte,38)39@ExperimentalUnsignedTypes40@ExperimentalSerializationApi41class JagMessageSerializationByteTest : StringSpec({42 "Encode/Decode Test" {43 checkAll<Byte, Byte, Byte, Byte> { default, neg, add, sub ->44 val expectedByteBuf = ByteBufAllocator.DEFAULT.jBuffer(Byte.SIZE_BYTES * 4).apply {45 writeByte(default.toInt())46 writeByteNeg(neg.toInt())47 writeByteAdd(add.toInt())48 writeByteSub(sub.toInt())49 }50 try {51 val expectedTest = ByteTest(default, neg, add, sub)52 val actualByteBuf = JagMessage.encodeToByteBuf(ByteTest.serializer(), expectedTest)53 try {54 actualByteBuf shouldBe expectedByteBuf55 val actualTest = JagMessage.decodeFromByteBuf(ByteTest.serializer(), expectedByteBuf)56 actualTest shouldBe expectedTest57 } finally {58 actualByteBuf.release()59 }60 } finally {61 expectedByteBuf.release()62 }63 }64 }65 "Unsigned Encode/Decode Test" {66 checkAll<UByte, UByte, UByte, UByte> { default, neg, add, sub ->67 val expectedByteBuf = ByteBufAllocator.DEFAULT.jBuffer(UByte.SIZE_BYTES * 4).apply {68 writeByte(default.toInt())69 writeByteNeg(neg.toInt())70 writeByteAdd(add.toInt())71 writeByteSub(sub.toInt())72 }73 try {74 val expectedTest = UByteTest(default, neg, add, sub)75 val actualByteBuf = JagMessage.encodeToByteBuf(UByteTest.serializer(), expectedTest)76 try {77 actualByteBuf shouldBe expectedByteBuf78 val actualTest = JagMessage.decodeFromByteBuf(UByteTest.serializer(), expectedByteBuf)79 actualTest shouldBe expectedTest80 } finally {81 actualByteBuf.release()82 }83 } finally {84 expectedByteBuf.release()85 }86 }87 }88})...

Full Screen

Full Screen

HuffmanEncoderTests.kt

Source:HuffmanEncoderTests.kt Github

copy

Full Screen

...29 DataOutputStream(baos).use { dos ->30 HuffmanEncoder(ByteArray(0)).writePreamble(tree, dos)31 val output = baos.toByteArray()32 output.size shouldBe 1233 output.asUByteArray() shouldBe ubyteArrayOf(34 0.toUByte(), // First byte of total code count35 3.toUByte(), // Second byte of total code count36 12.toUByte(), // First code represents the byte value 1237 10.toUByte(), // It requires 10 bits for representation38 0x55.toUByte(), // The first 8 bytes are 0101 010139 0xC0.toUByte(), // The next 2 bytes are 11, followed by 6 bytes of padding40 81.toUByte(), // Second code represents the byte value 8141 1.toUByte(), // It requires 1 bit for representation42 0x80.toUByte(), // The pattern is a single bit -> 1, followed by 7 bytes of padding,43 123.toUByte(), // Second code represents the byte value 12344 3.toUByte(), // It requires 3 bits for representation45 0x60.toUByte(), // The pattern is 011, followed by 5 bytes of padding46 )47 }...

Full Screen

Full Screen

LocationSpec.kt

Source:LocationSpec.kt Github

copy

Full Screen

...19 (Location(0.4) distance Location(0.6)) shouldBe (0.2 plusOrMinus tolerance)20 (Location(0.1) distance Location(0.9)) shouldBe (0.2 plusOrMinus tolerance)21 }22 test("fromByteArray simple") {23 Location.fromByteArray(ubyteArrayOf(UByte.MIN_VALUE)).value shouldBe (0.0 plusOrMinus tolerance)24 Location.fromByteArray(ubyteArrayOf(UByte.MAX_VALUE)).value shouldBe (1.0 plusOrMinus 0.01)25 Location.fromByteArray(ubyteArrayOf(UByte.MAX_VALUE, UByte.MAX_VALUE)).value shouldBe (1.0 plusOrMinus 0.0001)26 Location.fromByteArray(ubyteArrayOf(UByte.MAX_VALUE, UByte.MAX_VALUE, UByte.MAX_VALUE)).value shouldBe (1.0 plusOrMinus 0.000001)27 Location.fromByteArray(ubyteArrayOf(UByte.MIN_VALUE, UByte.MAX_VALUE)).value shouldBe ((1.0/256.0) plusOrMinus 0.001)28 }29 test("fromByteArray precision") {30 val randomBytes = ByteArray(20)31 random.nextBytes(randomBytes)32 val randomUBytes = randomBytes.asUByteArray()33 for (precision in 1 .. 7) {34 val pos = Location.fromByteArray(randomUBytes, precision)35 logger.info("precision: $precision position: $pos")36 }37 }38 test("Ensure locations generated from random hashes are evenly distributed") {39 val buckets = TreeMap<Double, AtomicInteger>()40 for (i in 0 .. 10000) {41 val nextDouble = random.nextDouble()...

Full Screen

Full Screen

EncodingHuffmanTreeTests.kt

Source:EncodingHuffmanTreeTests.kt Github

copy

Full Screen

1package info.spadger.datastructures.huffman2import io.kotest.core.spec.style.StringSpec3import io.kotest.matchers.collections.shouldContain4import io.kotest.matchers.shouldBe5import io.kotest.matchers.types.shouldBeInstanceOf6@kotlin.ExperimentalUnsignedTypes7class EncodingHuffmanTreeTests : StringSpec({8 "Initial state should be built correctly from input bytes" {9 val input = byteArrayOf(3, 0, 0, 5, 5, 5, 0, 0, 0, 1, 2, 0, 5, 5, 2, 3, 3).asUByteArray()10 val result = EncodingHuffmanTree.createInitialHistogram(input)11 result.size shouldBe 512 result shouldContain SingleValue(0.toUByte())13 result shouldContain SingleValue(5.toUByte())14 result shouldContain SingleValue(3.toUByte())15 result shouldContain SingleValue(2.toUByte())16 result shouldContain SingleValue(1.toUByte())17 }18 "An empty byte-array yields an empty set of codes" {19 val input = byteArrayOf()20 val sut = EncodingHuffmanTree.fromUncompressedData(input)21 sut.codeCount shouldBe 022 sut.shouldBeInstanceOf<EmptyEncodingHuffmanTree>()23 }24 "A byte-array with only a single specific byte yields the code 0" {25 val input = byteArrayOf(100, 100, 100, 100, 100)26 val sut = EncodingHuffmanTree.fromUncompressedData(input)27 sut.codeCount shouldBe 128 sut.encode(100.toUByte()) shouldBe listOf(false)29 }30 "A multiple bytes yields a valid tree" {31 val input = byteArrayOf(100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 1, 2, 2)32 val sut = EncodingHuffmanTree.fromUncompressedData(input)33 sut.codeCount shouldBe 334 sut.encode(100.toUByte()) shouldBe listOf(false)35 sut.encode(2.toUByte()) shouldBe listOf(true, false)36 sut.encode(1.toUByte()) shouldBe listOf(true, true)37 }38})...

Full Screen

Full Screen

ubyte.kt

Source:ubyte.kt Github

copy

Full Screen

1package io.kotest.matchers.bytes2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.shouldBe5fun UByte.shouldBeBetween(lower: UByte, upper: UByte): UByte {6 this shouldBe between(lower, upper)7 return this8}9fun between(lower: UByte, upper: UByte) = object : Matcher<UByte> {10 override fun test(value: UByte) = 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}...

Full Screen

Full Screen

ubyte

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.bytes.shouldBeExactly2 import io.kotest.matchers.bytes.shouldBeExactlyOneOf3 import io.kotest.matchers.bytes.shouldBeGreaterThan4 import io.kotest.matchers.bytes.shouldBeGreaterThanOrEqual5 import io.kotest.matchers.bytes.shouldBeLessThan6 import io.kotest.matchers.bytes.shouldBeLessThanOrEqual7 import io.kotest.matchers.bytes.shouldBeOneOf8 import io.kotest.matchers.bytes.shouldBePositive9 import io.kotest.matchers.bytes.shouldBeZero10 import io.kotest.matchers.bytes.shouldBeZeroOrNegative11 import io.kotest.matchers.bytes.shouldBeZeroOrPositive12 import io.kotest.matchers.bytes.shouldNotBeExactly13 import io.kotest.matchers.bytes.shouldNotBeExactlyOneOf14 import io.kotest.matchers.bytes.shouldNotBeGreaterThan15 import io.kotest.matchers.bytes.shouldNotBeGreaterThanOrEqual16 import io.kotest.matchers.bytes.shouldNotBeLessThan17 import io.kotest.matchers.bytes.shouldNotBeLessThanOrEqual18 import io.kotest.matchers.bytes.shouldNotBeOneOf19 import io.kotest.matchers.bytes.shouldNotBePositive20 import io.kotest.matchers.bytes.shouldNotBeZero21 import io.kotest.matchers.bytes.shouldNotBeZeroOrNegative22 import io.kotest.matchers.bytes.shouldNotBeZeroOrPositive23 import io.kotest.matchers.bytes.shouldNotBeExactlyOneOf24 import io.kotest.matchers.bytes.shouldNotBeExactly25 import io.kotest.matchers.bytes.shouldNotBeOneOf26 import io.kotest.matchers.bytes.shouldNotBePositive27 import io.kotest.matchers.bytes.shouldNotBeZero28 import io.kotest.matchers.bytes.shouldNotBeZeroOrNegative29 import io.kotest.matchers.bytes.shouldNotBeZeroOrPositive30 import io.kotest.matchers.bytes.shouldNotBeGreaterThan31 import io.kotest.matchers.bytes.shouldNotBeGreaterThanOrEqual32 import io.kotest.matchers.bytes.shouldNotBeLessThan33 import io.kotest.matchers.bytes.shouldNotBeLessThanOrEqual34 import io.kotest.matchers.bytes.shouldNot

Full Screen

Full Screen

ubyte

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.bytes.shouldBeLessThan2import io.kotest.matchers.floats.shouldBeGreaterThan3import io.kotest.matchers.doubles.shouldBeGreaterThan4import io.kotest.matchers.chars.shouldBeLowerCase5import io.kotest.matchers.strings.shouldBeEmpty6import io.kotest.matchers.arrays.shouldBeSorted7import io.kotest.matchers.collections.shouldHaveSize8import io.kotest.matchers.maps.shouldBeEmpty9import io.kotest.matchers.date.shouldBeBefore10import io.kotest.matchers.time.shouldBeAfter11import io.kotest.matchers.uri.shouldHaveHost12import io.kotest.matchers.regex.shouldMatch13import io.kotest.matchers.sequences.shouldBeEmpty14import io.kotest.matchers.optionals.shouldHaveValue15import io.kotest.matchers.types.shouldBeTypeOf16import io.kotest.matchers.throwable.shouldHaveMessage17import io.kotest.matchers.io.shouldBeEmpty18import io.kotest.matchers.files.shouldBeEmpty19import io.kotest.matchers.types.shouldBeTypeOf

Full Screen

Full Screen

ubyte

Using AI Code Generation

copy

Full Screen

1val bytes = ubyteArrayOf(1u, 2u, 3u, 4u)2val expected = ubyteArrayOf(1u, 2u, 3u, 4u)3val bytes = ushortArrayOf(1u, 2u, 3u, 4u)4val expected = ushortArrayOf(1u, 2u, 3u, 4u)5val bytes = uintArrayOf(1u, 2u, 3u, 4u)6val expected = uintArrayOf(1u, 2u, 3u, 4u)7val bytes = ulongArrayOf(1u, 2u, 3u, 4u)8val expected = ulongArrayOf(1u, 2u, 3u, 4u)9val bytes = UByteArray(4) { it.toUByte() }10val expected = UByteArray(4) { it.toUByte() }11val bytes = UShortArray(4) { it.toUShort() }12val expected = UShortArray(4) { it.toUShort() }13val bytes = UIntArray(4) { it.toUInt() }14val expected = UIntArray(4) { it.toUInt() }15val bytes = ULongArray(4) { it.toULong() }16val expected = ULongArray(4) { it.toULong() }

Full Screen

Full Screen

ubyte

Using AI Code Generation

copy

Full Screen

1val byte: Byte = 0xFF.toByte()2val short: Short = 0xFFFF.toShort()3val int: Int = 0xFFFFFFFF.toInt()4val long: Long = 0xFFFFFFFFFFFFFFFF.toLong()5val float: Float = 0xFFFFFFFFFFFFFFFF.toLong().toFloat()6val double: Double = 0xFFFFFFFFFFFFFFFF.toLong().toDouble()7val array: Array<Int> = arrayOf(1, 2, 3, 4, 5)8array shouldBe arrayOf(1, 2, 3, 4, 5)

Full Screen

Full Screen

ubyte

Using AI Code Generation

copy

Full Screen

1val matcher = haveSize(5)2matcher(ByteBuffer.allocate(5))3matcher(ByteBuffer.allocate(1))4matcher(ByteBuffer.allocate(0))5matcher(ByteBuffer.allocate(5).apply { put(1) })6matcher(ByteBuffer.allocate(5).apply { put(1) ; put(2) })7matcher(ByteBuffer.allocate(5).apply { put(1) ; put(2) ; put(3) })8matcher(ByteBuffer.allocate(5).apply { put(1) ; put(2) ; put(3) ; put(4) })9matcher(ByteBuffer.allocate(5).apply { put(1) ; put(2) ; put(3) ; put(4) ; put(5) })10matcher(ByteBuffer.allocate(5).apply { put(1) ; put(2) ; put(3) ; put(4) ; put(5) ; put(6) })11matcher(ByteBuffer.allocate(5).apply { put(1) ; put(2) ; put(3) ; put(4) ; put(5) ; put(6) ; put(7) })12matcher(ByteBuffer.allocate(5).apply { put(1) ; put(2) ; put(3) ; put(4) ; put(5) ; put(6) ; put(7) ; put(8) })13matcher(ByteBuffer.allocate(5).apply { put(1) ; put(2) ; put(3) ; put(4) ; put(5) ; put(6) ; put(7) ; put(8) ; put(9) })14matcher(ByteBuffer.allocate(5).apply { put(1) ; put(2) ; put(3) ; put(4) ; put(5) ; put(6) ; put(7) ; put(8) ; put(9) ; put(10) })15matcher(ByteBuffer.allocate(5).apply { put(1) ; put(2) ; put(3) ; put(4) ; put(5) ; put(6) ; put(7) ; put(8) ; put(9) ; put(10) ; put(11) })16matcher(ByteBuffer.allocate(5).apply { put(1) ; put(2) ; put(3) ; put(4) ; put(5) ; put(6) ; put

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 ubyte

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful