How to use byte method of test.Open class

Best Mockito-kotlin code snippet using test.Open.byte

CrescentLexerTests.kt

Source:CrescentLexerTests.kt Github

copy

Full Screen

1package dev.twelveoclock.lang.crescent2import dev.twelveoclock.lang.crescent.data.TestCode3import dev.twelveoclock.lang.crescent.language.token.CrescentToken.*4import dev.twelveoclock.lang.crescent.language.token.CrescentToken.Operator.*5import dev.twelveoclock.lang.crescent.language.token.CrescentToken.Statement.*6import dev.twelveoclock.lang.crescent.language.token.CrescentToken.Type.*7import dev.twelveoclock.lang.crescent.language.token.CrescentToken.Variable.*8import dev.twelveoclock.lang.crescent.lexers.CrescentLexer9import kotlin.test.Test10import kotlin.test.assertContentEquals11internal class CrescentLexerTests {12 @Test13 fun helloWorld() {14 val tokens = CrescentLexer.invoke(TestCode.helloWorlds)15 assertContentEquals(16 listOf(17 FUN, Key("main"), Bracket.OPEN,18 Key("println"), Parenthesis.OPEN, Data.String("Hello World"), Parenthesis.CLOSE,19 Key("println"), *Array(2) { Parenthesis.OPEN }, Data.String("Hello World"), *Array(2) { Parenthesis.CLOSE },20 Key("println"), *Array(10) { Parenthesis.OPEN }, Data.String("Hello World"), *Array(10) { Parenthesis.CLOSE },21 Bracket.CLOSE,22 ),23 tokens24 )25 }26 @Test27 fun argsHelloWorld() {28 //val tokens = CrescentLexer.invoke(TestCode.helloWorlds)29 }30 @Test31 fun funThing() {32 }33 @Test34 fun ifStatement() {35 val tokens = CrescentLexer.invoke(TestCode.ifStatement)36 assertContentEquals(37 listOf(38 FUN, Key("test1"), Parenthesis.OPEN, Key("args"), TYPE_PREFIX, SquareBracket.OPEN, Key("String"), SquareBracket.CLOSE, Parenthesis.CLOSE, Bracket.OPEN,39 IF, Parenthesis.OPEN, Key("args"), SquareBracket.OPEN, Data.Number(0.toByte()), SquareBracket.CLOSE, EQUALS_COMPARE, Data.String("true"), Parenthesis.CLOSE, Bracket.OPEN,40 Key("println"), Parenthesis.OPEN, Data.String("Meow"), Parenthesis.CLOSE,41 Bracket.CLOSE,42 ELSE, Bracket.OPEN,43 Key("println"), Parenthesis.OPEN, Data.String("Hiss"), Parenthesis.CLOSE,44 Bracket.CLOSE,45 Bracket.CLOSE,46 FUN, Key("test2"), Parenthesis.OPEN, Key("args"), TYPE_PREFIX, SquareBracket.OPEN, Key("String"), SquareBracket.CLOSE, Parenthesis.CLOSE, RETURN, Key("String"), Bracket.OPEN,47 IF, Parenthesis.OPEN, Key("args"), SquareBracket.OPEN, Data.Number(0.toByte()), SquareBracket.CLOSE, EQUALS_COMPARE, Data.String("true"), Parenthesis.CLOSE, Bracket.OPEN,48 RETURN, Data.String("Meow"),49 Bracket.CLOSE,50 ELSE, Bracket.OPEN,51 RETURN, Data.String("Hiss"),52 Bracket.CLOSE,53 Key("println"), Parenthesis.OPEN, Data.String("This shouldn't be printed"), Parenthesis.CLOSE,54 Bracket.CLOSE,55 FUN, Key("main"), Parenthesis.OPEN, Key("args"), TYPE_PREFIX, SquareBracket.OPEN, Key("String"), SquareBracket.CLOSE, Parenthesis.CLOSE, Bracket.OPEN,56 Key("test1"), Parenthesis.OPEN, Key("args"), Parenthesis.CLOSE,57 Key("println"), Parenthesis.OPEN, Key("test2"), Parenthesis.OPEN, Key("args"), Parenthesis.CLOSE, Parenthesis.CLOSE,58 Bracket.CLOSE59 ),60 tokens61 )62 }63 @Test64 fun ifInputStatement() {65 val tokens = CrescentLexer.invoke(TestCode.ifInputStatement)66 assertContentEquals(67 listOf(68 FUN, Key("main"), Bracket.OPEN,69 VAL, Key("input"), ASSIGN, Key("readBoolean"), Parenthesis.OPEN, Data.String("Enter a boolean value [true/false]"), Parenthesis.CLOSE,70 IF, Parenthesis.OPEN, Key("input"), Parenthesis.CLOSE, Bracket.OPEN,71 Key("println"), Parenthesis.OPEN, Data.String("Meow"), Parenthesis.CLOSE,72 Bracket.CLOSE,73 ELSE, Bracket.OPEN,74 Key("println"), Parenthesis.OPEN, Data.String("Hiss"), Parenthesis.CLOSE,75 Bracket.CLOSE,76 Bracket.CLOSE,77 ),78 tokens79 )80 }81 @Test82 fun stringInterpolation() {83 val tokens = CrescentLexer.invoke(TestCode.stringInterpolation)84 assertContentEquals(85 listOf(86 FUN, Key("main"), Bracket.OPEN,87 VAL, Key("x"), COMMA, Key("y"), COMMA, Key("z"), ASSIGN, Data.Number(0.toByte()),88 Key("println"), Parenthesis.OPEN, Data.String("\$x\$y\$z"), Parenthesis.CLOSE,89 Key("println"), Parenthesis.OPEN, Data.String("Hello \$x\$y\$z Hello"), Parenthesis.CLOSE,90 Key("println"), Parenthesis.OPEN, Data.String("Hello \$x Hello \$y Hello \$z Hello"), Parenthesis.CLOSE,91 Key("println"), Parenthesis.OPEN, Data.String("\${x}\${y}\${z}"), Parenthesis.CLOSE,92 Key("println"), Parenthesis.OPEN, Data.String("Hello \${x}\${y}\${z} Hello"), Parenthesis.CLOSE,93 Key("println"), Parenthesis.OPEN, Data.String("Hello \${x}Hello\${y}Hello\${z} Hello"), Parenthesis.CLOSE,94 Data.Comment("Should printout a dollar sign"),95 Key("println"), Parenthesis.OPEN, Data.String("\${'$'}"), Parenthesis.CLOSE,96 Data.Comment("Should println dollar sign next to the letter x"),97 Key("println"), Parenthesis.OPEN, Data.String("\\\$x"), Parenthesis.CLOSE,98 Key("println"), Parenthesis.OPEN, Data.String("$ x"), Parenthesis.CLOSE,99 Bracket.CLOSE,100 ),101 tokens102 )103 }104 @Test105 fun forLoop1() {106 val tokens = CrescentLexer.invoke(TestCode.forLoop1)107 assertContentEquals(108 listOf(109 FUN, Key("main"), Bracket.OPEN,110 VAL, Key("x"), COMMA, Key("y"), COMMA, Key("z"), ASSIGN, Data.Number(0.toByte()),111 Key("println"), Parenthesis.OPEN, Data.String("\$x\$y\$z"), Parenthesis.CLOSE,112 FOR, Key("x"), CONTAINS, Data.Number(0.toByte()), RANGE_TO, Data.Number(9.toByte()), Bracket.OPEN,113 Key("println"), Parenthesis.OPEN, Data.String("\$x"), Parenthesis.CLOSE,114 Bracket.CLOSE,115 FOR, Key("x"), COMMA, Key("y"), COMMA, Key("z"), CONTAINS, Data.Number(0.toByte()), RANGE_TO, Data.Number(9.toByte()), Bracket.OPEN,116 Key("println"), Parenthesis.OPEN, Data.String("\$x\$y\$z"), Parenthesis.CLOSE,117 Bracket.CLOSE,118 FOR, Key("x"), COMMA, Key("y"), COMMA, Key("z"), CONTAINS, Data.Number(0.toByte()), RANGE_TO, Data.Number(9.toByte()), COMMA, Data.Number(0.toByte()), RANGE_TO, Data.Number(9.toByte()), COMMA, Data.Number(0.toByte()), RANGE_TO, Data.Number(9.toByte()), Bracket.OPEN,119 Key("println"), Parenthesis.OPEN, Data.String("\$x\$y\$z"), Parenthesis.CLOSE,120 Bracket.CLOSE,121 Key("println"), Parenthesis.OPEN, Data.String("Hello World"), Parenthesis.CLOSE,122 Bracket.CLOSE,123 ),124 tokens125 )126 }127 @Test128 fun whileLoop() {129 val tokens = CrescentLexer.invoke(TestCode.whileLoop)130 assertContentEquals(131 listOf(132 FUN, Key("main"), Bracket.OPEN,133 VAR, Key("x"), ASSIGN, Data.Number(1.toByte()),134 WHILE, Parenthesis.OPEN, Key("x"), LESSER_EQUALS_COMPARE, Data.Number(10.toByte()), Parenthesis.CLOSE, Bracket.OPEN,135 Key("println"), Parenthesis.OPEN, Key("x"), Parenthesis.CLOSE,136 Key("x"), ADD_ASSIGN, Data.Number(1.toByte()),137 Bracket.CLOSE,138 Bracket.CLOSE,139 ),140 tokens141 )142 }143 @Test144 fun calculator() {145 val tokens = CrescentLexer.invoke(TestCode.calculator)146 assertContentEquals(147 listOf(148 FUN, Key("main"), Bracket.OPEN,149 VAL, Key("input1"), ASSIGN, Key("readDouble"), Parenthesis.OPEN, Data.String("Enter your first number"), Parenthesis.CLOSE,150 VAL, Key("input2"), ASSIGN, Key("readDouble"), Parenthesis.OPEN, Data.String("Enter your second number"), Parenthesis.CLOSE,151 VAL, Key("operation"), ASSIGN, Key("readLine"), Parenthesis.OPEN, Data.String("Enter an operation [+, -, *, /]"), Parenthesis.CLOSE,152 VAL, Key("result"), ASSIGN, WHEN, Parenthesis.OPEN, Key("operation"), Parenthesis.CLOSE, Bracket.OPEN,153 Data.Char('+'), RETURN, Key("input1"), ADD, Key("input2"),154 Data.Char('-'), RETURN, Key("input1"), SUB, Key("input2"),155 Data.Char('*'), RETURN, Key("input1"), MUL, Key("input2"),156 Data.Char('/'), RETURN, Key("input1"), DIV, Key("input2"),157 Bracket.CLOSE,158 Key("println"), Parenthesis.OPEN, Key("result"), Parenthesis.CLOSE,159 Bracket.CLOSE,160 ),161 tokens162 )163 }164 @Test165 fun constantsAndObject() {166 val tokens = CrescentLexer.invoke(TestCode.constantsAndObject)167 assertContentEquals(168 listOf(169 CONST, Key("thing1"), ASSIGN, Data.String("Mew"),170 OBJECT, Key("Constants"), Bracket.OPEN,171 CONST, Key("thing2"), ASSIGN, Data.String("Meow"),172 FUN, Key("printThings"), Parenthesis.OPEN, Parenthesis.CLOSE, Bracket.OPEN,173 Key("println"), Parenthesis.OPEN, Key("thing1"), Parenthesis.CLOSE,174 Key("println"), Parenthesis.OPEN, Key("thing2"), Parenthesis.CLOSE,175 Bracket.CLOSE,176 Bracket.CLOSE,177 FUN, Key("main"), Bracket.OPEN,178 Key("Constants"), DOT, Key("printThings"), Parenthesis.OPEN, Parenthesis.CLOSE,179 Key("println"), Parenthesis.OPEN, Key("thing1"), Parenthesis.CLOSE,180 Key("println"), Parenthesis.OPEN, Key("Constants"), DOT, Key("thing2"), Parenthesis.CLOSE,181 Bracket.CLOSE182 ),183 tokens184 )185 }186 @Test187 fun impl() {188 val tokens = CrescentLexer.invoke(TestCode.impl)189 assertContentEquals(190 listOf(191 STRUCT, Key("Example"), Parenthesis.OPEN,192 VAL, Key("aNumber"), TYPE_PREFIX, Key("I32"), Data.Comment("New lines makes commas redundant"),193 VAL, Key("aValue1"), Key("aValue2"), ASSIGN, Data.String(""), Data.Comment("Multi declaration of same type, can all be set to one or multiple default values"),194 Parenthesis.CLOSE,195 IMPL, Key("Example"), Bracket.OPEN,196 Data.Comment("All implementation methods"),197 FUN, Key("printValues"), Bracket.OPEN,198 Key("println"), Parenthesis.OPEN, Key("aNumber"), Parenthesis.CLOSE,199 Key("println"), Parenthesis.OPEN, Key("aValue1"), Parenthesis.CLOSE,200 Key("println"), Parenthesis.OPEN, Key("aValue2"), Parenthesis.CLOSE,201 Bracket.CLOSE,202 Bracket.CLOSE,203 Data.Comment("Can't use self in static syntax"),204 IMPL, Modifier.STATIC, Key("Example"), Bracket.OPEN,205 FUN, Key("add"), Parenthesis.OPEN, Key("value1"), Key("value2"), TYPE_PREFIX, Key("I32"), Parenthesis.CLOSE, RETURN, Key("I32"), Bracket.OPEN,206 RETURN, Key("value1"), ADD, Key("value2"),207 Bracket.CLOSE,208 FUN, Key("sub"), Parenthesis.OPEN, Key("value1"), Key("value2"), TYPE_PREFIX, Key("I32"), Parenthesis.CLOSE, RETURN, Key("I32"), Bracket.OPEN,209 RETURN, Key("value1"), SUB, Key("value2"),210 Bracket.CLOSE,211 Bracket.CLOSE,212 FUN, Key("main"), Bracket.OPEN,213 VAL, Key("example"), ASSIGN, Key("Example"), Parenthesis.OPEN, Data.Number(1.toByte()), COMMA, Data.String("Meow"), COMMA, Data.String("Mew"), Parenthesis.CLOSE,214 Key("example"), DOT, Key("printValues"), Parenthesis.OPEN, Parenthesis.CLOSE,215 Key("println"), Parenthesis.OPEN, Parenthesis.CLOSE,216 Key("println"), Parenthesis.OPEN, Key("example"), DOT, Key("aNumber"), Parenthesis.CLOSE,217 Key("println"), Parenthesis.OPEN, Key("example"), DOT, Key("aValue1"), Parenthesis.CLOSE,218 Key("println"), Parenthesis.OPEN, Key("example"), DOT, Key("aValue2"), Parenthesis.CLOSE,219 Key("println"), Parenthesis.OPEN, Key("Example"), DOT, Key("add"), Parenthesis.OPEN, Data.Number(1.toByte()), COMMA, Data.Number(2.toByte()), Parenthesis.CLOSE, Parenthesis.CLOSE,220 Key("println"), Parenthesis.OPEN, Key("Example"), DOT, Key("sub"), Parenthesis.OPEN, Data.Number(1.toByte()), COMMA, Data.Number(2.toByte()), Parenthesis.CLOSE, Parenthesis.CLOSE,221 Bracket.CLOSE,222 ),223 tokens224 )225 }226 @Test227 fun math() {228 val tokens = CrescentLexer.invoke(TestCode.math)229 assertContentEquals(230 listOf(231 FUN, Key("main"), Bracket.OPEN,232 Key("println"), Parenthesis.OPEN,233 Parenthesis.OPEN, Data.Number(1.0.toInt().toByte()), ADD, Data.Number(1.toByte()), Parenthesis.CLOSE,234 ADD, Data.Number(1.0.toInt().toByte()), DIV, Data.Number(10.0.toInt().toByte()), ADD, Data.Number(1000.0.toInt().toShort()), MUL, Data.Number(10.0.toInt().toByte()),235 DIV, Data.Number(11.0.toInt().toByte()), POW, Data.Number(10.0.toInt().toByte()),236 Parenthesis.CLOSE,237 Key("println"), Parenthesis.OPEN,238 Data.Number(4.toByte()), MUL, Parenthesis.OPEN, Data.Number(3.toByte()), Parenthesis.CLOSE, ADD, Data.Number(1.toByte()),239 Parenthesis.CLOSE,240 Bracket.CLOSE,241 ),242 tokens243 )244 }245 @Test246 fun sealed() {247 val tokens = CrescentLexer.invoke(TestCode.sealed)248 assertContentEquals(249 listOf(250 SEALED, Key("Example"), Bracket.OPEN,251 STRUCT, Key("Thing1"), Parenthesis.OPEN, VAL, Key("name"), TYPE_PREFIX, Key("String"), Parenthesis.CLOSE,252 STRUCT, Key("Thing2"), Parenthesis.OPEN, VAL, Key("id"), TYPE_PREFIX, Key("i32"), Parenthesis.CLOSE,253 OBJECT, Key("Thing3"),254 Bracket.CLOSE,255 ),256 tokens257 )258 }259 @Test260 fun enum() {261 val tokens = CrescentLexer.invoke(TestCode.enum)262 assertContentEquals(263 listOf(264 ENUM, Key("Color"), Parenthesis.OPEN, Key("name"), TYPE_PREFIX, Key("String"), Parenthesis.CLOSE, Bracket.OPEN,265 Key("RED"), Parenthesis.OPEN, Data.String("Red"), Parenthesis.CLOSE,266 Key("GREEN"), Parenthesis.OPEN, Data.String("Green"), Parenthesis.CLOSE,267 Key("BLUE"), Parenthesis.OPEN, Data.String("Blue"), Parenthesis.CLOSE,268 Bracket.CLOSE,269 FUN, Key("main"), Bracket.OPEN,270 Data.Comment(".random() will be built into the Enum type implementation"),271 VAL, Key("color"), ASSIGN, Key("Color"), DOT, Key("random"), Parenthesis.OPEN, Parenthesis.CLOSE,272 Data.Comment("Shows off cool Enum shorthand for when statements"),273 WHEN, Parenthesis.OPEN, Key("color"), Parenthesis.CLOSE, Bracket.OPEN,274 DOT, Key("RED"), RETURN, Bracket.OPEN, Key("println"), Parenthesis.OPEN, Data.String("Meow"), Parenthesis.CLOSE, Bracket.CLOSE,275 DOT, Key("GREEN"), RETURN, Bracket.OPEN, Bracket.CLOSE,276 ELSE, RETURN, Bracket.OPEN, Bracket.CLOSE,277 Bracket.CLOSE,278 WHEN, Parenthesis.OPEN, Key("name"), ASSIGN, Key("color"), DOT, Key("name"), Parenthesis.CLOSE, Bracket.OPEN,279 Data.String("Red"), RETURN, Key("println"), Parenthesis.OPEN, Key("name"), Parenthesis.CLOSE,280 Data.String("Green"), RETURN, Bracket.OPEN, Bracket.CLOSE,281 ELSE, RETURN, Bracket.OPEN, Bracket.CLOSE,282 Bracket.CLOSE,283 Bracket.CLOSE,284 ),285 tokens286 )287 }288 @Test289 fun comments() {290 val tokens = CrescentLexer.invoke(TestCode.comments)291 assertContentEquals(292 listOf(293 Data.Comment("Project level comment"),294 FUN, Key("main"), Bracket.OPEN,295 Key("println"), Data.Comment("(\"Meow\")"),296 Data.Comment("Meow"),297 Data.Comment("Meow"),298 Data.String("#meow"),299 Data.Number(1.toByte()), ADD, Data.Comment("Meow"),300 Data.Number(1.toByte()), SUB, Data.Comment("Meow"),301 Data.Number(1.toByte()), DIV, Data.Comment("Meow"),302 Data.Number(1.toByte()), MUL, Data.Comment("Meow"),303 Data.Number(1.toByte()), ASSIGN, Data.Comment("Meow"),304 Data.Comment("}")305 ),306 tokens307 )308 }309 @Test310 fun imports() {311 val tokens = CrescentLexer.invoke(TestCode.imports)312 assertContentEquals(313 listOf(314 Data.Comment("Current idea, Package -> Type"),315 IMPORT, Key("crescent"), DOT, Key("examples"), IMPORT_SEPARATOR, Key("Thing"),316 IMPORT, Key("crescent"), DOT, Key("examples"), IMPORT_SEPARATOR, Key("Thing2"), AS, Key("Thing3"),317 IMPORT, Key("crescent"), DOT, Key("examples"), IMPORT_SEPARATOR, MUL,318 Data.Comment("import crescent.examples as examples"),//IMPORT, Key("crescent"), DOT, Key("examples"), AS, Key("examples"),319 Data.Comment("Short hand method (If in same package)"),320 IMPORT, IMPORT_SEPARATOR, Key("Thing"),321 IMPORT, IMPORT_SEPARATOR, Key("Thing2"), AS, Key("Thing3")322 ),323 tokens324 )325 }326 @Test327 fun nateTriangle() {328 val tokens = CrescentLexer.invoke(TestCode.nateTriangle)329 println(tokens)330 assertContentEquals(331 listOf(332 FUN, Key("triangle"), Parenthesis.OPEN, Key("n"), TYPE_PREFIX, Key("Any"), COMMA, Key("k"), TYPE_PREFIX, Key("Any"), Parenthesis.CLOSE, Bracket.OPEN,333 IF, Parenthesis.OPEN, Key("n"), GREATER_EQUALS_COMPARE, Data.Number(0.toByte()), Parenthesis.CLOSE, Bracket.OPEN,334 Key("triangle"), Parenthesis.OPEN, Key("n"), SUB, Data.Number((1).toByte()), COMMA, Key("k"), ADD, Data.Number(1.toByte()), Parenthesis.CLOSE,335 VAR, Key("x"), TYPE_PREFIX, Key("I32"), ASSIGN, Data.Number(0.toByte()),336 VAR, Key("y"), TYPE_PREFIX, Key("I32"), ASSIGN, Data.Number(0.toByte()),337 WHILE, Parenthesis.OPEN, Key("x"), LESSER_COMPARE, Key("k"), Parenthesis.CLOSE, Bracket.OPEN,338 Key("print"), Parenthesis.OPEN, Data.String(" "), Parenthesis.CLOSE,339 Key("x"), ASSIGN, Key("x"), ADD, Data.Number(1.toByte()),340 Bracket.CLOSE,341 WHILE, Parenthesis.OPEN, Key("y"), LESSER_COMPARE, Key("n"), Parenthesis.CLOSE, Bracket.OPEN,342 Key("print"), Parenthesis.OPEN, Data.String("* "), Parenthesis.CLOSE,343 Key("y"), ASSIGN, Key("y"), ADD, Data.Number(1.toByte()),344 Bracket.CLOSE,345 Key("println"), Parenthesis.OPEN, Parenthesis.CLOSE,346 Bracket.CLOSE,347 Bracket.CLOSE,348 FUN, Key("main"), Parenthesis.OPEN, Parenthesis.CLOSE, Bracket.OPEN,349 Key("triangle"), Parenthesis.OPEN, Data.Number(5.toByte()), COMMA, Data.Number(0.toByte()), Parenthesis.CLOSE,350 Bracket.CLOSE351 ),352 tokens353 )354 }355}...

Full Screen

Full Screen

StoreTest.kt

Source:StoreTest.kt Github

copy

Full Screen

...196 val e = openStore()197 var b = ByteArray(0)198 val recid = e.put(b, Serializers.BYTE_ARRAY_NOSIZE)199 assertTrue(Arrays.equals(b, e.get(recid, Serializers.BYTE_ARRAY_NOSIZE)))200 b = byteArrayOf(1, 2, 3)201 e.update(recid, b, Serializers.BYTE_ARRAY_NOSIZE)202 assertTrue(Arrays.equals(b, e.get(recid, Serializers.BYTE_ARRAY_NOSIZE)))203 e.verify()204 b = byteArrayOf()205 e.update(recid, b, Serializers.BYTE_ARRAY_NOSIZE)206 assertTrue(Arrays.equals(b, e.get(recid, Serializers.BYTE_ARRAY_NOSIZE)))207 e.verify()208 e.delete(recid, Serializers.BYTE_ARRAY_NOSIZE)209 assertFailsWith(DBException.GetVoid::class.java) {210 e.get(recid, Serializers.BYTE_ARRAY_NOSIZE)211 }212 e.verify()213 e.close()214 }215 @Test fun get_deleted() {216 val e = openStore()217 val recid = e.put(1L, Serializers.LONG)218 e.verify()...

Full Screen

Full Screen

HeaderBytesTest.kt

Source:HeaderBytesTest.kt Github

copy

Full Screen

...16import org.junit.Test17import org.junit.runner.RunWith18@RunWith(AndroidJUnit4::class)19class HeaderBytesTest {20 val bytes = "abcdefghijklmnopqrstuvwxyz".toByteArray()21 @Test22 fun testRangeEquals() {23 HeaderBytes(bytes).apply {24 Assert.assertTrue(rangeEquals(0, "abc".toByteArray()))25 Assert.assertTrue(rangeEquals(1, "bcd".toByteArray()))26 Assert.assertTrue(rangeEquals(20, "uvw".toByteArray()))27 Assert.assertTrue(rangeEquals(23, "xyz".toByteArray()))28 Assert.assertFalse(rangeEquals(0, "abd".toByteArray()))29 Assert.assertFalse(rangeEquals(1, "bdc".toByteArray()))30 Assert.assertFalse(rangeEquals(20, "uwf".toByteArray()))31 }32 }33 @Test34 fun testIndexOf() {35 HeaderBytes(bytes).apply {36 Assert.assertEquals(0, indexOf('a'.code.toByte(), 0, 26))37 Assert.assertEquals(0, indexOf('a'.code.toByte(), 0, 1))38 Assert.assertEquals(12, indexOf('m'.code.toByte(), 0, 26))39 Assert.assertEquals(25, indexOf('z'.code.toByte(), 0, 26))40 Assert.assertEquals(-1, indexOf('a'.code.toByte(), 0, 0))41 Assert.assertEquals(-1, indexOf('a'.code.toByte(), 1, 26))42 Assert.assertEquals(-1, indexOf('m'.code.toByte(), 13, 26))43 assertThrow(IllegalArgumentException::class) {44 indexOf('z'.code.toByte(), 28, 26)45 }46 Assert.assertEquals(0, indexOf("abc".toByteArray(), 0, 26))47 Assert.assertEquals(12, indexOf("mno".toByteArray(), 0, 26))48 Assert.assertEquals(23, indexOf("xyz".toByteArray(), 0, 26))49 Assert.assertEquals(-1, indexOf("abc".toByteArray(), 10, 26))50 Assert.assertEquals(-1, indexOf("mno".toByteArray(), 15, 26))51 Assert.assertEquals(-1, indexOf("xyz".toByteArray(), 25, 26))52 }53 }54 @Test55 fun testGet() {56 HeaderBytes(bytes).apply {57 Assert.assertEquals('a'.code.toByte(), get(0))58 Assert.assertEquals('m'.code.toByte(), get(12))59 Assert.assertEquals('z'.code.toByte(), get(25))60 assertThrow(ArrayIndexOutOfBoundsException::class) {61 get(26)62 }63 }64 }65 @Test66 fun testIsWebP() {67 val (context, _) = getContextAndSketch()68 HeaderBytes(context.assets.open("sample.webp").use {69 ByteArray(1024).apply { it.read(this) }70 }).apply {...

Full Screen

Full Screen

TestPrelude.kt

Source:TestPrelude.kt Github

copy

Full Screen

...105 assertFalse(listOf(s2, s4).isDisjoint { it })106 }107 @Test108 fun testByteString() {109 val byteArray = byteArrayOf(127, 0, -1)110 val byteString = ByteString(byteArray)111 byteArray[0] = 120112 assertEquals(3, byteString.size())113 assertEquals(0, byteString.byteAt(1))114 assertEquals("7f 00 ff", byteString.toString())115 assertEquals(1, setOf(byteString, ByteString(byteString.toList().toByteArray())).size)116 assertEquals("byte", ByteString("byte".toByteArray()).asString())117 val byteArray2 = byteString.toByteArray()118 val byteString2 = ByteString(byteArray2)119 byteArray2[0] = 120120 assertEquals(byteString, byteString2)121 }122}...

Full Screen

Full Screen

UnInterruptibleFileChannelTest.kt

Source:UnInterruptibleFileChannelTest.kt Github

copy

Full Screen

...14class UnInterruptibleFileChannelTest {15 @Rule16 @JvmField17 val tempDirectory = TempDirectory()18 private val byteBuf1 = ByteBuffer.wrap(byteArrayOf(1, 2, 3, 4))19 private val byteBuf2 = ByteBuffer.wrap(byteArrayOf(5, 6, 7, 8))20 @After21 fun clearInterruptedStatus() {22 Thread.interrupted()23 }24 @Test25 fun `test no interruption`() {26 UnInterruptibleFileChannel(newTempFile(), StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE).use {27 it.write(byteBuf1)28 it.write(byteBuf2)29 val readBuffer1 = ByteBuffer.allocate(4)30 it.read(readBuffer1, 0)31 val readBuffer2 = ByteBuffer.allocate(4)32 it.read(readBuffer2, 0)33 Assert.assertEquals(byteBuf1, readBuffer1)34 Assert.assertEquals(byteBuf2, readBuffer2)35 }36 }37 @Test38 fun `test interrupted on last operation`() {39 UnInterruptibleFileChannel(newTempFile(), StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE).use {40 it.write(byteBuf1)41 it.write(byteBuf2)42 val readBuffer1 = ByteBuffer.allocate(4)43 it.read(readBuffer1, 0)44 val currentThread = Thread.currentThread()45 currentThread.interrupt()46 val readBuffer2 = ByteBuffer.allocate(4)47 it.read(readBuffer2, 0)48 Assert.assertEquals(byteBuf1, readBuffer1)49 Assert.assertEquals(byteBuf2, readBuffer2)50 }51 }52 @Test53 fun `test interrupted in the middle`() {54 UnInterruptibleFileChannel(newTempFile(), StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE).use {55 it.write(byteBuf1)56 it.write(byteBuf2)57 val currentThread = Thread.currentThread()58 currentThread.interrupt()59 val readBuffer1 = ByteBuffer.allocate(4)60 it.read(readBuffer1, 0)61 Assert.assertTrue(Thread.currentThread().isInterrupted)62 val readBuffer2 = ByteBuffer.allocate(4)63 it.read(readBuffer2, 0)64 Assert.assertEquals(byteBuf1, readBuffer1)65 Assert.assertEquals(byteBuf2, readBuffer2)66 }67 }68 @Test69 fun `test open existing file`() {70 val file = newTempFile()71 UnInterruptibleFileChannel(file, StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE).use {72 it.write(byteBuf1)73 it.write(byteBuf2)74 }75 Thread.currentThread().interrupt()76 val readBuffer1 = ByteBuffer.allocate(4)77 val readBuffer2 = ByteBuffer.allocate(4)78 UnInterruptibleFileChannel(file, StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE).use {79 it.read(readBuffer1, 0)80 it.read(readBuffer2, 0)81 }82 Assert.assertEquals(byteBuf1, readBuffer1)83 Assert.assertEquals(byteBuf2, readBuffer2)84 }85 @Test86 fun `test write to read-only file`() {87 val file = newTempFile()88 var secondOperationStarted = false89 var exceptionHappened = false90 try {91 UnInterruptibleFileChannel(file, StandardOpenOption.READ).use {92 it.write(byteBuf1)93 secondOperationStarted = true94 it.write(byteBuf2)95 }96 Assert.fail("Should not executed without exception")97 }98 catch (e: NonWritableChannelException) {99 exceptionHappened = true100 }101 Assert.assertTrue(exceptionHappened)102 Assert.assertFalse(secondOperationStarted)103 }104 @Test105 fun `test concurrent access`() {106 val file = newTempFile()107 val threadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())108 fun joinThreads() {109 threadPool.shutdown()110 repeat(60) {111 if (threadPool.awaitTermination(1, TimeUnit.SECONDS)) {112 return@repeat113 }114 }115 Assert.assertTrue(threadPool.isTerminated)116 }117 try {118 UnInterruptibleFileChannel(file, StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE).use { fileHandle ->119 (0..100).map {120 threadPool.submit {121 val threadId = Thread.currentThread().id122 val data = byteArrayOf(threadId.toByte(), threadId.toByte(), threadId.toByte(), threadId.toByte())123 fileHandle.write(ByteBuffer.wrap(data), threadId * 4)124 }125 }.toList().forEach { it.get(1, TimeUnit.MINUTES) }126 Thread.currentThread().interrupt()127 fileHandle.size()128 Assert.assertTrue(Thread.interrupted())129 (0..100).map {130 threadPool.submit {131 val threadId = Thread.currentThread().id132 val expectedData = ByteBuffer.wrap(byteArrayOf(threadId.toByte(), threadId.toByte(), threadId.toByte(), threadId.toByte()))133 val actualData = ByteBuffer.allocate(4)134 Assert.assertEquals(4, fileHandle.read(actualData, threadId * 4))135 Assert.assertEquals(expectedData, actualData.rewind())136 }137 }.toList().forEach { it.get(1, TimeUnit.MINUTES) }138 }139 }140 finally {141 joinThreads()142 }143 }144 private fun newTempFile() = tempDirectory.newFile("test.txt").toPath()145}...

Full Screen

Full Screen

IoTest.kt

Source:IoTest.kt Github

copy

Full Screen

1package array2import kotlin.test.*3class IoTest {4 @Test5 fun testBinaryFile() {6 openInputFile("test-data/plain.txt").use { input ->7 val buf = ByteArray(3)8 val result = input.readBlock(buf)9 assertEquals(3, result)10 assertByteArrayContent("abc".encodeToByteArray(), buf)11 }12 }13 @Test14 fun testPartialBlock() {15 openInputFile("test-data/plain.txt").use { input ->16 val buf = ByteArray(10) { 0 }17 val result = input.readBlock(buf, 2, 3)18 assertEquals(3, result)19 assertByteArrayContent("abc".encodeToByteArray(), buf, 2)20 }21 }22 @Test23 fun testMultipleReads() {24 openInputFile("test-data/plain.txt").use { input ->25 val buf = ByteArray(5) { 0 }26 val result1 = input.readBlock(buf, 2, 3)27 assertEquals(3, result1)28 assertByteArrayContent("abc".encodeToByteArray(), buf, 2)29 val result2 = input.readBlock(buf, 0, 3)30 assertEquals(3, result2)31 assertByteArrayContent("bar".encodeToByteArray(), buf)32 }33 }34 @Test35 fun testCharacterContent() {36 openInputCharFile("test-data/char-tests.txt").use { input ->37 assertEquals(0x61, input.nextCodepoint())38 assertEquals(0x62, input.nextCodepoint())39 assertEquals(0x2283, input.nextCodepoint())40 assertEquals(0x22C6, input.nextCodepoint())41 assertEquals(0x1D49F, input.nextCodepoint())42 assertEquals(0xE01, input.nextCodepoint())43 assertEquals(0xA, input.nextCodepoint())44 assertNull(input.nextCodepoint())45 }46 }47 @Test48 fun testReadline() {49 openInputCharFile("test-data/plain.txt").use { input ->50 assertEquals("abcbar", input.nextLine())51 assertNull(input.nextCodepoint())52 }53 }54 @Test55 fun characterProviderLines() {56 openInputCharFile("test-data/multi.txt").use { input ->57 val expected = listOf("foo", "bar", "test", "abcdef", "testtest", " testline", "", "aa", "ab", "ac", "ad")58 val res = ArrayList<String>()59 input.lines().forEach { s ->60 res.add(s)61 }62 assertEquals(expected, res)63 }64 }65 @Test66 fun fileNotFoundError() {67 assertFailsWith<MPFileException> {68 openInputCharFile("test-data/this-file-should-not-be-found")69 }70 }71 @Test72 fun stringBuilderOutput() {73 val out = StringBuilderOutput()74 out.writeString("abc")75 out.writeString("efg")76 assertEquals("abcefg", out.buf.toString())77 }78 @Test79 fun resolveDirectoryPathAbsolute() {80 assertEquals("/foo/bar", resolveDirectoryPath("/foo/bar", "/xyz"))81 }82 @Test83 fun resolveDirectoryPathRelative() {84 assertEquals("/xyz/foo/bar", resolveDirectoryPath("foo/bar", "/xyz"))85 }86 @Test87 fun resolveDirectoryPathBlankNameNotAllowed() {88 assertFails {89 resolveDirectoryPath("", "/foo/bar")90 }91 }92 @Test93 fun resolveDirectoryPathWithNull() {94 assertEquals("foo/bar", resolveDirectoryPath("foo/bar", null))95 assertEquals("/foo/bar", resolveDirectoryPath("/foo/bar", null))96 }97 @Test98 fun stringCharacterProvider() {99 val prov = StringCharacterProvider("fooabc")100 assertEquals('f'.code, prov.nextCodepoint())101 assertEquals('o'.code, prov.nextCodepoint())102 assertEquals('o'.code, prov.nextCodepoint())103 assertEquals('a'.code, prov.nextCodepoint())104 assertEquals('b'.code, prov.nextCodepoint())105 assertEquals('c'.code, prov.nextCodepoint())106 assertNull(prov.nextCodepoint())107 }108 @Test109 fun astralPlaneStringCharProv() {110 openInputCharFile("test-data/char-tests.txt").use { input ->111 val s = input.nextLine()112 assertNotNull(s)113 val prov = StringCharacterProvider(s)114 assertEquals(0x61, prov.nextCodepoint())115 assertEquals(0x62, prov.nextCodepoint())116 assertEquals(0x2283, prov.nextCodepoint())117 assertEquals(0x22C6, prov.nextCodepoint())118 assertEquals(0x1D49F, prov.nextCodepoint())119 assertEquals(0xE01, prov.nextCodepoint())120 assertNull(prov.nextCodepoint())121 }122 }123 private fun assertByteArrayContent(expected: ByteArray, content: ByteArray, start: Int? = null) {124 val startPos = start ?: 0125 for (i in expected.indices) {126 assertEquals(expected[i], content[startPos + i])127 }128 }129}...

Full Screen

Full Screen

AtomicFileTest.kt

Source:AtomicFileTest.kt Github

copy

Full Screen

...32 file = AtomicFile(temporaryFolder.newFile())33 }34 @Test fun tryWriteSuccess() {35 file.tryWrite {36 it.write(byteArrayOf(0, 1, 2))37 }38 val bytes = file.openRead().use { it.readBytes() }39 assertArrayEquals(byteArrayOf(0, 1, 2), bytes)40 }41 @Test fun tryWriteFail() {42 val os = file.startWrite()43 os.write(byteArrayOf(0, 1, 2))44 file.finishWrite(os)45 val failure = IOException("Broken!")46 assertThrows<IOException> {47 file.tryWrite {48 it.write(byteArrayOf(3, 4, 5))49 throw failure50 }51 }.isSameAs(failure)52 val bytes = file.openRead().use { it.readBytes() }53 assertArrayEquals(byteArrayOf(0, 1, 2), bytes)54 }55 @Test fun writeBytes() {56 file.writeBytes(byteArrayOf(0, 1, 2))57 val bytes = file.openRead().use { it.readBytes() }58 assertArrayEquals(byteArrayOf(0, 1, 2), bytes)59 }60 @Test fun writeText() {61 file.writeText("Hey")62 val bytes = file.openRead().use { it.readBytes() }63 assertArrayEquals(byteArrayOf(72, 101, 121), bytes)64 }65 @Test fun writeTextCharset() {66 file.writeText("Hey", charset = Charsets.UTF_16LE)67 val bytes = file.openRead().use { it.readBytes() }68 assertArrayEquals(byteArrayOf(72, 0, 101, 0, 121, 0), bytes)69 }70 @Test fun readBytes() {71 val os = file.startWrite()72 os.write(byteArrayOf(0, 1, 2))73 file.finishWrite(os)74 assertArrayEquals(byteArrayOf(0, 1, 2), file.readBytes())75 }76 @Test fun readText() {77 val os = file.startWrite()78 os.write(byteArrayOf(72, 101, 121))79 file.finishWrite(os)80 assertEquals("Hey", file.readText())81 }82 @Test fun readTextCharset() {83 val os = file.startWrite()84 os.write(byteArrayOf(72, 0, 101, 0, 121, 0))85 file.finishWrite(os)86 assertEquals("Hey", file.readText(charset = Charsets.UTF_16LE))87 }88}...

