How to use Arb.filterIsInstance method of io.kotest.property.arbitrary.filter class

Best Kotest code snippet using io.kotest.property.arbitrary.filter.Arb.filterIsInstance

ValidatedTest.kt

Source:ValidatedTest.kt Github

copy

Full Screen

1package arrow.core2import arrow.core.Either.Left3import arrow.core.Either.Right4import arrow.core.test.UnitSpec5import arrow.typeclasses.Monoid6import arrow.typeclasses.Semigroup7import arrow.core.test.generators.validated8import io.kotest.assertions.fail9import io.kotest.matchers.nulls.shouldBeNull10import io.kotest.property.Arb11import io.kotest.property.checkAll12import io.kotest.matchers.shouldBe13import io.kotest.property.arbitrary.int14import io.kotest.property.arbitrary.long15import io.kotest.property.arbitrary.orNull16import io.kotest.property.arbitrary.string17@Suppress("RedundantSuspendModifier")18class ValidatedTest : UnitSpec() {19 init {20 "fold should call function on Invalid" {21 val exception = Exception("My Exception")22 val result: Validated<Throwable, String> = Invalid(exception)23 result.fold(24 { e -> e.message + " Checked" },25 { fail("Some should not be called") }26 ) shouldBe "My Exception Checked"27 }28 "fold should call function on Valid" {29 val value = "Some value"30 val result: Validated<Throwable, String> = Valid(value)31 result.fold(32 { fail("None should not be called") },33 { a -> "$a processed" }34 ) shouldBe "$value processed"35 }36 "leftMap should modify error" {37 Valid(10).mapLeft { fail("None should not be called") } shouldBe Valid(10)38 Invalid(13).mapLeft { i -> "$i is Coming soon!" } shouldBe Invalid("13 is Coming soon!")39 }40 "exist should return false if is Invalid" {41 Invalid(13).exist { fail("None should not be called") } shouldBe false42 }43 "exist should return the value of predicate if is Valid" {44 Valid(13).exist { v -> v > 10 } shouldBe true45 Valid(13).exist { v -> v < 10 } shouldBe false46 }47 "swap should return Valid(e) if is Invalid and Invalid(v) otherwise" {48 Valid(13).swap() shouldBe Invalid(13)49 Invalid(13).swap() shouldBe Valid(13)50 }51 "getOrElse should return value if is Valid or default otherwise" {52 Valid(13).getOrElse { fail("None should not be called") } shouldBe 1353 Invalid(13).getOrElse { "defaultValue" } shouldBe "defaultValue"54 }55 "orNull should return value if is Valid or null otherwise" {56 Valid(13).orNull() shouldBe 1357 val invalid: Validated<Int, Int> = Invalid(13)58 invalid.orNull() shouldBe null59 }60 "orNone should return value if is Valid or None otherwise" {61 Valid(13).orNone() shouldBe Some(13)62 val invalid: Validated<Int, Int> = Invalid(13)63 invalid.orNone() shouldBe None64 }65 "valueOr should return value if is Valid or the the result of f otherwise" {66 Valid(13).valueOr { fail("None should not be called") } shouldBe 1367 Invalid(13).valueOr { e -> "$e is the defaultValue" } shouldBe "13 is the defaultValue"68 }69 "orElse should return Valid(value) if is Valid or the result of default otherwise" {70 Valid(13).orElse { fail("None should not be called") } shouldBe Valid(13)71 Invalid(13).orElse { Valid("defaultValue") } shouldBe Valid("defaultValue")72 Invalid(13).orElse { Invalid("defaultValue") } shouldBe Invalid("defaultValue")73 }74 "foldLeft should return b when is Invalid" {75 Invalid(13).foldLeft("Coming soon!") { _, _ -> fail("None should not be called") } shouldBe "Coming soon!"76 }77 "foldLeft should return f processed when is Valid" {78 Valid(10).foldLeft("Tennant") { b, a -> "$a is $b" } shouldBe "10 is Tennant"79 }80 "toEither should return Either.Right(value) if is Valid or Either.Left(error) otherwise" {81 Valid(10).toEither() shouldBe Right(10)82 Invalid(13).toEither() shouldBe Left(13)83 }84 "toIor should return Ior.Right(value) if is Valid or Ior.Left(error) otherwise" {85 Valid(10).toIor() shouldBe Ior.Right(10)86 Invalid(13).toIor() shouldBe Ior.Left(13)87 }88 "toOption should return Some(value) if is Valid or None otherwise" {89 Valid(10).toOption() shouldBe Some(10)90 Invalid(13).toOption() shouldBe None91 }92 "toList should return listOf(value) if is Valid or empty list otherwise" {93 Valid(10).toList() shouldBe listOf(10)94 Invalid(13).toList() shouldBe listOf<Int>()95 }96 "toValidatedNel should return Valid(value) if is Valid or Invalid<NonEmptyList<E>, A>(error) otherwise" {97 Valid(10).toValidatedNel() shouldBe Valid(10)98 Invalid(13).toValidatedNel() shouldBe Invalid(NonEmptyList(13, listOf()))99 }100 "findValid should return the first Valid value or combine or Invalid values otherwise" {101 Valid(10).findValid(Semigroup.int()) { fail("None should not be called") } shouldBe Valid(10)102 Invalid(10).findValid(Semigroup.int()) { Valid(5) } shouldBe Valid(5)103 Invalid(10).findValid(Semigroup.int()) { Invalid(5) } shouldBe Invalid(15)104 }105 val nullableLongSemigroup = object : Monoid<Long?> {106 override fun empty(): Long? = 0107 override fun Long?.combine(b: Long?): Long? =108 Nullable.zip(this@combine, b) { a, bb -> a + bb }109 }110 "zip identity" {111 checkAll(Arb.validated(Arb.long().orNull(), Arb.int().orNull())) { validated ->112 val res = validated.zip(nullableLongSemigroup, Valid(Unit)) { a, _ -> a }113 res shouldBe validated114 }115 }116 "tap applies effects returning the original value" {117 checkAll(Arb.validated(Arb.long(), Arb.int())) { validated ->118 var effect = 0119 val res = validated.tap { effect += 1 }120 val expected = when (validated) {121 is Validated.Valid -> 1122 is Validated.Invalid -> 0123 }124 effect shouldBe expected125 res shouldBe validated126 }127 }128 "tapInvalid applies effects returning the original value" {129 checkAll(Arb.validated(Arb.long(), Arb.int())) { validated ->130 var effect = 0131 val res = validated.tapInvalid { effect += 1 }132 val expected = when (validated) {133 is Validated.Valid -> 0134 is Validated.Invalid -> 1135 }136 effect shouldBe expected137 res shouldBe validated138 }139 }140 "zip is derived from flatMap" {141 checkAll(142 Arb.validated(Arb.long().orNull(), Arb.int().orNull()),143 Arb.validated(Arb.long().orNull(), Arb.int().orNull()),144 Arb.validated(Arb.long().orNull(), Arb.int().orNull()),145 Arb.validated(Arb.long().orNull(), Arb.int().orNull()),146 Arb.validated(Arb.long().orNull(), Arb.int().orNull()),147 Arb.validated(Arb.long().orNull(), Arb.int().orNull()),148 Arb.validated(Arb.long().orNull(), Arb.int().orNull()),149 Arb.validated(Arb.long().orNull(), Arb.int().orNull()),150 Arb.validated(Arb.long().orNull(), Arb.int().orNull()),151 Arb.validated(Arb.long().orNull(), Arb.int().orNull())152 ) { a, b, c, d, e, f, g, h, i, j ->153 val res = a.zip(154 nullableLongSemigroup,155 b, c, d, e, f, g, h, i, j156 ) { a, b, c, d, e, f, g, h, i, j ->157 Nullable.zip(158 a,159 b,160 c,161 d,162 e,163 f,164 g,165 h,166 i,167 j168 ) { a, b, c, d, e, f, g, h, i, j -> a + b + c + d + e + f + g + h + i + j }169 }170 val all = listOf(a, b, c, d, e, f, g, h, i, j)171 val isValid = all.all { it.isValid }172 val expected: Validated<Long?, Int?> =173 if (isValid) Valid(all.fold<Validated<Long?, Int?>, Int?>(0) { acc, validated ->174 Nullable.zip(175 acc,176 validated.orNull()177 ) { a, b -> a + b }178 })179 else Invalid(180 all.filterIsInstance<Invalid<Long?>>().map { it.value }.combineAll(nullableLongSemigroup)181 )182 res shouldBe expected183 }184 }185 "zip should return Valid(f(a)) if both are Valid" {186 Valid(10).zip(Semigroup.int(), Valid { a: Int -> a + 5 }) { a, ff -> ff(a) } shouldBe Valid(15)187 }188 "zip should return first Invalid found if is unique or combine both otherwise" {189 Invalid(10).zip(Semigroup.int(), Valid { a: Int -> a + 5 }) { a, ff -> ff(a) } shouldBe Invalid(10)190 Valid(10).zip<Int, Int, (Int) -> Int, Int>(Semigroup.int(), Invalid(5)) { a, ff -> ff(a) } shouldBe Invalid(5)191 Invalid(10).zip<Int, Int, (Int) -> Int, Int>(Semigroup.int(), Invalid(5)) { a, ff -> ff(a) } shouldBe Invalid(15)192 }193 data class MyException(val msg: String) : Exception()194 "fromEither should return Valid if is Either.Right or Failure otherwise" {195 Validated.fromEither(Right(10)) shouldBe Valid(10)196 Validated.fromEither(Left(10)) shouldBe Invalid(10)197 }198 "fromOption should return Valid if is Some or Invalid otherwise" {199 Validated.fromOption<Int, Int>(Some(10)) { fail("should not be called") } shouldBe Valid(10)200 Validated.fromOption<Int, Int>(None) { 5 } shouldBe Invalid(5)201 }202 "fromNullable should return Valid if is not-null or Invalid otherwise" {203 Validated.fromNullable<Int, Int>(10) { fail("should not be called") } shouldBe Valid(10)204 Validated.fromNullable<Int, Int>(null) { 5 } shouldBe Invalid(5)205 }206 "invalidNel<E> should return a Invalid<NonEmptyList<E>>" {207 Validated.invalidNel<Int, Int>(10) shouldBe Invalid(NonEmptyList(10, listOf()))208 }209 "withEither should return Valid(result) if f return Right" {210 Valid(10).withEither { it.map { it + 5 } } shouldBe Valid(15)211 Invalid(10).withEither { Right(5) } shouldBe Valid(5)212 }213 "withEither should return Invalid(result) if f return Left" {214 Valid(10).withEither { Left(5) } shouldBe Invalid(5)215 Invalid(10).withEither(::identity) shouldBe Invalid(10)216 }217 "catch should return Valid(result) when f does not throw" {218 suspend fun loadFromNetwork(): Int = 1219 Validated.catch { loadFromNetwork() } shouldBe Valid(1)220 }221 "catch should return Invalid(result) when f throws" {222 val exception = MyException("Boom!")223 suspend fun loadFromNetwork(): Int = throw exception224 Validated.catch { loadFromNetwork() } shouldBe Invalid(exception)225 }226 "catchNel should return Valid(result) when f does not throw" {227 suspend fun loadFromNetwork(): Int = 1228 Validated.catchNel { loadFromNetwork() } shouldBe Valid(1)229 }230 "catchNel should return Invalid(Nel(result)) when f throws" {231 val exception = MyException("Boom!")232 suspend fun loadFromNetwork(): Int = throw exception233 Validated.catchNel { loadFromNetwork() } shouldBe Invalid(nonEmptyListOf(exception))234 }235 "Cartesian builder should build products over homogeneous Validated" {236 Valid("11th").zip(237 Semigroup.string(),238 Valid("Doctor"),239 Valid("Who")240 ) { a, b, c -> "$a $b $c" } shouldBe Valid("11th Doctor Who")241 }242 "Cartesian builder should build products over heterogeneous Validated" {243 Valid(13).zip(244 Semigroup.string(),245 Valid("Doctor"),246 Valid(false)247 ) { a, b, c -> "${a}th $b is $c" } shouldBe Valid("13th Doctor is false")248 }249 "Cartesian builder should build products over Invalid Validated" {250 Invalid("fail1").zip(251 Semigroup.string(),252 Invalid("fail2"),253 Valid("Who")254 ) { _, _, _ -> "success!" } shouldBe Invalid("fail1fail2")255 }256 "Cartesian builder for nel doesn't need semigroup parameter" {257 "fail1".invalidNel().zip(258 "fail2".invalidNel()259 ) { _, _ -> "success!" } shouldBe Invalid(nonEmptyListOf("fail1", "fail2"))260 }261 "CombineK should combine Valid Validated" {262 val valid = Valid("Who")263 valid.combineK(Semigroup.string(), valid) shouldBe (Valid("Who"))264 }265 "CombineK should combine Valid and Invalid Validated" {266 val valid = Valid("Who")267 val invalid = Invalid("Nope")268 valid.combineK(Semigroup.string(), invalid) shouldBe (Valid("Who"))269 }270 "CombineK should combine Invalid Validated" {271 val invalid = Invalid("Nope")272 invalid.combineK(Semigroup.string(), invalid) shouldBe (Invalid("NopeNope"))273 }274 "Combine should combine Valid Validated" {275 val valid: Validated<String, String> = Valid("Who")276 valid.combine(Monoid.string(), Monoid.string(), valid) shouldBe (Valid("WhoWho"))277 }278 "Combine should combine Valid and Invalid Validated" {279 val valid = Valid("Who")280 val invalid = Invalid("Nope")281 valid.combine(Monoid.string(), Monoid.string(), invalid) shouldBe (Invalid("Nope"))282 }283 "Combine should combine Invalid Validated" {284 val invalid: Validated<String, String> = Invalid("Nope")285 invalid.combine(Monoid.string(), Monoid.string(), invalid) shouldBe (Invalid("NopeNope"))286 }287 "traverse should yield list when validated is valid" {288 val valid = Valid("Who")289 val invalid = Invalid("Nope")290 valid.traverse { listOf(it) } shouldBe listOf(Valid("Who"))291 invalid.traverse { listOf(it) } shouldBe emptyList()292 }293 "sequence should yield consistent result with traverse" {294 checkAll(Arb.string(), Arb.string()) { a: String, b: String ->295 val valid = Valid(a)296 val invalid = Invalid(b)297 valid.traverse { listOf(it) } shouldBe valid.map { listOf(it) }.sequence()298 invalid.traverse { listOf(it) } shouldBe invalid.map { listOf(it) }.sequence()299 }300 }301 "traverseOption should yield option when validated is valid" {302 val valid = Valid("Who")303 val invalid = Invalid("Nope")304 valid.traverseOption { Some(it) } shouldBe Some(Valid("Who"))305 invalid.traverseOption { Some(it) } shouldBe None306 }307 "sequenceOption should yield consistent result with traverseOption" {308 checkAll(Arb.string(), Arb.string()) { a: String, b: String ->309 val valid = Valid(a)310 val invalid = Invalid(b)311 valid.traverseOption { Some(it) } shouldBe valid.map { Some(it) }.sequenceOption()312 invalid.traverseOption { Some(it) } shouldBe invalid.map { Some(it) }.sequenceOption()313 }314 }315 "traverseNullable should yield non-null object when validated is valid" {316 val valid = Valid("Who")317 val invalid = Invalid("Nope")318 valid.traverseNullable<String?> { it } shouldBe Valid("Who")319 valid.traverseNullable<String?> { null }.shouldBeNull()320 invalid.traverseNullable<String?> { it }.shouldBeNull()321 }322 "sequenceNullable should yield consistent result with traverseNullable" {323 checkAll(Arb.string(), Arb.string()) { a: String, b: String ->324 val valid = Valid(a)325 val invalid = Invalid(b)326 valid.traverseNullable<String?> { it } shouldBe valid.map<String?> { it }.sequenceNullable()327 valid.traverseNullable<String?> { null } shouldBe valid.map<String?> { null }.sequenceNullable()328 invalid.traverseNullable<String?> { it } shouldBe invalid.map<String?> { it }.sequenceNullable()329 }330 }331 "traverseEither should wrap validated in either" {332 val valid = Valid("Who")333 val invalid = Invalid("Nope")334 valid.traverseEither { it.right() } shouldBe Valid("Who").right()335 invalid.traverseEither { it.right() } shouldBe Invalid("Nope").right()336 }337 "sequenceEither should yield consistent result with traverseEither" {338 checkAll(Arb.string(), Arb.string()) { a: String, b: String ->339 val valid = Valid(a)340 val invalid = Invalid(b)341 valid.traverseEither { Right(it) } shouldBe valid.map { Right(it) }.sequenceEither()342 invalid.traverseEither { Right(it) } shouldBe invalid.map { Right(it) }.sequenceEither()343 }344 }345 "bitraverse should wrap valid or invalid in a list" {346 val valid = Valid("Who")347 val invalid = Invalid("Nope")348 valid.bitraverse({ listOf(it) }, { listOf(it) }) shouldBe listOf(Valid("Who"))349 invalid.bitraverse({ listOf(it) }, { listOf(it) }) shouldBe listOf(Invalid("Nope"))350 }351 "bisequence should yield consistent result with bitraverse" {352 checkAll(Arb.string(), Arb.string()) { a: String, b: String ->353 val valid: Validated<String, String> = Valid(a)354 val invalid: Validated<String, String> = Invalid(b)355 valid.bimap({ listOf(it) }, { listOf(it) }).bisequence() shouldBe valid.bitraverse(356 { listOf(it) },357 { listOf(it) })358 invalid.bimap({ listOf(it) }, { listOf(it) }).bisequence() shouldBe invalid.bitraverse(359 { listOf(it) },360 { listOf(it) })361 }362 }363 "bitraverseOption should wrap valid or invalid in an option" {364 val valid = Valid("Who")365 val invalid = Invalid("Nope")366 valid.bitraverseOption({ Some(it) }, { Some(it) }) shouldBe Some(Valid("Who"))367 invalid.bitraverseOption({ Some(it) }, { Some(it) }) shouldBe Some(Invalid("Nope"))368 }369 "bisequenceOption should yield consistent result with bitraverseOption" {370 checkAll(Arb.string(), Arb.string()) { a: String, b: String ->371 val valid: Validated<String, String> = Valid(a)372 val invalid: Validated<String, String> = Invalid(b)373 valid.bimap({ Some(it) }, { Some(it) }).bisequenceOption() shouldBe374 valid.bitraverseOption({ Some(it) }, { Some(it) })375 invalid.bimap({ Some(it) }, { Some(it) }).bisequenceOption() shouldBe376 invalid.bitraverseOption({ Some(it) }, { Some(it) })377 }378 }379 "bitraverseNullable should wrap valid or invalid in a nullable" {380 val valid = Valid("Who")381 val invalid = Invalid("Nope")382 valid.bitraverseNullable({ it }, { it }) shouldBe Valid("Who")383 invalid.bitraverseNullable({ it }, { it }) shouldBe Invalid("Nope")384 }385 "bisequenceOption should yield consistent result with bitraverseOption" {386 checkAll(Arb.string().orNull(), Arb.string().orNull()) { a: String?, b: String? ->387 val valid: Validated<String?, String?> = Valid(a)388 val invalid: Validated<String?, String?> = Invalid(b)389 valid.bimap({ it }, { it }).bisequenceNullable() shouldBe390 valid.bitraverseNullable({ it }, { it })391 invalid.bimap({ it }, { it }).bisequenceNullable() shouldBe392 invalid.bitraverseNullable({ it }, { it })393 }394 }395 "bitraverseEither should wrap valid or invalid in an either" {396 val valid = Valid("Who")397 val invalid = Invalid("Nope")398 valid.bitraverseEither({ it.left() }, { it.right() }) shouldBe Valid("Who").right()399 invalid.bitraverseEither({ it.left() }, { it.right() }) shouldBe "Nope".left()400 }401 "bisequenceEither should yield consistent result with bitraverseEither" {402 checkAll(Arb.string(), Arb.string()) { a: String, b: String ->403 val valid: Validated<String, String> = Valid(a)404 val invalid: Validated<String, String> = Invalid(b)405 valid.bimap({ it.left() }, { it.right() }).bisequenceEither() shouldBe406 valid.bitraverseEither({ it.left() }, { it.right() })407 invalid.bimap({ it.left() }, { it.right() }).bisequenceEither() shouldBe408 invalid.bitraverseEither({ it.left() }, { it.right() })409 }410 }411 "andThen should return Valid(result) if f return Valid" {412 checkAll(Arb.int(), Arb.int()) { x, y ->413 Valid(x).andThen { Valid(it + y) } shouldBe Valid(x + y)414 }415 }416 "andThen should only run f on valid instances " {417 checkAll(Arb.int(), Arb.int()) { x, y ->418 Invalid(x).andThen { Valid(y) } shouldBe Invalid(x)419 }420 }421 "andThen should return Invalid(result) if f return Invalid " {422 checkAll(Arb.int(), Arb.int()) { x, y ->423 Valid(x).andThen { Invalid(it + y) } shouldBe Invalid(x + y)424 }425 }426 }427}...

