Best Kotest code snippet using io.kotest.matchers.collections.bein.beIn
spider.kt
Source:spider.kt
1package assimp.obj2import assimp.*3import glm_.mat4x4.Mat44import glm_.vec3.Vec35import io.kotest.matchers.collections.shouldContain6import io.kotest.matchers.shouldBe7import java.io.File8import java.net.URL9import java.util.*10object spider {11 var isObj = false12 var isFbx = false13 fun reset() {14 isObj = false15 isFbx = false16 }17 object obj {18 operator fun invoke(directory: String) {19 isObj = true20 val urls = File(getResource(directory).toURI())21 .listFiles()!!22 .filterNot { it.absolutePath.endsWith("spider.obj", ignoreCase = true) }23 .map { it.toURI().toURL() }24 .toTypedArray()25 val objFile = getResource("$directory/spider.obj")26 check(objFile, *urls)27 reset()28 }29 }30 object fbx {31 operator fun invoke(directory: String,32 objFileMeshIndices: Boolean = true) {33 isFbx = true34 check(getResource("$directory/spider.fbx"))35 reset()36 }37 }38 fun check(vararg urls: URL) =39 Importer().testURLs(*urls) {40 with(rootNode) {41 transformation shouldBe Mat4()42 numChildren shouldBe 1943 val remainingNames = mutableListOf("HLeib01", "OK", "Bein1Li", "Bein1Re", "Bein2Li", "Bein2Re", "Bein3Re", "Bein3Li", "Bein4Re",44 "Bein4Li", "Zahn", "klZahn", "Kopf", "Brust", "Kopf2", "Zahn2", "klZahn2", "Auge", "Duplicate05")45 (0 until numChildren).map {46 val childNode = children[it]47 when {48 isObj -> remainingNames[0] shouldBe childNode.name49 else -> remainingNames shouldContain childNode.name50 }51 remainingNames -= childNode.name52 childNode.meshes[0] shouldBe it53 }54 numMeshes shouldBe 055 }56 numMeshes shouldBe 1957 with(meshes.find { it.name == "HLeib01" }!!) {58 primitiveTypes shouldBe AiPrimitiveType.TRIANGLE.i59 numVertices shouldBe 24060 numFaces shouldBe 8061 vertices[0].shouldEqual(Vec3(x = 1.160379, y = 4.512684, z = 6.449167), epsilon)62 vertices[numVertices - 1].shouldEqual(Vec3(x = -4.421391, y = -3.605049, z = -20.462471), epsilon)63 normals[0].shouldEqual(Vec3(-0.537588000, -0.0717979968, 0.840146005), epsilon)64 normals[numVertices - 1].shouldEqual(Vec3(-0.728103995, -0.400941998, -0.555975974), epsilon)65 // TODO check for kotlintest 2.0 array check66 textureCoords[0][0].contentEquals(floatArrayOf(0.186192f, 0.222718f)) shouldBe true67 textureCoords[0][numVertices - 1].contentEquals(floatArrayOf(0.103881f, 0.697021f)) shouldBe true68 textureCoords[0][0].size shouldBe 269 faces[0] shouldBe listOf(0, 1, 2)70 faces[numFaces - 1] shouldBe listOf(237, 238, 239)71 materials[materialIndex].name shouldBe "HLeibTex"72 }73 with(meshes.find { it.name == "OK" }!!) {74 primitiveTypes shouldBe AiPrimitiveType.TRIANGLE.i75 numVertices shouldBe 18076 numFaces shouldBe 6077 vertices[0].shouldEqual(Vec3(x = -41.8566132f, y = -0.754845977f, z = 9.43077183f), epsilon)78 vertices[numVertices - 1].shouldEqual(Vec3(x = -49.7138367f, y = -2.98359, z = -21.4211159f), epsilon)79 normals[0].shouldEqual(Vec3(x = -0.236278996f, y = 0.0291850008f, z = 0.971247017f), epsilon)80 normals[numVertices - 1].shouldEqual(Vec3(x = -0.862017989f, y = 0.0830229968f, z = -0.500032008f), epsilon)81 textureCoords[0][0].contentEquals(floatArrayOf(-0.0658710003f, -0.410016000f)) shouldBe true82 textureCoords[0][numVertices - 1].contentEquals(floatArrayOf(-0.318565995f, 1.05051804f)) shouldBe true83 textureCoords[0][0].size shouldBe 284 faces[0] shouldBe listOf(0, 1, 2)85 faces[numFaces - 1] shouldBe listOf(177, 178, 179)86 materials[materialIndex].name shouldBe "Skin"87 }88 with(meshes.find { it.name == "Duplicate05" }!!) {89 primitiveTypes shouldBe AiPrimitiveType.TRIANGLE.i90 numVertices shouldBe 11491 numFaces shouldBe 3892 vertices[0].shouldEqual(Vec3(x = -59.4670486f, y = 18.1400757f, z = -17.1943588), epsilon)93 vertices[numVertices - 1].shouldEqual(Vec3(x = -62.2673569f, y = 15.2776031f, z = -14.7453232f), epsilon)94 normals[0].shouldEqual(Vec3(x = 0.0751359984f, y = 0.741809011f, z = -0.666388988f), epsilon)95 normals[numVertices - 1].shouldEqual(Vec3(x = -0.776385009f, y = -0.629855990f, z = 0.0225169994f), epsilon)96 textureCoords[0][0].contentEquals(floatArrayOf(0.899282992f, 0.970311999f)) shouldBe true97 textureCoords[0][numVertices - 1].contentEquals(floatArrayOf(0.372330993f, 0.198948994f)) shouldBe true98 textureCoords[0][0].size shouldBe 299 faces[0] shouldBe listOf(0, 1, 2)100 faces[numFaces - 1] shouldBe listOf(111, 112, 113)101 materials[materialIndex].name shouldBe "Augentex"102 }103 if (isObj) {104 /*105 TODO the material data in the fbx file is different from the obj file(mat file)106 because of that we just don't check the material data in the fbx file right now.107 */108 with(materials.find { it.name == "Skin" }!!) {109 shadingModel shouldBe AiShadingMode.gouraud110 with(color!!) {111 ambient!!.shouldEqual(Vec3(0.200000003f), epsilon)112 diffuse!!.shouldEqual(Vec3(0.827450991f, 0.792156994f, 0.772548974f), epsilon)113 specular!!.shouldEqual(Vec3(0), epsilon)114 emissive!!.shouldEqual(Vec3(0), epsilon)115 shininess shouldBe 0f116 opacity shouldBe 1f117 refracti shouldBe 1f118 }119 textures[0].file shouldBe ".\\wal67ar_small.jpg"120 }121 with(materials.find { it.name == "Brusttex" }!!) {122 shadingModel shouldBe AiShadingMode.gouraud123 with(color!!) {124 ambient!!.shouldEqual(Vec3(0.200000003f), epsilon)125 diffuse!!.shouldEqual(Vec3(0.800000012f), epsilon)126 specular!!.shouldEqual(Vec3(0), epsilon)127 emissive!!.shouldEqual(Vec3(0), epsilon)128 shininess shouldBe 0f129 opacity shouldBe 1f130 refracti shouldBe 1f131 }132 textures[0].file shouldBe ".\\wal69ar_small.jpg"133 }134 with(materials.find { it.name == "HLeibTex" }!!) {135 shadingModel shouldBe AiShadingMode.gouraud136 with(color!!) {137 ambient!!.shouldEqual(Vec3(0.200000003f), epsilon)138 diffuse!!.shouldEqual(Vec3(0.690195978f, 0.639216006f, 0.615685999f), epsilon)139 specular!!.shouldEqual(Vec3(0), epsilon)140 emissive!!.shouldEqual(Vec3(0), epsilon)141 shininess shouldBe 0f142 opacity shouldBe 1f143 refracti shouldBe 1f144 }145 textures[0].file shouldBe ".\\SpiderTex.jpg"146 }147 with(materials.find { it.name == "BeinTex" }!!) {148 shadingModel shouldBe AiShadingMode.gouraud149 with(color!!) {150 ambient!!.shouldEqual(Vec3(0.200000003f), epsilon)151 diffuse!!.shouldEqual(Vec3(0.800000012f), epsilon)152 specular!!.shouldEqual(Vec3(0), epsilon)153 emissive!!.shouldEqual(Vec3(0), epsilon)154 shininess shouldBe 0f155 opacity shouldBe 1f156 refracti shouldBe 1f157 }158 textures[0].file shouldBe ".\\drkwood2.jpg"159 }160 with(materials.find { it.name == "Augentex" }!!) {161 name shouldBe "Augentex"162 shadingModel shouldBe AiShadingMode.gouraud163 with(color!!) {164 ambient!!.shouldEqual(Vec3(0.200000003f), epsilon)165 diffuse!!.shouldEqual(Vec3(0.800000012f), epsilon)166 specular!!.shouldEqual(Vec3(0), epsilon)167 emissive!!.shouldEqual(Vec3(0), epsilon)168 shininess shouldBe 0f169 opacity shouldBe 1f170 refracti shouldBe 1f171 }172 textures[0].file shouldBe ".\\engineflare1.jpg"173 }174 if (!isObj)175 numTextures shouldBe 5 // TODO numTextures is not set in obj176 textures.size shouldBe 5177 }178 }179}...
bein.kt
Source:bein.kt
...14 *15 * An empty collection will always fail. If you need to check for empty collection, use [Collection.shouldBeEmpty]16 *17 * @see [shouldNotBeIn]18 * @see [beIn]19 */20infix fun <T> T.shouldBeIn(collection: Collection<T>): T {21 this should beIn(collection)22 return this23}24/**25 * Verifies that this element is NOT any of [collection]26 *27 * Assertion to check that this element is not any of [collection]. This assertion checks by value, and not by reference,28 * therefore any instance with same value must not be in [collection], or this will fail.29 *30 * An empty collection will always fail. If you need to check for empty collection, use [Collection.shouldBeEmpty]31 *32 * @see [shouldNotBeIn]33 * @see [beIn]34 */35infix fun <T> T.shouldNotBeIn(collection: Collection<T>): T {36 this shouldNot beIn(collection.toList())37 return this38}39/**40 * Verifies that this element is any of [any] by comparing value41 *42 * Assertion to check that this element is any of [any]. This assertion checks by value, and not by reference,43 * therefore even if the exact instance is not any of [any] but another instance with same value is present, the44 * test will pass.45 *46 * An empty collection will always fail. If you need to check for empty collection, use [Collection.shouldBeEmpty]47 *48 * @see [shouldNotBeIn]49 * @see [beIn]50 */51fun <T> T.shouldBeIn(vararg any: T): T {52 this should beIn(any.toList())53 return this54}55/**56 * Verifies that this element is NOT any of [any]57 *58 * Assertion to check that this element is not any of [any]. This assertion checks by value, and not by reference,59 * therefore any instance with same value must not be in [any], or this will fail.60 *61 * An empty collection will always fail. If you need to check for empty collection, use [Collection.shouldBeEmpty]62 *63 * @see [shouldNotBeIn]64 * @see [beIn]65 */66fun <T> T.shouldNotBeIn(vararg any: T): T {67 this shouldNot beIn(any.toList())68 return this69}70/**71 * Verifies that this element is in [array] by comparing value72 *73 * Assertion to check that this element is in [array]. This assertion checks by value, and not by reference,74 * therefore even if the exact instance is not in [array] but another instance with same value is present, the75 * test will pass.76 *77 * An empty array will always fail. If you need to check for empty array, use [Array.shouldBeEmpty]78 *79 * @see [shouldNotBeIn]80 * @see [beIn]81 */82@JvmName("shouldBeInArray")83infix fun <T> T.shouldBeIn(array: Array<T>): T {84 this should beIn(array.toList())85 return this86}87/**88 * Verifies that this element is NOT any of [array]89 *90 * Assertion to check that this element is not any of [array]. This assertion checks by value, and not by reference,91 * therefore any instance with same value must not be in [array], or this will fail.92 *93 * An empty array will always fail. If you need to check for empty array, use [Array.shouldBeEmpty]94 *95 * @see [shouldNotBeIn]96 * @see [beIn]97 */98@JvmName("shouldNotBeInArray")99infix fun <T> T.shouldNotBeIn(array: Array<T>): T {100 this shouldNot beIn(array.toList())101 return this102}103/**104 * Matcher that verifies that this element is in [collection] by comparing value105 *106 * Assertion to check that this element is in [collection]. This assertion checks by value, and not by reference,107 * therefore even if the exact instance is not in [collection] but another instance with same value is present, the108 * test will pass.109 *110 * An empty collection will always fail. If you need to check for empty collection, use [Collection.shouldBeEmpty]111 *112 * @see [shouldBeOneOf]113 * @see [shouldNotBeOneOf]114 */115fun <T> beIn(collection: Collection<T>) = object : Matcher<T> {116 override fun test(value: T): MatcherResult {117 if (collection.isEmpty()) throwEmptyCollectionError()118 val match = value in collection119 return MatcherResult(120 match,121 { "Collection should contain ${value.print().value}, but doesn't. Possible values: ${collection.print().value}" },122 {123 "Collection should not contain ${value.print().value}, but does. Forbidden values: ${collection.print().value}"124 })125 }126}...
matchers.kt
Source:matchers.kt
...3import io.kotest.matchers.Matcher4import io.kotest.matchers.MatcherResult5import physics2d.core.api.Vec6import physics2d.core.internal.eq7import io.kotest.matchers.collections.beIn as beInMatcher8infix fun <T> Iterable<T>.forEachAssert(match: (T) -> Unit) {9 forEach { cur ->10 withClue("given collection item: $cur"){11 match(cur)12 }13 }14}15fun beDouble(other: Double) = matcher<Double?> {16 MatcherResult(17 this != null && eq(other),18 "$this should be $other",19 "$this is not $other"20 )21}22fun beOrthogonalTo(other: Vec) = matcher<Vec?> {23 MatcherResult(24 this != null && 0.0.eq(x * other.x + y * other.y),25 "$this should be orthogonal to $other",26 "$this is not orthogonal to $other"27 )28}29fun <T> matcher(test: T.() -> MatcherResult) = object : Matcher<T> {30 override fun test(value: T) = test(value)31}32fun <T> beIn(vararg e: T): Matcher<T> = beInMatcher(e.asList())...
beIn
Using AI Code Generation
1val list = listOf(1, 2, 3, 4)2list should beIn(listOf(1, 2, 3, 4, 5))3list shouldNot beIn(listOf(5, 6, 7, 8, 9))4assert(listOf(1, 2, 3, 4) should beIn(listOf(1, 2, 3, 4, 5)))5assert(listOf(1, 2, 3, 4) shouldNot beIn(listOf(5, 6, 7, 8, 9)))6val list = listOf(1, 2, 3, 4)7list should beIn(1, 2, 3, 4, 5)8list shouldNot beIn(5, 6, 7, 8, 9)9assert(listOf(1, 2, 3, 4) should beIn(1, 2, 3, 4, 5))10assert(listOf(1, 2, 3, 4) shouldNot beIn(5, 6, 7, 8, 9))11val list = listOf(1, 2, 3, 4)12list should beIn(1..5)13list shouldNot beIn(5..9)14assert(listOf(1, 2, 3, 4) should beIn(1..5))15assert(listOf(1, 2, 3, 4) shouldNot beIn(5..9))16val list = listOf(1, 2, 3, 4)17list should beIn(1..5)18list shouldNot beIn(5..9)19assert(listOf(1, 2, 3, 4) should beIn(1..5))20assert(listOf(1, 2, 3, 4) shouldNot beIn(5..9))21val list = listOf(1
beIn
Using AI Code Generation
1val list = listOf ( 1 , 2 , 3 , 4 , 5 ) list should beIn ( 1 , 2 , 3 , 4 , 5 ) list should beIn ( 1 , 2 , 3 , 4 , 6 )2val list = listOf ( 1 , 2 , 3 , 4 , 5 ) list should beIn ( 1 , 2 , 3 , 4 , 5 ) list should beIn ( 1 , 2 , 3 , 4 , 6 )3val list = listOf ( 1 , 2 , 3 , 4 , 5 ) list should beIn ( 1 , 2 , 3 , 4 , 5 ) list should beIn ( 1 , 2 , 3 , 4 , 6 )4val list = listOf ( 1 , 2 , 3 , 4 , 5 ) list should beIn ( 1 , 2 , 3 , 4 , 5 ) list should beIn ( 1 , 2 , 3 , 4 , 6 )5val list = listOf ( 1 , 2 , 3 , 4 , 5 ) list should beIn ( 1 , 2 , 3 , 4 , 5 ) list should beIn ( 1 , 2 , 3 , 4 , 6 )6val list = listOf ( 1 , 2 , 3 , 4 , 5 ) list should beIn ( 1 , 2 , 3 , 4 , 5 ) list should beIn ( 1 , 2 , 3 , 4 , 6 )7val list = listOf ( 1 , 2 , 3 , 4 , 5 ) list should beIn
beIn
Using AI Code Generation
1val list = listOf(1, 2, 3, 4, 5)2list should beIn(1, 2, 3, 4, 5)3val list = listOf(1, 2, 3, 4, 5)4list shouldNot beIn(6, 7, 8, 9, 10)5val list = listOf(1, 2, 3, 4, 5)6list shouldNot beIn(1, 2, 3, 4, 5)7val list = listOf(1, 2, 3, 4, 5)8list shouldNot beIn(6, 7, 8, 9, 10)9val list = listOf(1, 2, 3, 4, 5)10list shouldNot beIn(1, 2, 3, 4, 5)11val list = listOf(1, 2, 3, 4, 5)12list shouldNot beIn(6, 7, 8, 9, 10)13val list = listOf(1, 2, 3, 4, 5)14list shouldNot beIn(1, 2, 3, 4, 5)15val list = listOf(1, 2, 3, 4, 5)16list shouldNot beIn(6, 7, 8, 9, 10)
beIn
Using AI Code Generation
1beIn(listOf(1, 2, 3, 4))2beIn(1, 2, 3, 4)3beIn(1..4)4beIn(1 until 5)5beIn(1..4 step 2)6beIn(1..4 step 3)7beIn(listOf(1, 2, 3, 4))8beIn(1, 2, 3, 4)9beIn(1..4)10beIn(1 until 5)11beIn(1..4 step 2)12beIn(1..4 step 3)13beIn(listOf(1, 2, 3, 4))14beIn(1, 2, 3, 4)15beIn(1..4)16beIn(1 until 5)17beIn(1..4 step 2)18beIn(1..4 step 3)19beIn(listOf(1, 2, 3, 4))20beIn(1, 2, 3, 4)21beIn(1..4)22beIn(1 until 5)23beIn(1..4 step 2)24beIn(1..4 step 3)25beIn(listOf(1, 2, 3, 4))26beIn(1, 2, 3, 4)27beIn(1..4)28beIn(1 until 5)29beIn(1..4 step 2)30beIn(1..4 step 3)31beIn(listOf(1, 2, 3, 4))32beIn(1, 2, 3, 4)33beIn(1..4)34beIn(1 until 5)35beIn(1..4 step 2)36beIn(1..4 step 3)
beIn
Using AI Code Generation
1val list = listOf(1,2,3,4,5)2list should beIn(1,2,3)3list should beIn(1,2,3,6)4val list = listOf(1,2,3,4,5)5list should beIn(1,2,3)6list should beIn(1,2,3,6)7val list = listOf(1,2,3,4,5)8list should beIn(1,2,3)9list should beIn(1,2,3,6)10val list = listOf(1,2,3,4,5)11list should beIn(1,2,3)12list should beIn(1,2,3,6)13val list = listOf(1,2,3,4,5)14list should beIn(1,2,3)15list should beIn(1,2,3,6)16val list = listOf(1,2,3,4,5)17list should beIn(1,2,3)18list should beIn(1,2,3,6)19val list = listOf(1,2,3,4,5)20list should beIn(1,2,3)21list should beIn(1,2,3,6)22val list = listOf(1,2,3,4,5)23list should beIn(1,2,3)24list should beIn(1,2,3,6)25val list = listOf(1,2,3,4,5)26list should beIn(1,2,3)27list should beIn(1,2
beIn
Using AI Code Generation
1fun main(args: Array<String>) { val list = listOf(1, 2, 3) list should beIn(listOf(1, 2, 3)) list shouldNot beIn(listOf(4, 5, 6)) }2fun main(args: Array<String>) { val map = mapOf("a" to 1, "b" to 2, "c" to 3) map should beIn(mapOf("a" to 1, "b" to 2, "c" to 3)) map shouldNot beIn(mapOf("d" to 4, "e" to 5, "f" to 6)) }3fun main(args: Array<String>) { val list = listOf("a", "b", "c") list should beIn(listOf("a", "b", "c")) list shouldNot beIn(listOf("d", "e", "f")) }4fun main(args: Array<String>) { val sequence = sequenceOf(1, 2, 3) sequence should beIn(sequenceOf(1, 2, 3)) sequence shouldNot beIn(sequenceOf(4, 5, 6)) }5fun main(args: Array<String>) { 10 should beIn(1..20) 10 shouldNot beIn(11..20) }6fun main(args: Array<String>) { 10L should beIn(1L..20L) 10L shouldNot beIn(11L..20L) }
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!