Full Screen

Full Screen

GpxSerializerTest.kt

Source:GpxSerializerTest.kt Github

copy

Full Screen

1package com.tobiaskress.readwritegpxandroid.parser2import org.junit.Test3import java.io.ByteArrayInputStream4class GpxSerializerTest {5 @Test6 fun testWriteShoresOfDerwentwater() {7 val input = ReadWriteGpxTest.getAssets()!!.open("shores-of-derwentwater.xml")8 val gpx = GpxParser().parse(input)9 val serializedGpx = GpxSerializer().serialize(gpx)10 val serializedInput = ByteArrayInputStream(serializedGpx.toByteArray(Charsets.UTF_8))11 ReadWriteGpxTest.testShoresOfDerwentwater(serializedInput)12 }13 @Test14 fun testWriteWadlbeisserExport() {15 val input = ReadWriteGpxTest.getAssets()!!.open("wadlbeisserExport.gpx")16 val gpx = GpxParser().parse(input)17 val serializedGpx = GpxSerializer().serialize(gpx)18 val serializedInput = ByteArrayInputStream(serializedGpx.toByteArray(Charsets.UTF_8))19 ReadWriteGpxTest.testWadlbeisserExport(serializedInput)20 }21 @Test22 fun testWriteGarminBaseCampExport() {23 val input = ReadWriteGpxTest.getAssets()!!.open("garminBaseCampExport.gpx")24 val gpx = GpxParser().parse(input)25 val serializedGpx = GpxSerializer().serialize(gpx)26 val serializedInput = ByteArrayInputStream(serializedGpx.toByteArray(Charsets.UTF_8))27 ReadWriteGpxTest.testGarminBaseCampExport(serializedInput)28 }29 @Test30 fun testWriteFullMetadataParsing() {31 val input = ReadWriteGpxTest.getAssets()!!.open("metadata-full.gpx")32 val gpx = GpxParser().parse(input)33 val serializedGpx = GpxSerializer().serialize(gpx)34 val serializedInput = ByteArrayInputStream(serializedGpx.toByteArray(Charsets.UTF_8))35 ReadWriteGpxTest.testFullMetadataParsing(serializedInput)36 }37 @Test38 fun testWriteMinimalMetadataParsing() {39 val input = ReadWriteGpxTest.getAssets()!!.open("metadata-minimal.gpx")40 val gpx = GpxParser().parse(input)41 val serializedGpx = GpxSerializer().serialize(gpx)42 val serializedInput = ByteArrayInputStream(serializedGpx.toByteArray(Charsets.UTF_8))43 ReadWriteGpxTest.testMinimalMetadataParsing(serializedInput)44 }45 @Test46 fun testWriteMissingMagvar() {47 val input = ReadWriteGpxTest.getAssets()!!.open("missing-magvar.gpx")48 val gpx = GpxParser().parse(input)49 val serializedGpx = GpxSerializer().serialize(gpx)50 val serializedInput = ByteArrayInputStream(serializedGpx.toByteArray(Charsets.UTF_8))51 ReadWriteGpxTest.testMissingMagvar(serializedInput)52 }53}...