Full Screen

Full Screen

OptionTest.kt

Source:OptionTest.kt Github

copy

Full Screen

1package arrow.core2import arrow.core.computations.OptionEffect3import arrow.core.computations.RestrictedOptionEffect4import arrow.core.computations.ensureNotNull5import arrow.core.computations.option6import arrow.core.test.UnitSpec7import arrow.core.test.generators.option8import arrow.core.test.laws.FxLaws9import arrow.core.test.laws.MonoidLaws10import arrow.typeclasses.Monoid11import io.kotest.matchers.shouldBe12import io.kotest.matchers.shouldNotBe13import io.kotest.property.Arb14import io.kotest.property.arbitrary.boolean15import io.kotest.property.arbitrary.int16import io.kotest.property.arbitrary.long17import io.kotest.property.arbitrary.map18import io.kotest.property.arbitrary.orNull19import io.kotest.property.arbitrary.string20import io.kotest.property.checkAll21class OptionTest : UnitSpec() {22 val some: Option<String> = Some("kotlin")23 val none: Option<String> = None24 init {25 testLaws(26 MonoidLaws.laws(Monoid.option(Monoid.int()), Arb.option(Arb.int())),27 FxLaws.suspended<OptionEffect<*>, Option<String>, String>(28 Arb.string().map(Option.Companion::invoke),29 Arb.option(Arb.string()),30 Option<String>::equals,31 option::invoke32 ) {33 it.bind()34 },35 FxLaws.eager<RestrictedOptionEffect<*>, Option<String>, String>(36 Arb.string().map(Option.Companion::invoke),37 Arb.option(Arb.string()),38 Option<String>::equals,39 option::eager40 ) {41 it.bind()42 }43 )44 "ensure null in option computation" {45 checkAll(Arb.boolean(), Arb.int()) { predicate, i ->46 option {47 ensure(predicate)48 i49 } shouldBe if (predicate) Some(i) else None50 }51 }52 "ensureNotNull in option computation" {53 fun square(i: Int): Int = i * i54 checkAll(Arb.int().orNull()) { i: Int? ->55 option {56 val ii = i57 ensureNotNull(ii)58 square(ii) // Smart-cast by contract59 } shouldBe i.toOption().map(::square)60 }61 }62 "short circuit null" {63 option {64 val number: Int = "s".length65 val x = ensureNotNull(number.takeIf { it > 1 })66 x67 throw IllegalStateException("This should not be executed")68 } shouldBe None69 }70 "tap applies effects returning the original value" {71 checkAll(Arb.option(Arb.long())) { option ->72 var effect = 073 val res = option.tap { effect += 1 }74 val expected = when (option) {75 is Some -> 176 is None -> 077 }78 effect shouldBe expected79 res shouldBe option80 }81 }82 "tapNone applies effects returning the original value" {83 checkAll(Arb.option(Arb.long())) { option ->84 var effect = 085 val res = option.tapNone { effect += 1 }86 val expected = when (option) {87 is Some -> 088 is None -> 189 }90 effect shouldBe expected91 res shouldBe option92 }93 }94 "fromNullable should work for both null and non-null values of nullable types" {95 checkAll(Arb.int().orNull()) { a: Int? ->96 // This seems to be generating only non-null values, so it is complemented by the next test97 val o: Option<Int> = Option.fromNullable(a)98 if (a == null) o shouldBe None else o shouldBe Some(a)99 }100 }101 "fromNullable should return none for null values of nullable types" {102 val a: Int? = null103 Option.fromNullable(a) shouldBe None104 }105 "getOrElse" {106 some.getOrElse { "java" } shouldBe "kotlin"107 none.getOrElse { "java" } shouldBe "java"108 }109 "orNull" {110 some.orNull() shouldNotBe null111 none.orNull() shouldBe null112 }113 "map" {114 some.map(String::toUpperCase) shouldBe Some("KOTLIN")115 none.map(String::toUpperCase) shouldBe None116 }117 "zip" {118 checkAll(Arb.int()) { a: Int ->119 val op: Option<Int> = a.some()120 some.zip(op) { a, b -> a + b } shouldBe Some("kotlin$a")121 none.zip(op) { a, b -> a + b } shouldBe None122 some.zip(op) shouldBe Some(Pair("kotlin", a))123 }124 }125 "mapNotNull" {126 some.mapNotNull { it.toIntOrNull() } shouldBe None127 some.mapNotNull { it.toUpperCase() } shouldBe Some("KOTLIN")128 }129 "fold" {130 some.fold({ 0 }) { it.length } shouldBe 6131 none.fold({ 0 }) { it.length } shouldBe 0132 }133 "flatMap" {134 some.flatMap { Some(it.toUpperCase()) } shouldBe Some("KOTLIN")135 none.flatMap { Some(it.toUpperCase()) } shouldBe None136 }137 "align" {138 some align some shouldBe Some(Ior.Both("kotlin", "kotlin"))139 some align none shouldBe Some(Ior.Left("kotlin"))140 none align some shouldBe Some(Ior.Right("kotlin"))141 none align none shouldBe None142 some.align(some) { "$it" } shouldBe Some("Ior.Both(kotlin, kotlin)")143 some.align(none) { "$it" } shouldBe Some("Ior.Left(kotlin)")144 none.align(some) { "$it" } shouldBe Some("Ior.Right(kotlin)")145 none.align(none) { "$it" } shouldBe None146 val nullable = null.some()147 some align nullable shouldBe Some(Ior.Both("kotlin", null))148 nullable align some shouldBe Some(Ior.Both(null, "kotlin"))149 nullable align nullable shouldBe Some(Ior.Both(null, null))150 some.align(nullable) { "$it" } shouldBe Some("Ior.Both(kotlin, null)")151 nullable.align(some) { "$it" } shouldBe Some("Ior.Both(null, kotlin)")152 nullable.align(nullable) { "$it" } shouldBe Some("Ior.Both(null, null)")153 }154 "filter" {155 some.filter { it == "java" } shouldBe None156 none.filter { it == "java" } shouldBe None157 some.filter { it.startsWith('k') } shouldBe Some("kotlin")158 }159 "filterNot" {160 some.filterNot { it == "java" } shouldBe Some("kotlin")161 none.filterNot { it == "java" } shouldBe None162 some.filterNot { it.startsWith('k') } shouldBe None163 }164 "filterIsInstance" {165 val someAny: Option<Any> = some166 someAny.filterIsInstance<String>() shouldBe Some("kotlin")167 someAny.filterIsInstance<Int>() shouldBe None168 val someNullableAny: Option<Any?> = null.some()169 someNullableAny.filterIsInstance<String?>() shouldBe Some(null)170 someNullableAny.filterIsInstance<String>() shouldBe None171 val noneAny: Option<Any> = none172 noneAny.filterIsInstance<String>() shouldBe None173 noneAny.filterIsInstance<Int>() shouldBe None174 }175 "exists" {176 some.exists { it.startsWith('k') } shouldBe true177 some.exists { it.startsWith('j') } shouldBe false178 none.exists { it.startsWith('k') } shouldBe false179 }180 "all" {181 some.all { it.startsWith('k') } shouldBe true182 some.all { it.startsWith('j') } shouldBe false183 none.all { it.startsWith('k') } shouldBe true184 }185 "orElse" {186 some.orElse { Some("java") } shouldBe Some("kotlin")187 none.orElse { Some("java") } shouldBe Some("java")188 }189 "toList" {190 some.toList() shouldBe listOf("kotlin")191 none.toList() shouldBe listOf()192 }193 "Iterable.firstOrNone" {194 val iterable = iterableOf(1, 2, 3, 4, 5, 6)195 iterable.firstOrNone() shouldBe Some(1)196 iterable.firstOrNone { it > 2 } shouldBe Some(3)197 iterable.firstOrNone { it > 7 } shouldBe None198 val emptyIterable = iterableOf<Int>()199 emptyIterable.firstOrNone() shouldBe None200 val nullableIterable1 = iterableOf(null, 2, 3, 4, 5, 6)201 nullableIterable1.firstOrNone() shouldBe Some(null)202 val nullableIterable2 = iterableOf(1, 2, 3, null, 5, null)203 nullableIterable2.firstOrNone { it == null } shouldBe Some(null)204 }205 "Collection.firstOrNone" {206 val list = listOf(1, 2, 3, 4, 5, 6)207 list.firstOrNone() shouldBe Some(1)208 val emptyList = emptyList<Int>()209 emptyList.firstOrNone() shouldBe None210 val nullableList = listOf(null, 2, 3, 4, 5, 6)211 nullableList.firstOrNone() shouldBe Some(null)212 }213 "Iterable.singleOrNone" {214 val iterable = iterableOf(1, 2, 3, 4, 5, 6)215 iterable.singleOrNone() shouldBe None216 iterable.singleOrNone { it > 2 } shouldBe None217 val singleIterable = iterableOf(3)218 singleIterable.singleOrNone() shouldBe Some(3)219 singleIterable.singleOrNone { it == 3 } shouldBe Some(3)220 val nullableSingleIterable1 = iterableOf<Int?>(null)221 nullableSingleIterable1.singleOrNone() shouldBe Some(null)222 val nullableSingleIterable2 = iterableOf(1, 2, 3, null, 5, 6)223 nullableSingleIterable2.singleOrNone { it == null } shouldBe Some(null)224 val nullableSingleIterable3 = iterableOf(1, 2, 3, null, 5, null)225 nullableSingleIterable3.singleOrNone { it == null } shouldBe None226 }227 "Collection.singleOrNone" {228 val list = listOf(1, 2, 3, 4, 5, 6)229 list.singleOrNone() shouldBe None230 val singleList = listOf(3)231 singleList.singleOrNone() shouldBe Some(3)232 val nullableSingleList = listOf(null)233 nullableSingleList.singleOrNone() shouldBe Some(null)234 }235 "Iterable.lastOrNone" {236 val iterable = iterableOf(1, 2, 3, 4, 5, 6)237 iterable.lastOrNone() shouldBe Some(6)238 iterable.lastOrNone { it < 4 } shouldBe Some(3)239 iterable.lastOrNone { it > 7 } shouldBe None240 val emptyIterable = iterableOf<Int>()241 emptyIterable.lastOrNone() shouldBe None242 val nullableIterable1 = iterableOf(1, 2, 3, 4, 5, null)243 nullableIterable1.lastOrNone() shouldBe Some(null)244 val nullableIterable2 = iterableOf(null, 2, 3, null, 5, 6)245 nullableIterable2.lastOrNone { it == null } shouldBe Some(null)246 }247 "Collection.lastOrNone" {248 val list = listOf(1, 2, 3, 4, 5, 6)249 list.lastOrNone() shouldBe Some(6)250 val emptyList = emptyList<Int>()251 emptyList.lastOrNone() shouldBe None252 val nullableList = listOf(1, 2, 3, 4, 5, null)253 nullableList.lastOrNone() shouldBe Some(null)254 }255 "Iterable.elementAtOrNone" {256 val iterable = iterableOf(1, 2, 3, 4, 5, 6)257 iterable.elementAtOrNone(index = 3 - 1) shouldBe Some(3)258 iterable.elementAtOrNone(index = -1) shouldBe None259 iterable.elementAtOrNone(index = 100) shouldBe None260 val nullableIterable = iterableOf(1, 2, null, 4, 5, 6)261 nullableIterable.elementAtOrNone(index = 3 - 1) shouldBe Some(null)262 }263 "Collection.elementAtOrNone" {264 val list = listOf(1, 2, 3, 4, 5, 6)265 list.elementAtOrNone(index = 3 - 1) shouldBe Some(3)266 list.elementAtOrNone(index = -1) shouldBe None267 list.elementAtOrNone(index = 100) shouldBe None268 val nullableList = listOf(1, 2, null, 4, 5, 6)269 nullableList.elementAtOrNone(index = 3 - 1) shouldBe Some(null)270 }271 "and" {272 val x = Some(2)273 val y = Some("Foo")274 x and y shouldBe Some("Foo")275 x and None shouldBe None276 None and x shouldBe None277 None and None shouldBe None278 }279 "or" {280 val x = Some(2)281 val y = Some(100)282 x or y shouldBe Some(2)283 x or None shouldBe Some(2)284 None or x shouldBe Some(2)285 None or None shouldBe None286 }287 "toLeftOption" {288 1.leftIor().leftOrNull() shouldBe 1289 2.rightIor().leftOrNull() shouldBe null290 (1 to 2).bothIor().leftOrNull() shouldBe 1291 }292 "pairLeft" {293 val some: Option<Int> = Some(2)294 val none: Option<Int> = None295 some.pairLeft("key") shouldBe Some("key" to 2)296 none.pairLeft("key") shouldBe None297 }298 "pairRight" {299 val some: Option<Int> = Some(2)300 val none: Option<Int> = None301 some.pairRight("right") shouldBe Some(2 to "right")302 none.pairRight("right") shouldBe None303 }304 "Option<Pair<L, R>>.toMap()" {305 val some: Option<Pair<String, String>> = Some("key" to "value")306 val none: Option<Pair<String, String>> = None307 some.toMap() shouldBe mapOf("key" to "value")308 none.toMap() shouldBe emptyMap()309 }310 "traverse should yield list of option" {311 val some: Option<String> = Some("value")312 val none: Option<String> = None313 some.traverse { listOf(it) } shouldBe listOf(Some("value"))314 none.traverse { listOf(it) } shouldBe emptyList()315 }316 "sequence should be consistent with traverse" {317 checkAll(Arb.option(Arb.int())) { option ->318 option.map { listOf(it) }.sequence() shouldBe option.traverse { listOf(it) }319 }320 }321 "traverseEither should yield either of option" {322 val some: Option<String> = Some("value")323 val none: Option<String> = None324 some.traverseEither { it.right() } shouldBe some.right()325 none.traverseEither { it.right() } shouldBe none.right()326 }327 "sequenceEither should be consistent with traverseEither" {328 checkAll(Arb.option(Arb.int())) { option ->329 option.map { it.right() }.sequenceEither() shouldBe option.traverseEither { it.right() }330 }331 }332 "traverseValidated should yield validated of option" {333 val some: Option<String> = Some("value")334 val none: Option<String> = None335 some.traverseValidated { it.valid() } shouldBe some.valid()336 none.traverseValidated { it.valid() } shouldBe none.valid()337 }338 "sequenceValidated should be consistent with traverseValidated" {339 checkAll(Arb.option(Arb.int())) { option ->340 option.map { it.valid() }.sequenceValidated() shouldBe option.traverseValidated { it.valid() }341 }342 }343 "catch should return Some(result) when f does not throw" {344 val recover: (Throwable) -> Option<Int> = { _ -> None}345 Option.catch(recover) { 1 } shouldBe Some(1)346 }347 "catch should return Some(recoverValue) when f throws" {348 val exception = Exception("Boom!")349 val recoverValue = 10350 val recover: (Throwable) -> Option<Int> = { _ -> Some(recoverValue) }351 Option.catch(recover) { throw exception } shouldBe Some(recoverValue)352 }353 "catch should return Some(result) when f does not throw" {354 Option.catch { 1 } shouldBe Some(1)355 }356 "catch should return None when f throws" {357 val exception = Exception("Boom!")358 Option.catch { throw exception } shouldBe None359 }360 }361}362// Utils363private fun <T> iterableOf(vararg elements: T): Iterable<T> = Iterable { iterator { yieldAll(elements.toList()) } }...

Full Screen

Full Screen

EngineTest.kt

Source:EngineTest.kt Github

copy

Full Screen

1package no.ks.kes.test.example2import io.kotest.assertions.asClue3import io.kotest.assertions.fail4import io.kotest.assertions.failure5import io.kotest.assertions.throwables.shouldThrowExactly6import io.kotest.assertions.timing.eventually7import io.kotest.core.spec.style.StringSpec8import io.kotest.matchers.collections.beEmpty9import io.kotest.matchers.collections.shouldContain10import io.kotest.matchers.collections.shouldHaveAtLeastSize11import io.kotest.matchers.collections.shouldHaveSize12import io.kotest.matchers.should13import io.kotest.matchers.shouldBe14import io.kotest.matchers.throwable.shouldHaveMessage15import io.kotest.property.Arb16import io.kotest.property.arbitrary.UUIDVersion17import io.kotest.property.arbitrary.uuid18import io.kotest.property.checkAll19import kotlinx.coroutines.asCoroutineDispatcher20import kotlinx.coroutines.async21import kotlinx.coroutines.awaitAll22import no.ks.kes.lib.Projections23import no.ks.kes.lib.Sagas24import no.ks.kes.test.AggregateKey25import no.ks.kes.test.withKes26import java.util.*27import java.util.concurrent.Executors28import kotlin.time.*29@ExperimentalTime30class EngineTest : StringSpec({31 "Test command handler" {32 withKes(eventSerdes = Events.serdes, cmdSerdes = Cmds.serdes) { kes ->33 val engineCmdHandler = EngineCmdHandler(kes.aggregateRepository)34 val aggregateId = UUID.randomUUID()35 engineCmdHandler.handle(Cmds.Create(aggregateId)).asClue {36 it.id shouldBe aggregateId37 it.running shouldBe false38 it.startCount shouldBe 039 }40 eventually(3.toDuration(DurationUnit.SECONDS)) {41 kes.eventStream.get(AggregateKey(ENGINE_AGGREGATE_TYPE, aggregateId))?.asClue { events ->42 events shouldHaveSize 143 events[0].eventData::class.java shouldBe Events.Created::class.java44 } ?: fail("No events was found for aggregate")45 }46 }47 }48 "Test command handler using several threads" {49 withKes(eventSerdes = Events.serdes, cmdSerdes = Cmds.serdes) { kes ->50 val engineCmdHandler = EngineCmdHandler(kes.aggregateRepository)51 val aggregateId = UUID.randomUUID()52 engineCmdHandler.handle(Cmds.Create(aggregateId)).asClue {53 it.id shouldBe aggregateId54 it.running shouldBe false55 it.startCount shouldBe 056 }57 eventually(3.toDuration(DurationUnit.SECONDS)) {58 kes.eventStream.get(AggregateKey(ENGINE_AGGREGATE_TYPE, aggregateId))?.asClue { events ->59 events shouldHaveSize 160 events[0].eventData::class.java shouldBe Events.Created::class.java61 } ?: fail("No events was found for aggregate")62 }63 Executors.newFixedThreadPool(10).asCoroutineDispatcher().use { dispatcher ->64 awaitAll(65 async(dispatcher) { engineCmdHandler.handleUnsynchronized(Cmds.Start(aggregateId)) },66 async(dispatcher) { engineCmdHandler.handleUnsynchronized(Cmds.Start(aggregateId)) },67 async(dispatcher) { engineCmdHandler.handleUnsynchronized(Cmds.Start(aggregateId)) },68 async(dispatcher) { engineCmdHandler.handleUnsynchronized(Cmds.Start(aggregateId)) },69 async(dispatcher) { engineCmdHandler.handleUnsynchronized(Cmds.Start(aggregateId)) },70 async(dispatcher) { engineCmdHandler.handleUnsynchronized(Cmds.Start(aggregateId)) },71 async(dispatcher) { engineCmdHandler.handleUnsynchronized(Cmds.Start(aggregateId)) },72 async(dispatcher) { engineCmdHandler.handleUnsynchronized(Cmds.Start(aggregateId)) },73 async(dispatcher) { engineCmdHandler.handleUnsynchronized(Cmds.Start(aggregateId)) },74 async(dispatcher) { engineCmdHandler.handleUnsynchronized(Cmds.Start(aggregateId)) }75 )76 }77 eventually(3.toDuration(DurationUnit.SECONDS)) {78 kes.eventStream.get(AggregateKey(ENGINE_AGGREGATE_TYPE, aggregateId))?.asClue { writeEventWrappers ->79 writeEventWrappers shouldHaveAtLeastSize 280 val events = writeEventWrappers.map { it.eventData }.toList()81 events.filterIsInstance<Events.Created>() shouldHaveSize 182 // At this point we really don't know how many of these events was applied as EngineCmdHandler checks aggregate state before generating Started events83 // As we are using the handleUnsynchronized function we can therefore not guarantee how many started events are generated84 events.filterIsInstance<Events.Started>() shouldHaveAtLeastSize 185 } ?: fail("No events was found for aggregate")86 }87 }88 }89 "Test command handler by providing event and command types explicitly" {90 withKes(events = Events.all, cmds = Cmds.all) { kes ->91 val engineCmdHandler = EngineCmdHandler(kes.aggregateRepository)92 val aggregateId = UUID.randomUUID()93 engineCmdHandler.handle(Cmds.Create(aggregateId)).asClue {94 it.id shouldBe aggregateId95 it.running shouldBe false96 it.startCount shouldBe 097 }98 eventually(3.toDuration(DurationUnit.SECONDS)) {99 kes.eventStream.get(AggregateKey(ENGINE_AGGREGATE_TYPE, aggregateId))?.asClue { events ->100 events shouldHaveSize 1101 events[0].eventData::class.java shouldBe Events.Created::class.java102 } ?: fail("No events was found for aggregate")103 }104 }105 }106 "Test saga with timeout" {107 withKes(Events.serdes, Cmds.serdes) { kes ->108 val engineCmdHandler = EngineCmdHandler(kes.aggregateRepository)109 val commandQueue = kes.createCommandQueue(setOf(engineCmdHandler))110 Sagas.initialize(111 eventSubscriberFactory = kes.subscriberFactory,112 sagaRepository = kes.createSagaRepository(commandQueue),113 sagas = setOf(EngineSaga),114 commandQueue = commandQueue,115 pollInterval = 1.seconds.toLongMilliseconds()116 ) {117 e -> failure("Failed to handle saga event", e)118 }119 val aggregateId = UUID.randomUUID()120 engineCmdHandler.handle(Cmds.Create(aggregateId)).asClue {121 it.id shouldBe aggregateId122 it.running shouldBe false123 it.startCount shouldBe 0124 }125 eventually(10.toDuration(DurationUnit.SECONDS)) {126 kes.eventStream.get(AggregateKey(ENGINE_AGGREGATE_TYPE, aggregateId))?.asClue { wrappers ->127 val events = wrappers.map { it.eventData }.toList()128 events.filterIsInstance<Events.Created>() shouldHaveSize 1129 events.filterIsInstance<Events.Started>() shouldHaveSize 1130 events.filterIsInstance<Events.Stopped>() shouldHaveSize 1131 } ?: fail("No events was found for aggregate")132 engineCmdHandler.handle(Cmds.Check(aggregateId)).asClue {133 it.running shouldBe false134 it.startCount shouldBe 1135 }136 }137 }138 }139 "Test using both projection and saga" {140 withKes(Events.serdes, Cmds.serdes) { kes ->141 val engineCmdHandler = EngineCmdHandler(kes.aggregateRepository)142 val commandQueue = kes.createCommandQueue(setOf(engineCmdHandler))143 val engineProjection = EnginesProjection()144 Sagas.initialize(145 eventSubscriberFactory = kes.subscriberFactory,146 sagaRepository = kes.createSagaRepository(commandQueue),147 sagas = setOf(EngineSaga),148 commandQueue = commandQueue,149 pollInterval = 1.seconds.toLongMilliseconds()150 ) {151 e -> failure("Failed to handle saga event", e)152 }153 Projections.initialize(eventSubscriberFactory = kes.subscriberFactory,154 projections = setOf(engineProjection),155 projectionRepository = kes.projectionRepository,156 subscriber = testCase.displayName157 ) { e ->158 failure("Failed during eventhandling in projection", e)159 }160 val aggregatesCreated = 10161 checkAll(iterations = aggregatesCreated, Arb.uuid(UUIDVersion.V4, false)) { aggregateId ->162 engineCmdHandler.handle(Cmds.Create(aggregateId)).asClue {163 it.id shouldBe aggregateId164 it.running shouldBe false165 it.startCount shouldBe 0166 }167 }168 eventually(30.toDuration(DurationUnit.SECONDS)) {169 engineProjection.all shouldHaveSize aggregatesCreated170 engineProjection.allRunning should beEmpty()171 engineProjection.allStopped shouldHaveSize aggregatesCreated172 }173 }174 }175 "Test projection" {176 withKes(Events.serdes, Cmds.serdes) { kes ->177 val engineCmdHandler = EngineCmdHandler(kes.aggregateRepository)178 val engineProjection = EnginesProjection()179 Projections.initialize(180 eventSubscriberFactory = kes.subscriberFactory,181 projections = setOf(engineProjection),182 projectionRepository = kes.projectionRepository,183 subscriber = testCase.displayName184 ) { e ->185 failure("Failed during projection event handling", e)186 }187 val aggregateId = UUID.randomUUID()188 engineCmdHandler.handle(Cmds.Create(aggregateId)).asClue {189 it.id shouldBe aggregateId190 it.running shouldBe false191 it.startCount shouldBe 0192 }193 eventually(3.toDuration(DurationUnit.SECONDS)) {194 engineProjection.all shouldContain aggregateId195 }196 }197 }198 "Test projection when you have 1000 Created events" {199 withKes(Events.serdes, Cmds.serdes) { kes ->200 val engineCmdHandler = EngineCmdHandler(kes.aggregateRepository)201 val engineProjection = EnginesProjection()202 Projections.initialize(203 eventSubscriberFactory = kes.subscriberFactory,204 projections = setOf(engineProjection),205 projectionRepository = kes.projectionRepository,206 subscriber = testCase.displayName207 ) { e ->208 failure("Failed during projection event handling", e)209 }210 val aggregatesToCreate = 1000211 checkAll(aggregatesToCreate, Arb.uuid(UUIDVersion.V4, false)) { aggregateId ->212 engineCmdHandler.handle(Cmds.Create(aggregateId)).asClue {213 it.id shouldBe aggregateId214 it.running shouldBe false215 it.startCount shouldBe 0216 }217 }218 eventually(3.toDuration(DurationUnit.SECONDS)) {219 engineProjection.all shouldHaveSize aggregatesToCreate220 }221 }222 }223 "Test issuing commands that are not init commands before the aggregate has been created" {224 withKes(Events.serdes, Cmds.serdes) { kes ->225 val engineCmdHandler = EngineCmdHandler(kes.aggregateRepository)226 checkAll(iterations = 100, Arb.uuid(UUIDVersion.V4, false)) { aggregateId ->227 shouldThrowExactly<IllegalStateException> {228 // The Start command is not declared a init command in EngineCmdHandler and thus this command should rejected as the aggregate does not exist229 engineCmdHandler.handle(Cmds.Start(aggregateId))230 } shouldHaveMessage "Aggregate $aggregateId does not exist, and cmd Start is not configured as an initializer. Consider adding an \"init\" configuration for this command."231 }232 }233 }234})...

Full Screen

Full Screen

filter.kt

Source:filter.kt Github

copy

Full Screen

1package io.kotest.property.arbitrary2import io.kotest.property.Arb3import io.kotest.property.PropertyTesting4import io.kotest.property.RTree5import io.kotest.property.RandomSource6import io.kotest.property.Sample7import io.kotest.property.filter8/**9 * Returns a new [Arb] which takes its elements from the receiver and filters them using the supplied10 * predicate. This gen will continue to request elements from the underlying gen until one satisfies11 * the predicate.12 */13fun <A> Arb<A>.filter(predicate: (A) -> Boolean): Arb<A> = trampoline { sampleA ->14 object : Arb<A>() {15 override fun edgecase(rs: RandomSource): A? =16 sequenceOf(sampleA.value)17 .plus(generateSequence { this@filter.edgecase(rs) })18 .take(PropertyTesting.maxFilterAttempts)19 .filter(predicate)20 .firstOrNull()21 override fun sample(rs: RandomSource): Sample<A> {22 val sample = sequenceOf(sampleA).plus(this@filter.samples(rs)).filter { predicate(it.value) }.first()23 return Sample(sample.value, sample.shrinks.filter(predicate) ?: RTree({ sample.value }))24 }25 }26}27/**28 * @return a new [Arb] by filtering this arbs output by the negated function [f]29 */30fun <A> Arb<A>.filterNot(f: (A) -> Boolean): Arb<A> = filter { !f(it) }31/**32 * Create a new [Arb] by keeping only instances of B generated by this gen.33 * This is useful if you have a type hierarchy and only want to retain34 * a particular subtype.35 */36@Suppress("UNCHECKED_CAST")37inline fun <A, reified B : A> Arb<A>.filterIsInstance(): Arb<B> = filter { it is B }.map { it as B }...

Full Screen

Full Screen

Arb.filterIsInstance

Using AI Code Generation

copy

Full Screen

1val arbString = Arb.string()2val arbInt = Arb.int()3val arbIntOrString = arbString.or(arbInt)4val arbIntOrString2 = arbString.or(arbInt)5val arbIntOrString3 = arbIntOrString.or(arbIntOrString2)6val arbIntOrString4 = arbIntOrString3.filterIsInstance<String>()7val arbIntOrString5 = arbIntOrString4.filterIsInstance<Int>()8val arbIntOrString6 = arbIntOrString5.filterIsInstance<String>()9val arbIntOrString7 = arbIntOrString6.filterIsInstance<Int>()10val arbIntOrString8 = arbIntOrString7.filterIsInstance<String>()11val arbIntOrString9 = arbIntOrString8.filterIsInstance<Int>()12val arbIntOrString10 = arbIntOrString9.filterIsInstance<String>()13val arbIntOrString11 = arbIntOrString10.filterIsInstance<Int>()14val arbIntOrString12 = arbIntOrString11.filterIsInstance<String>()15val arbIntOrString13 = arbIntOrString12.filterIsInstance<Int>()16val arbIntOrString14 = arbIntOrString13.filterIsInstance<String>()17val arbIntOrString15 = arbIntOrString14.filterIsInstance<Int>()18val arbIntOrString16 = arbIntOrString15.filterIsInstance<String>()19val arbIntOrString17 = arbIntOrString16.filterIsInstance<Int>()20val arbIntOrString18 = arbIntOrString17.filterIsInstance<String>()21val arbIntOrString19 = arbIntOrString18.filterIsInstance<Int>()22val arbIntOrString20 = arbIntOrString19.filterIsInstance<String>()23val arbIntOrString21 = arbIntOrString20.filterIsInstance<Int>()24val arbIntOrString22 = arbIntOrString21.filterIsInstance<String>()25val arbIntOrString23 = arbIntOrString22.filterIsInstance<Int>()26val arbIntOrString24 = arbIntOrString23.filterIsInstance<String>()27val arbIntOrString25 = arbIntOrString24.filterIsInstance<Int>()28val arbIntOrString26 = arbIntOrString25.filterIsInstance<String>()29val arbIntOrString27 = arbIntOrString26.filterIsInstance<Int>()30val arbIntOrString28 = arbIntOrString27.filterIsInstance<String>()

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful