Best Kotest code snippet using io.kotest.matchers.collections.bein.test
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)...
bein.kt
Source: bein.kt
1package io.kotest.matchers.collections2import io.kotest.assertions.print.print3import io.kotest.matchers.Matcher4import io.kotest.matchers.MatcherResult5import io.kotest.matchers.should6import io.kotest.matchers.shouldNot7import kotlin.jvm.JvmName8/**9 * Verifies that this element is in [collection] by comparing value10 *11 * Assertion to check that this element is in [collection]. This assertion checks by value, and not by reference,12 * therefore even if the exact instance is not in [collection] but another instance with same value is present, the13 * test will pass.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
1package physics2d.core2import io.kotest.assertions.withClue3import 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())...
Check out the latest blogs from LambdaTest on this topic:
Agile software development stems from a philosophy that being agile means creating and responding to change swiftly. Agile means having the ability to adapt and respond to change without dissolving into chaos. Being Agile involves teamwork built on diverse capabilities, skills, and talents. Team members include both the business and software development sides working together to produce working software that meets or exceeds customer expectations continuously.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
Building a website is all about keeping the user experience in mind. Ultimately, it’s about providing visitors with a mind-blowing experience so they’ll keep coming back. One way to ensure visitors have a great time on your site is to add some eye-catching text or image animations.
Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
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!!