Full Screen

Full Screen

byte

Using AI Code Generation

copy

Full Screen

1package com.example.sqllite;2import java.io.File;3import android.app.Activity;4import android.content.Context;5import android.database.Cursor;6import android.database.sqlite.SQLiteDatabase;7import android.os.Bundle;8import android.os.Environment;9import android.util.Log;10import android.view.View;11import android.view.View.OnClickListener;12import android.widget.Button;13public class MainActivity extends Activity {14SQLiteDatabase db;15public void onCreate(Bundle savedInstanceState) {16super.onCreate(savedInstanceState);17setContentView(R.layout.activity_main);18Button btnCreate = (Button) findViewById(R.id.btnCreate);19Button btnInsert = (Button) findViewById(R.id.btnInsert);20Button btnUpdate = (Button) findViewById(R.id.btnUpdate);21Button btnDelete = (Button) findViewById(R.id.btnDelete);22Button btnSelect = (Button) findViewById(R.id.btnSelect);23btnCreate.setOnClickListener(new OnClickListener() {24public void onClick(View v) {25db = openOrCreateDatabase("test.db", Context.MODE_PRIVATE, null);26db.execSQL("CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR);");27db.execSQL("CREATE INDEX IF NOT EXISTS idx_name ON test (name);");28}29});30btnInsert.setOnClickListener(new OnClickListener() {31public void onClick(View v) {32db.execSQL("INSERT INTO test VALUES (NULL, 'test1');");33db.execSQL("INSERT INTO test VALUES (NULL, 'test2');");34db.execSQL("INSERT INTO test VALUES (NULL, 'test3');");35}36});37btnUpdate.setOnClickListener(new OnClickListener() {38public void onClick(View v) {39db.execSQL("UPDATE test SET name = ? WHERE id = ?", new Object[] { "test4", 1 });40}41});42btnDelete.setOnClickListener(new OnClickListener() {43public void onClick(View v) {44db.execSQL("DELETE FROM test WHERE id = ?", new Object[] { 2 });45}46});47btnSelect.setOnClickListener(new OnClickListener() {48public void onClick(View v) {49Cursor c = db.rawQuery("SELECT * FROM test", null);50while (c.moveToNext()) {51Log.i("SQLite",

Full Screen

Full Screen

byte

Using AI Code Generation

copy

Full Screen

1private void button1_Click(object sender, EventArgs e)2{3string str = "Hello World";4byte[] bytes = Encoding.ASCII.GetBytes(str);5string str2 = Encoding.ASCII.GetString(bytes);6MessageBox.Show(str2);7}8private void button2_Click(object sender, EventArgs e)9{10string str = "Hello World";11char[] chars = str.ToCharArray();12string str2 = new string(chars);13MessageBox.Show(str2);14}15private void button3_Click(object sender, EventArgs e)16{17string str = "Hello World";18byte[] bytes = Encoding.Unicode.GetBytes(str);19string str2 = Encoding.Unicode.GetString(bytes);20MessageBox.Show(str2);21}22private void button4_Click(object sender, EventArgs e)23{24string str = "Hello World";25byte[] bytes = Encoding.UTF8.GetBytes(str);26string str2 = Encoding.UTF8.GetString(bytes);27MessageBox.Show(str2);28}29private void button5_Click(object sender, EventArgs e)30{31string str = "Hello World";32byte[] bytes = Encoding.UTF32.GetBytes(str);33string str2 = Encoding.UTF32.GetString(bytes);34MessageBox.Show(str2);35}36private void button6_Click(object sender, EventArgs e)37{38string str = "Hello World";39byte[] bytes = Encoding.ASCII.GetBytes(str);40string str2 = Encoding.ASCII.GetString(bytes);41MessageBox.Show(str2);42}43private void button7_Click(object sender, EventArgs e)44{45string str = "Hello World";46byte[] bytes = Encoding.Default.GetBytes(str);47string str2 = Encoding.Default.GetString(bytes);48MessageBox.Show(str2);49}50private void button8_Click(object sender, EventArgs e)51{52string str = "Hello World";53byte[] bytes = Encoding.Unicode.GetBytes(str);54string str2 = Encoding.Unicode.GetString(bytes);55MessageBox.Show(str2);56}57private void button9_Click(object sender

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful