How to use test method of io.kotest.matchers.bytes.ubyte class

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

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

1package prog8tests2import io.kotest.core.spec.style.FunSpec3import io.kotest.matchers.shouldBe4import io.kotest.matchers.shouldNotBe5import io.kotest.matchers.string.shouldContain6import prog8.code.target.C64Target7import prog8.compiler.printProgram8import prog8tests.helpers.ErrorReporterForTests9import prog8tests.helpers.compileText10class TestTypecasts: FunSpec({11 test("correct typecasts") {12 val text = """13 %import floats14 15 main {16 sub start() {17 float @shared fl = 3.45618 uword @shared uw = 555519 byte @shared bb = -4420 bb = uw as byte21 uw = bb as uword22 fl = uw as float23 fl = bb as float24 bb = fl as byte25 uw = fl as uword26 }27 }28 """29 val result = compileText(C64Target(), false, text, writeAssembly = true)!!30 result.program.entrypoint.statements.size shouldBe 1331 }32 test("invalid typecasts of numbers") {33 val text = """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 = 100194 word @shared ww = func(ub1, ub2, ub3, ub4)195 ww = func(ub4, ub2, ub3, ub1)196 ww=afunc(ub1, ub2, ub3, ub4)197 ww=afunc(ub4, ub2, ub3, ub1)198 }199 200 sub func(word x1, word y1, word x2, word y2) -> word {201 return x1202 }203 204 asmsub afunc(word x1 @R0, word y1 @R1, word x2 @R2, word y2 @R3) -> word @AY {205 %asm {{206 lda cx16.r0207 ldy cx16.r0+1208 rts209 }}210 }211 }"""212 compileText(C64Target(), true, text, writeAssembly = true) shouldNotBe null213 }214 test("lsb msb used as args with word types") {215 val text = """216 main {217 sub start() {218 uword xx=${'$'}ea31219 uword @shared ww = plot(lsb(xx), msb(xx))220 }221 222 inline asmsub plot(uword plotx @R0, uword ploty @R1) -> uword @AY{223 %asm {{224 lda cx16.r0225 ldy cx16.r1226 rts227 }}228 }...

Full Screen

Full Screen

ByteBufByteTest.kt

Source:ByteBufByteTest.kt Github

copy

Full Screen

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

Full Screen

Full Screen

JagMessageSerializationByteTest.kt

Source:JagMessageSerializationByteTest.kt Github

copy

Full Screen

...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(...

Full Screen

Full Screen

CpuTest.kt

Source:CpuTest.kt Github

copy

Full Screen

1package net.chompsoftware.k6502.hardware2import io.kotest.matchers.should3import io.kotest.matchers.shouldBe4import net.chompsoftware.k6502.hardware.InstructionSet.*5import org.junit.jupiter.api.Test6import org.junit.jupiter.api.fail7@ExperimentalUnsignedTypes8class CpuTest {9 @Test10 fun `All operations should take at least 1 cycle`() {11 values().forEach { instruction ->12 val memory = Memory(setupMemory(instruction.u, 0x01u, 0x02u))13 val state = CpuState(cycleCount = 100)14 try {15 val result = Cpu().run(state, memory)16 if (result.cycleCount == 100L) {17 fail("${instruction.name} took 0 cycles")...

Full Screen

Full Screen

LocationSpec.kt

Source:LocationSpec.kt Github

copy

Full Screen

1package locutus.tools.math2import io.kotest.core.spec.Order3import io.kotest.core.spec.style.FunSpec4import io.kotest.matchers.doubles.*5import io.kotest.matchers.ints.shouldBeInRange6import io.kotest.matchers.shouldBe7import kweb.util.random8import locutus.tools.crypto.hash9import mu.KotlinLogging10import java.util.*11import java.util.concurrent.atomic.AtomicInteger12import kotlin.math.roundToInt13private val tolerance = 0.00000000114private val logger = KotlinLogging.logger {}15@Order(0)16@ExperimentalUnsignedTypes17class LocationSpec : FunSpec({18 test("Distance") {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()42 val toString = nextDouble.toString()43 val toByteArray = toString.toByteArray()44 val randomBA = toByteArray.hash()45 val location = Location.fromByteArray(randomBA.asUByteArray())46 val bucket = (location.value * 10.0).roundToInt().toDouble()/10.047 buckets.computeIfAbsent(bucket) { AtomicInteger(0) }.incrementAndGet()48 }49 buckets[0.0]!!.get() shouldBeInRange(400 .. 600)50 buckets[1.0]!!.get() shouldBeInRange(400 .. 600)51 for (n in 2 .. 9) {52 buckets[n.toDouble() / 10.0]!!.get() shouldBeInRange(900 .. 1100)...

Full Screen

Full Screen

ByteTest.kt

Source:ByteTest.kt Github

copy

Full Screen

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.bytes.shouldBeBetween7import 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 ByteTest : FunSpec({14 test("<Byte, Byte> 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((Byte.MAX_VALUE - 10).toByte(), Byte.MAX_VALUE),21 row(Byte.MIN_VALUE, (Byte.MIN_VALUE + 10).toByte())22 ) { vMin, vMax ->23 val expectedValues = (vMin..vMax).map { it.toByte() }.toSet()24 val actualValues = (1..100_000).map { Arb.byte(vMin, vMax).single() }.toSet()25 actualValues shouldBe expectedValues26 }27 }28 test("Arb.byte edge cases should respect min and max bounds") {29 checkCoverage("run", 25.0) {30 PropTest(iterations = 1000).checkAll<Byte, Byte> { min, max ->31 if (min < max) {32 classify("run")33 Arb.byte(min, max).edgecases().forAll {34 it.shouldBeBetween(min, max)35 }36 }37 }38 }39 }40})41class UByteTest : FunSpec({42 test("<UByte, UByte> should give values between min and max inclusive") {43 forAll(44 row(1u, 3u),45 row(0u, 100u),46 row((UByte.MAX_VALUE - 10u).toUByte(), UByte.MAX_VALUE),47 row(UByte.MIN_VALUE, (UByte.MIN_VALUE + 10u).toUByte())48 ) { vMin, vMax ->49 val expectedValues = (vMin..vMax).map { it.toUByte() }.toSet()50 val actualValues = (1..100_000).map { Arb.uByte(vMin, vMax).single() }.toSet()51 actualValues shouldBe expectedValues52 }53 }54 test("Arb.uByte edge cases should respect min and max bounds") {55 checkCoverage("run", 25.0) {56 PropTest(iterations = 1000).checkAll<UByte, UByte> { min, max ->57 if (min < max) {58 classify("run")59 Arb.uByte(min, max).edgecases().forAll {60 it.shouldBeBetween(min, max)61 }62 }63 }64 }65 }66})...

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

test

Using AI Code Generation

copy

Full Screen

1 "UByteMatchers" should {2 "beLessThan" {3 1.ubyte should beLessThan(2.ubyte)4 1.ubyte shouldNot beLessThan(1.ubyte)5 2.ubyte shouldNot beLessThan(1.ubyte)6 }7 "beLessThanOrEqual" {8 1.ubyte should beLessThanOrEqual(2.ubyte)9 1.ubyte should beLessThanOrEqual(1.ubyte)10 2.ubyte shouldNot beLessThanOrEqual(1.ubyte)11 }12 "beGreaterThan" {13 2.ubyte should beGreaterThan(1.ubyte)14 1.ubyte shouldNot beGreaterThan(1.ubyte)15 1.ubyte shouldNot beGreaterThan(2.ubyte)16 }17 "beGreaterThanOrEqual" {18 2.ubyte should beGreaterThanOrEqual(1.ubyte)19 1.ubyte should beGreaterThanOrEqual(1.ubyte)20 1.ubyte shouldNot beGreaterThanOrEqual(2.ubyte)21 }22 "beBetween" {23 1.ubyte should beBetween(1.ubyte, 2.ubyte)24 1.ubyte shouldNot beBetween(2.ubyte, 3.ubyte)25 2.ubyte should beBetween(1.ubyte, 2.ubyte)26 2.ubyte shouldNot beBetween(3.ubyte, 4.ubyte)27 }28 }29})30Property Matcher Description beLessThan(value) Checks that the subject is less than the given value. beLessThanOrEqual(value) Checks that the subject is less than or equal to the given value. beGreaterThan(value) Checks that the subject is greater than the given value

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1 "UByteMatchers" When {2 "using should" should {3 "have a shouldBeGreaterThan method" {4 }5 "have a shouldBeGreaterThanOrEqual method" {6 }7 "have a shouldBeLessThan method" {8 }9 "have a shouldBeLessThanOrEqual method" {10 }11 "have a shouldBeBetween method" {12 }13 "have a shouldBeBetweenInclusive method" {14 }15 "have a shouldNotBeBetween method" {16 }17 "have a shouldNotBeBetweenInclusive method" {18 }19 }20 "using shouldNot" should {21 "have a shouldBeGreaterThan method" {22 }23 "have a shouldBeGreaterThanOrEqual method" {24 }25 "have a shouldBeLessThan method" {26 }27 "have a shouldBeLessThanOrEqual method" {28 }29 }30 }31})32 "UShortMatchers" When {33 "using should" should {34 "have a shouldBeGreaterThan method" {35 }36 "have a shouldBeGreaterThanOrEqual method" {37 }38 "have a shouldBeLessThan method" {39 }

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 method 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