How to use Arb.withEdgecases method of io.kotest.property.arbitrary.edgecases class

Best Kotest code snippet using io.kotest.property.arbitrary.edgecases.Arb.withEdgecases

BindTest.kt

Source:BindTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.property.arbitrary2import io.kotest.assertions.throwables.shouldThrowAny3import io.kotest.core.spec.style.StringSpec4import io.kotest.extensions.system.captureStandardOut5import io.kotest.matchers.collections.shouldContainExactly6import io.kotest.matchers.collections.shouldHaveAtLeastSize7import io.kotest.matchers.comparables.beGreaterThan8import io.kotest.matchers.comparables.beLessThan9import io.kotest.matchers.comparables.shouldBeGreaterThan10import io.kotest.matchers.ints.shouldBeLessThan11import io.kotest.matchers.should12import io.kotest.matchers.shouldNotBe13import io.kotest.matchers.string.shouldContain14import io.kotest.property.Arb15import io.kotest.property.EdgeConfig16import io.kotest.property.RandomSource17import io.kotest.property.arbitrary.bind18import io.kotest.property.arbitrary.boolean19import io.kotest.property.arbitrary.double20import io.kotest.property.arbitrary.filter21import io.kotest.property.arbitrary.negativeInt22import io.kotest.property.arbitrary.positiveInt23import io.kotest.property.arbitrary.string24import io.kotest.property.arbitrary.take25import io.kotest.property.arbitrary.withEdgecases26import io.kotest.property.arbitrary.zip27import io.kotest.property.checkAll28import io.kotest.matchers.doubles.beGreaterThan as gtd29class BindTest : StringSpec({30 data class User(val email: String, val id: Int)31 data class FooC(val a: String, val b: Int, val c: Double)32 data class FooD(val a: String, val b: Int, val c: Double, val d: Int)33 data class FooE(val a: String, val b: Int, val c: Double, val d: Int, val e: Boolean)34 "Arb.bind(a,b) should generate distinct values" {35 val arbA = Arb.string()36 val arbB = Arb.string()37 Arb.bind(arbA, arbB) { a, b -> a + b }.take(1000).toSet().shouldHaveAtLeastSize(100)38 Arb.zip(arbA, arbB) { a, b -> a + b }.take(1000).toSet().shouldHaveAtLeastSize(100)39 }40 "Arb.bindB" {41 val gen = Arb.bind(Arb.string(), Arb.positiveInt(), ::User)42 checkAll(gen) {43 it.email shouldNotBe null44 it.id should beGreaterThan(0)45 }46 }47 "Arb.bindC" {48 val gen = Arb.bind(Arb.string(), Arb.positiveInt(), Arb.double().filter { it > 0 }, ::FooC)49 checkAll(gen) {50 it.a shouldNotBe null51 it.b should beGreaterThan(0)52 it.c should gtd(0.0)53 }54 }55 "Arb.zipC" {56 val gen = Arb.zip(Arb.string(), Arb.positiveInt(), Arb.double().filter { it > 0 }, ::FooC)57 checkAll(gen) {58 it.a shouldNotBe null59 it.b should beGreaterThan(0)60 it.c should gtd(0.0)61 }62 }63 "Arb.bind(a,b,c) should generate distinct values" {64 val arbA = Arb.string()65 val arbB = Arb.string()66 val arbC = Arb.string()67 Arb.bind(arbA, arbB, arbC) { a, b, c -> "$a$b$c" }.take(1000).toSet().shouldHaveAtLeastSize(100)68 }69 "Arb.bindD" {70 val gen =71 Arb.bind(Arb.string(), Arb.positiveInt(), Arb.double().filter { it > 0 }, Arb.negativeInt(), ::FooD)72 checkAll(gen) {73 it.a shouldNotBe null74 it.b should beGreaterThan(0)75 it.c should gtd(0.0)76 it.d should beLessThan(0)77 }78 }79 "Arb.bind(a,b,c,d) should generate distinct values" {80 val arbA = Arb.string()81 val arbB = Arb.string()82 val arbC = Arb.string()83 val arbD = Arb.string()84 Arb.bind(arbA, arbB, arbC, arbD) { a, b, c, d -> "$a$b$c$d" }.take(1000).toSet().shouldHaveAtLeastSize(100)85 }86 "Arb.bindE" {87 val gen = Arb.bind(88 Arb.string(),89 Arb.positiveInt(),90 Arb.double().filter { it > 0 },91 Arb.negativeInt(),92 Arb.boolean(),93 ::FooE94 )95 checkAll(gen) {96 it.a shouldNotBe null97 it.b should beGreaterThan(0)98 it.c should gtd(0.0)99 it.d should beLessThan(0)100 }101 }102 "Arb.zipE" {103 val gen = Arb.zip(104 Arb.string(),105 Arb.positiveInt(),106 Arb.double().filter { it > 0 },107 Arb.negativeInt(),108 Arb.boolean(),109 ::FooE110 )111 checkAll(gen) {112 it.a shouldNotBe null113 it.b should beGreaterThan(0)114 it.c should gtd(0.0)115 it.d should beLessThan(0)116 }117 }118 "Arb.bind(a,b,c,d,e) should generate distinct values" {119 val arbA = Arb.string()120 val arbB = Arb.string()121 val arbC = Arb.string()122 val arbD = Arb.string()123 val arbE = Arb.string()124 Arb.bind(arbA, arbB, arbC, arbD, arbE) { a, b, c, d, e -> "$a$b$c$d$e" }.take(1000).toSet()125 .shouldHaveAtLeastSize(100)126 }127 "Arb.bind(a,b,c,d,e,f) should generate distinct values" {128 val arbA = Arb.string()129 val arbB = Arb.string()130 val arbC = Arb.string()131 val arbD = Arb.string()132 val arbE = Arb.string()133 val arbF = Arb.string()134 Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF) { a, b, c, d, e, f -> "$a$b$c$d$e$f" }.take(1000).toSet()135 .shouldHaveAtLeastSize(100)136 }137 "Arb.bind(a,b,c,d,e,f,g) should generate distinct values" {138 val arbA = Arb.string()139 val arbB = Arb.string()140 val arbC = Arb.string()141 val arbD = Arb.string()142 val arbE = Arb.string()143 val arbF = Arb.string()144 val arbG = Arb.string()145 Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, arbG) { a, b, c, d, e, f, g -> "$a$b$c$d$e$f$g" }.take(1000).toSet()146 .shouldHaveAtLeastSize(100)147 }148 "Arb.bind(a,b,c,d,e,f,g,h) should generate distinct values" {149 val arbA = Arb.string()150 val arbB = Arb.string()151 val arbC = Arb.string()152 val arbD = Arb.string()153 val arbE = Arb.string()154 val arbF = Arb.string()155 val arbG = Arb.string()156 val arbH = Arb.string()157 Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, arbG, arbH) { a, b, c, d, e, f, g, h -> "$a$b$c$d$e$f$g$h" }158 .take(1000).toSet().shouldHaveAtLeastSize(100)159 }160 "Arb.bind(a,b,c,d,e,f,g,h,i) should generate distinct values" {161 val arbA = Arb.string()162 val arbB = Arb.string()163 val arbC = Arb.string()164 val arbD = Arb.string()165 val arbE = Arb.string()166 val arbF = Arb.string()167 val arbG = Arb.string()168 val arbH = Arb.string()169 val arbI = Arb.string()170 Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, arbG, arbH, arbI) { a, b, c, d, e, f, g, h, i ->171 "$a$b$c$d$e$f$g$h$i"172 }.take(1000).toSet().shouldHaveAtLeastSize(100)173 }174 "Arb.bind(a,b,c,d,e,f,g,h,i,j) should generate distinct values" {175 val arbA = Arb.string()176 val arbB = Arb.string()177 val arbC = Arb.string()178 val arbD = Arb.string()179 val arbE = Arb.string()180 val arbF = Arb.string()181 val arbG = Arb.string()182 val arbH = Arb.string()183 val arbI = Arb.string()184 val arbJ = Arb.string()185 Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, arbG, arbH, arbI, arbJ) { a, b, c, d, e, f, g, h, i, j ->186 "$a$b$c$d$e$f$g$h$i$j"187 }.take(1000).toSet().shouldHaveAtLeastSize(100)188 }189 "Arb.bind(a,b) should compute the probabilistic edge cases" {190 val arbA = Arb.string(1).withEdgecases("a")191 val arbB = Arb.string(1).withEdgecases("a", "b")192 val arb = Arb.bind(arbA, arbB) { a, b -> a + b }193 val edgeCases = arb194 .generate(RandomSource.seeded(1234L), EdgeConfig(edgecasesGenerationProbability = 1.0))195 .take(5)196 .map { it.value }197 .toList()198 edgeCases shouldContainExactly listOf(199 "ab",200 "ab",201 "aa",202 "ab",203 "aa"204 )205 }206 "Arb.bind(a,b,c) should compute probabilistic edge cases" {207 val arbA = Arb.string(1).withEdgecases("a")208 val arbB = Arb.string(1).withEdgecases("a", "b")209 val arbC = Arb.string(1).withEdgecases(emptyList())210 val arb = Arb.bind(arbA, arbB, arbC) { a, b, c -> a + b + c }211 val edgeCases = arb212 .generate(RandomSource.seeded(1234L), EdgeConfig(edgecasesGenerationProbability = 1.0))213 .take(5)214 .map { it.value }215 .toList()216 edgeCases shouldContainExactly listOf(217 "abk",218 "abK",219 "abz",220 "aaw",221 "ab/"222 )223 }224 "Arb.bind(a,b,c,d) should compute probabilistic edge cases" {225 val arbA = Arb.string(1).withEdgecases("a")226 val arbB = Arb.string(1).withEdgecases("a", "b")227 val arbC = Arb.string(1).withEdgecases("a", "b")228 val arbD = Arb.string(1).withEdgecases(emptyList())229 val arb = Arb.bind(arbA, arbB, arbC, arbD) { a, b, c, d -> "$a$b$c$d" }230 val edgeCases = arb231 .generate(RandomSource.seeded(1234L), EdgeConfig(edgecasesGenerationProbability = 1.0))232 .take(5)233 .map { it.value }234 .toList()235 edgeCases shouldContainExactly listOf(236 "abb ",237 "aaaC",238 "aabV",239 "abad",240 "aabb"241 )242 }243 "Arb.bind(a,b,c,d,e) should compute probabilistic edge cases" {244 val arbA = Arb.string(1).withEdgecases("a")245 val arbB = Arb.string(1).withEdgecases("a", "b")246 val arbC = Arb.string(1).withEdgecases(emptyList())247 val arbD = Arb.string(1).withEdgecases("a", "b")248 val arbE = Arb.string(1).withEdgecases("a", "b")249 val arb = Arb.bind(arbA, arbB, arbC, arbD, arbE) { a, b, c, d, e -> "$a$b$c$d$e" }250 val edgeCases = arb251 .generate(RandomSource.seeded(1234L), EdgeConfig(edgecasesGenerationProbability = 1.0))252 .take(5)253 .map { it.value }254 .toList()255 edgeCases shouldContainExactly listOf(256 "abkbb",257 "aaCab",258 "aa-ba",259 "ab/aa",260 "aa`aa"261 )262 }263 "Arb.bind(a,b,c,d,e,f) should compute probabilistic edge cases" {264 val arbA = Arb.string(1).withEdgecases("a", "b")265 val arbB = Arb.string(1).withEdgecases("a", "b")266 val arbC = Arb.string(1).withEdgecases(emptyList())267 val arbD = Arb.string(1).withEdgecases("a", "b")268 val arbE = Arb.string(1).withEdgecases("a", "b")269 val arbF = Arb.string(1).withEdgecases(emptyList())270 val arb = Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF) { a, b, c, d, e, f -> "$a$b$c$d$e$f" }271 val edgeCases = arb272 .generate(RandomSource.seeded(1234L), EdgeConfig(edgecasesGenerationProbability = 1.0))273 .take(5)274 .map { it.value }275 .toList()276 edgeCases shouldContainExactly listOf(277 "bbkbb?",278 "aaGaaP",279 "ba'ab/",280 "bb;bbL",281 "bbiab;"282 )283 }284 "Arb.bind(a,b,c,d,e,f,g) should compute probabilistic edge cases" {285 val arbA = Arb.string(1).withEdgecases(emptyList())286 val arbB = Arb.string(1).withEdgecases("a", "b")287 val arbC = Arb.string(1).withEdgecases("a")288 val arbD = Arb.string(1).withEdgecases("a", "b")289 val arbE = Arb.string(1).withEdgecases("a", "b")290 val arbF = Arb.string(1).withEdgecases(emptyList())291 val arbG = Arb.string(1).withEdgecases("a", "b")292 val arb = Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, arbG) { a, b, c, d, e, f, g -> "$a$b$c$d$e$f$g" }293 val edgeCases = arb294 .generate(RandomSource.seeded(1234L), EdgeConfig(edgecasesGenerationProbability = 1.0))295 .take(5)296 .map { it.value }297 .toList()298 edgeCases shouldContainExactly listOf(299 "%babb?a",300 "#baabVa",301 "'aaabsb",302 ":baaa\\b",303 "`babaBa"304 )305 }306 "Arb.bind(a,b,c,d,e,f,g,h) should compute probabilistic edge cases" {307 val arbA = Arb.string(1).withEdgecases("a", "b")308 val arbB = Arb.string(1).withEdgecases("a")309 val arbC = Arb.string(1).withEdgecases("a", "b")310 val arbD = Arb.string(1).withEdgecases("a", "b")311 val arbE = Arb.string(1).withEdgecases(emptyList())312 val arbF = Arb.string(1).withEdgecases("a", "b")313 val arbG = Arb.string(1).withEdgecases("a", "b")314 val arbH = Arb.string(1).withEdgecases(emptyList())315 val arb =316 Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, arbG, arbH) { a, b, c, d, e, f, g, h -> "$a$b$c$d$e$f$g$h" }317 val edgeCases = arb318 .generate(RandomSource.seeded(1234L), EdgeConfig(edgecasesGenerationProbability = 1.0))319 .take(5)320 .map { it.value }321 .toList()322 edgeCases shouldContainExactly listOf(323 "babacbbK",324 "aaaaPbaw",325 "aaabsbb;",326 "aaabsbb`",327 "babbPbb'"328 )329 }330 "Arb.bind(a,b,c,d,e,f,g,h,i) should compute probabilistic edge cases" {331 val arbA = Arb.string(1).withEdgecases("a", "b")332 val arbB = Arb.string(1).withEdgecases(emptyList())333 val arbC = Arb.string(1).withEdgecases("a")334 val arbD = Arb.string(1).withEdgecases("a", "b")335 val arbE = Arb.string(1).withEdgecases("a", "b")336 val arbF = Arb.string(1).withEdgecases(emptyList())337 val arbG = Arb.string(1).withEdgecases("a", "b")338 val arbH = Arb.string(1).withEdgecases("a", "b")339 val arbI = Arb.string(1).withEdgecases("a", "b")340 val arb = Arb.bind(341 arbA,342 arbB,343 arbC,344 arbD,345 arbE,346 arbF,347 arbG,348 arbH,349 arbI350 ) { a, b, c, d, e, f, g, h, i -> "$a$b$c$d$e$f$g$h$i" }351 val edgeCases = arb352 .generate(RandomSource.seeded(1234L), EdgeConfig(edgecasesGenerationProbability = 1.0))353 .take(5)354 .map { it.value }355 .toList()356 edgeCases shouldContainExactly listOf(357 "boabb?aaa",358 "bzaab8aba",359 "azabb;bba",360 "bsabaAaba",361 "aEaabBaaa"362 )363 }364 "Arb.bind(a,b,c,d,e,f,g,h,i,j) should compute probabilistic edge cases" {365 val arbA = Arb.string(1).withEdgecases("a", "b")366 val arbB = Arb.string(1).withEdgecases(emptyList())367 val arbC = Arb.string(1).withEdgecases("a", "b")368 val arbD = Arb.string(1).withEdgecases("a", "b")369 val arbE = Arb.string(1).withEdgecases("a")370 val arbF = Arb.string(1).withEdgecases("a", "b")371 val arbG = Arb.string(1).withEdgecases("a", "b")372 val arbH = Arb.string(1).withEdgecases(emptyList())373 val arbI = Arb.string(1).withEdgecases("a", "b")374 val arbJ = Arb.string(1).withEdgecases("a", "b")375 val arb = Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, arbG, arbH, arbI, arbJ) { a, b, c, d, e, f, g, h, i, j ->376 "$a$b$c$d$e$f$g$h$i$j"377 }378 val edgeCases = arb379 .generate(RandomSource.seeded(1234L), EdgeConfig(edgecasesGenerationProbability = 1.0))380 .take(5)381 .map { it.value }382 .toList()383 edgeCases shouldContainExactly listOf(384 "boababbKaa",385 "aVababa'ab",386 "a2bbabbLab",387 "b\\bbabaBab",388 "aabaaaa*ab"389 )390 }391 "Arb.bind(a,b,c,d,e,f,g,h,i,j,k) should compute probabilistic edge cases" {392 val arbA = Arb.string(1).withEdgecases("a", "b")393 val arbB = Arb.string(1).withEdgecases("a")394 val arbC = Arb.string(1).withEdgecases("a", "b")395 val arbD = Arb.string(1).withEdgecases("a", "b")396 val arbE = Arb.string(1).withEdgecases(emptyList())397 val arbF = Arb.string(1).withEdgecases("a", "b")398 val arbG = Arb.string(1).withEdgecases("a", "b")399 val arbH = Arb.string(1).withEdgecases("a", "b")400 val arbI = Arb.string(1).withEdgecases("a", "b")401 val arbJ = Arb.string(1).withEdgecases(emptyList())402 val arbK = Arb.string(1).withEdgecases("a", "b")403 val arb =404 Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, arbG, arbH, arbI, arbJ, arbK) { a, b, c, d, e, f, g, h, i, j, k ->405 "$a$b$c$d$e$f$g$h$i$j$k"406 }407 val edgeCases = arb408 .generate(RandomSource.seeded(1234L), EdgeConfig(edgecasesGenerationProbability = 1.0))409 .take(5)410 .map { it.value }411 .toList()412 edgeCases shouldContainExactly listOf(413 "babacbbaaCa",414 "aaab8abaaSb",415 "baba`aaabsb",416 "baabYbabb=b",417 "aaaa*abbaOa"418 )419 }420 "Arb.bind(a,b,c,d,e,f,g,h,i,j,k,l) should compute probabilistic edge cases" {421 val arbA = Arb.string(1).withEdgecases("a", "b")422 val arbB = Arb.string(1).withEdgecases("a", "b")423 val arbC = Arb.string(1).withEdgecases(emptyList())424 val arbD = Arb.string(1).withEdgecases("a", "b")425 val arbE = Arb.string(1).withEdgecases("a", "b")426 val arbF = Arb.string(1).withEdgecases("a", "b")427 val arbG = Arb.string(1).withEdgecases("a", "b")428 val arbH = Arb.string(1).withEdgecases("a", "b")429 val arbI = Arb.string(1).withEdgecases("a", "b")430 val arbJ = Arb.string(1).withEdgecases("a")431 val arbK = Arb.string(1).withEdgecases("a", "b")432 val arbL = Arb.string(1).withEdgecases(emptyList())433 val arb = Arb.bind(434 arbA,435 arbB,436 arbC,437 arbD,438 arbE,439 arbF,440 arbG,441 arbH,442 arbI,443 arbJ,444 arbK,445 arbL446 ) { a, b, c, d, e, f, g, h, i, j, k, l ->447 "$a$b$c$d$e$f$g$h$i$j$k$l"448 }449 val edgeCases = arb450 .generate(RandomSource.seeded(1234L), EdgeConfig(edgecasesGenerationProbability = 1.0))451 .take(5)452 .map { it.value }453 .toList()454 edgeCases shouldContainExactly listOf(455 "bbkbbbbaaaaG",456 "ba-babaababs",457 "ba`aaabbbab`",458 "baBabbbababh",459 "ab?babbabaa0"460 )461 }462 "Arb.bind(a,b,c,d,e,f,g,h,i,j,k,l,m) should compute probabilistic edge cases" {463 val arbA = Arb.string(1).withEdgecases(emptyList())464 val arbB = Arb.string(1).withEdgecases("a", "b")465 val arbC = Arb.string(1).withEdgecases("a", "b")466 val arbD = Arb.string(1).withEdgecases("a")467 val arbE = Arb.string(1).withEdgecases("a", "b")468 val arbF = Arb.string(1).withEdgecases("a", "b")469 val arbG = Arb.string(1).withEdgecases(emptyList())470 val arbH = Arb.string(1).withEdgecases("a", "b")471 val arbI = Arb.string(1).withEdgecases("a", "b")472 val arbJ = Arb.string(1).withEdgecases("a")473 val arbK = Arb.string(1).withEdgecases("a", "b")474 val arbL = Arb.string(1).withEdgecases("a", "b")475 val arbM = Arb.string(1).withEdgecases(emptyList())476 val arb = Arb.bind(477 arbA,478 arbB,479 arbC,480 arbD,481 arbE,482 arbF,483 arbG,484 arbH,485 arbI,486 arbJ,487 arbK,488 arbL,489 arbM490 ) { a, b, c, d, e, f, g, h, i, j, k, l, m ->491 "$a$b$c$d$e$f$g$h$i$j$k$l$m"492 }493 val edgeCases = arb494 .generate(RandomSource.seeded(1234L), EdgeConfig(edgecasesGenerationProbability = 1.0))495 .take(5)496 .map { it.value }497 .toList()498 edgeCases shouldContainExactly listOf(499 "%baabbWaaaabz",500 "-baaaaSbaabb;",501 "Lababb\\bbabaB",502 " ababa#aaaab ",503 "7aaaaapbaaaav"504 )505 }506 "Arb.bind(a,b,c,d,e,f,g,h,i,j,k,l,m,n) should compute probabilistic edge cases" {507 val arbA = Arb.string(1).withEdgecases("a")508 val arbB = Arb.string(1).withEdgecases("a", "b")509 val arbC = Arb.string(1).withEdgecases("a", "b")510 val arbD = Arb.string(1).withEdgecases("a", "b")511 val arbE = Arb.string(1).withEdgecases("a", "b")512 val arbF = Arb.string(1).withEdgecases("a", "b")513 val arbG = Arb.string(1).withEdgecases("a", "b")514 val arbH = Arb.string(1).withEdgecases(emptyList())515 val arbI = Arb.string(1).withEdgecases("a", "b")516 val arbJ = Arb.string(1).withEdgecases("a", "b")517 val arbK = Arb.string(1).withEdgecases("a", "b")518 val arbL = Arb.string(1).withEdgecases("a", "b")519 val arbM = Arb.string(1).withEdgecases("a", "b")520 val arbN = Arb.string(1).withEdgecases(emptyList())521 val arb = Arb.bind(522 arbA,523 arbB,524 arbC,525 arbD,526 arbE,527 arbF,528 arbG,529 arbH,530 arbI,531 arbJ,532 arbK,533 arbL,534 arbM,535 arbN536 ) { a, b, c, d, e, f, g, h, i, j, k, l, m, n ->537 "$a$b$c$d$e$f$g$h$i$j$k$l$m$n"538 }539 val edgeCases = arb540 .generate(RandomSource.seeded(1234L), EdgeConfig(edgecasesGenerationProbability = 1.0))541 .take(5)542 .map { it.value }543 .toList()544 edgeCases shouldContainExactly listOf(545 "abbabbbWaaaabz",546 "aababaaSbaabb;",547 "aaabbbb\\bbabaB",548 "abababa#aabab ",549 "abaabaapbabaav"550 )551 }552 "Arb.bind list" {553 val arbs: List<Arb<String>> = generateSequence { Arb.string(1).withEdgecases("a") }.take(100).toList()554 val arb: Arb<String> = Arb.bind(arbs) { it.joinToString("") }555 val edgeCases = arb556 .generate(RandomSource.seeded(1234L), EdgeConfig(edgecasesGenerationProbability = 1.0))557 .take(5)558 .map { it.value }559 .toList()560 edgeCases shouldContainExactly listOf(561 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",562 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",563 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",564 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",565 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"566 )567 }568 "!Arb.bind shrinks" {569 data class Person(val name: String, val age: Int)570 val arb = Arb.bind<Person>()571 val stdout = captureStandardOut {572 shouldThrowAny {573 checkAll(arb) { person ->574 person.name.length shouldBeLessThan 10575 person.age shouldBeGreaterThan -1576 person.age shouldBeLessThan 130577 }578 }579 }580 stdout shouldContain "Shrink result"581 stdout shouldContain "Person(name=, age=-1)"582 }583})...

Full Screen

Full Screen

BuilderTest.kt

Source:BuilderTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.property.arbitrary2import io.kotest.assertions.throwables.shouldNotThrowAny3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.core.spec.style.FunSpec5import io.kotest.matchers.collections.shouldContainExactly6import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder7import io.kotest.matchers.ints.shouldBeBetween8import io.kotest.matchers.ints.shouldBeGreaterThan9import io.kotest.matchers.nulls.shouldBeNull10import io.kotest.matchers.shouldBe11import io.kotest.matchers.string.shouldHaveLengthBetween12import io.kotest.matchers.types.shouldBeSameInstanceAs13import io.kotest.property.Arb14import io.kotest.property.RandomSource15import io.kotest.property.arbitrary.Codepoint16import io.kotest.property.arbitrary.IntShrinker17import io.kotest.property.arbitrary.alphanumeric18import io.kotest.property.arbitrary.arbitrary19import io.kotest.property.arbitrary.constant20import io.kotest.property.arbitrary.edgecases21import io.kotest.property.arbitrary.flatMap22import io.kotest.property.arbitrary.generateArbitrary23import io.kotest.property.arbitrary.int24import io.kotest.property.arbitrary.map25import io.kotest.property.arbitrary.next26import io.kotest.property.arbitrary.numbers.IntClassifier27import io.kotest.property.arbitrary.single28import io.kotest.property.arbitrary.string29import io.kotest.property.arbitrary.take30import io.kotest.property.arbitrary.withEdgecases31import kotlinx.coroutines.withContext32import kotlin.coroutines.CoroutineContext33import kotlin.random.nextInt34class BuilderTest : FunSpec() {35 init {36 test("custom arb test") {37 arbitrary {38 it.random.nextInt(3..6)39 }.take(1000).toSet() shouldBe setOf(3, 4, 5, 6)40 }41 test("composition of arbs") {42 data class Person(val name: String, val age: Int)43 val personArb = arbitrary { rs ->44 val name = Arb.string(10..12).next(rs)45 val age = Arb.int(21, 150).next(rs)46 Person(name, age)47 }48 personArb.next().name.shouldHaveLengthBetween(10, 12)49 personArb.next().age.shouldBeBetween(21, 150)50 }51 context("arbitrary builder using restricted continuation") {52 test("should be stack safe") {53 val arb: Arb<Int> = arbitrary {54 (1..100000).map {55 Arb.int().bind()56 }.last()57 }58 val result = shouldNotThrowAny { arb.single(RandomSource.seeded(1234)) }59 result shouldBe -148693402360 }61 test("should be equivalent to chaining flatMaps") {62 val arbFlatMaps: Arb<String> =63 Arb.string(5, Codepoint.alphanumeric()).withEdgecases("edge1", "edge2").flatMap { first ->64 Arb.int(1..9).withEdgecases(5).flatMap { second ->65 Arb.int(101..109).withEdgecases(100 + second).map { third ->66 "$first $second $third"67 }68 }69 }70 val arb: Arb<String> = arbitrary {71 val first = Arb.string(5, Codepoint.alphanumeric()).withEdgecases("edge1", "edge2").bind()72 val second = Arb.int(1..9).withEdgecases(5).bind()73 val third = Arb.int(101..109).withEdgecases(100 + second).bind()74 "$first $second $third"75 }76 val flatMapsResult = arbFlatMaps.generate(RandomSource.seeded(12345L)).take(100).map { it.value }.toList()77 val builderResult = arb.generate(RandomSource.seeded(12345L)).take(100).map { it.value }.toList()78 // should be equivalent79 builderResult shouldContainExactly flatMapsResult80 }81 test("should bind edgecases") {82 val arb: Arb<String> = arbitrary {83 val first = Arb.string(5, Codepoint.alphanumeric()).withEdgecases("edge1", "edge2").bind()84 val second = Arb.int(1..9).withEdgecases(5).bind()85 val third = Arb.int(101..109).withEdgecases(100 + second, 109).bind()86 "$first $second $third"87 }88 arb.edgecases() shouldContainExactlyInAnyOrder setOf(89 "edge1 5 105",90 "edge2 5 105",91 "edge1 5 109",92 "edge2 5 109",93 )94 }95 test("should preserve edgecases of dependent arbs, even when intermideary arb(s) have no edgecases") {96 val arb: Arb<String> = arbitrary {97 val first = Arb.string(5, Codepoint.alphanumeric()).withEdgecases("edge1", "edge2").bind()98 val second = Arb.int(1..4).withEdgecases(emptyList()).bind()99 val third = Arb.int(101..109).withEdgecases(100 + second).bind()100 "$first $second $third"101 }102 arb.edgecases() shouldContainExactlyInAnyOrder setOf(103 "edge1 1 101",104 "edge1 2 102",105 "edge1 3 103",106 "edge1 4 104",107 "edge2 1 101",108 "edge2 2 102",109 "edge2 3 103",110 "edge2 4 104"111 )112 }113 test("should assign edgecases") {114 val edges = setOf("edge1", "edge2")115 val arb = arbitrary(edges.toList()) { "abcd" }116 arb.edgecases() shouldContainExactlyInAnyOrder edges117 }118 test("should assign edgecases and shrinker") {119 val shrinker = IntShrinker(1..5)120 val edges = setOf(1, 2)121 val arb = arbitrary(edges.toList(), shrinker) { 5 }122 arb.edgecases() shouldContainExactlyInAnyOrder edges123 arb.sample(RandomSource.seeded(1234L)).shrinks.children.value.map { it.value() } shouldBe shrinker.shrink(5)124 }125 test("should use shrinker when provided") {126 val shrinker = IntShrinker(1..5)127 val arb = arbitrary(shrinker) { 5 }128 arb.classifier.shouldBeNull()129 val shrinks = arb.sample(RandomSource.seeded(1234L)).shrinks130 shrinks.children.value.map { it.value() } shouldContainExactly shrinker.shrink(5)131 }132 test("should use classifier when provided") {133 val classifier = IntClassifier(1..5)134 val arb = arbitrary(classifier) { 5 }135 arb.classifier shouldBeSameInstanceAs classifier136 }137 test("should use classifier and shrinker when provided") {138 val shrinker = IntShrinker(1..5)139 val classifier = IntClassifier(1..5)140 val arb = arbitrary(shrinker, classifier) { 5 }141 arb.classifier shouldBeSameInstanceAs classifier142 val shrinks = arb.sample(RandomSource.seeded(1234L)).shrinks143 shrinks.children.value.map { it.value() } shouldContainExactly shrinker.shrink(5)144 }145 test("should use edgecase function when provided") {146 val arb = arbitrary({ 5 }) { 10 }147 arb.edgecases() shouldContainExactlyInAnyOrder setOf(5)148 }149 test("should use edgecase function and shrinker when provided") {150 val shrinker = IntShrinker(1..5)151 val arb = arbitrary({ 5 }, shrinker) { 10 }152 arb.edgecases() shouldContainExactlyInAnyOrder setOf(5)153 val shrinks = arb.sample(RandomSource.seeded(1234L)).shrinks154 shrinks.children.value.map { it.value() } shouldContainExactly shrinker.shrink(10)155 }156 test("should support .bind() syntax") {157 val arb = Arb.constant(5)158 val shrinker = IntShrinker(1..5)159 val classifier = IntClassifier(1..5)160 arbitrary { arb.bind() }.single() shouldBe 5161 arbitrary(shrinker) { arb.bind() }.single() shouldBe 5162 arbitrary(classifier) { arb.bind() }.single() shouldBe 5163 arbitrary(shrinker, classifier) { arb.bind() }.single() shouldBe 5164 arbitrary(listOf(5)) { arb.bind() }.single() shouldBe 5165 arbitrary({ 5 }) { arb.bind() }.single() shouldBe 5166 arbitrary({ 5 }, shrinker) { arb.bind() }.single() shouldBe 5167 }168 }169 context("suspend arbitrary builder with unrestricted continuation") {170 suspend fun combineAsString(vararg values: Any?): String = values.joinToString(" ")171 test("should build arb on the parent coroutine context") {172 val arb = withContext(Foo("hello")) {173 generateArbitrary {174 val hello = coroutineContext[Foo]?.value175 val world = arbitrary { "world" }.bind()176 val first = Arb.int(1..10).bind()177 val second = Arb.int(11..20).bind()178 combineAsString(hello, world, first, second)179 }180 }181 arb.generate(RandomSource.seeded(1234L)).take(4).toList().map { it.value } shouldContainExactly listOf(182 "hello world 2 20",183 "hello world 6 12",184 "hello world 7 19",185 "hello world 9 13"186 )187 }188 test("should bind edgecases") {189 val arb: Arb<String> = generateArbitrary {190 val first = Arb.string(5, Codepoint.alphanumeric()).withEdgecases("edge1", "edge2").bind()191 val second = Arb.int(1..9).withEdgecases(5).bind()192 val third = Arb.int(101..109).withEdgecases(100 + second, 109).bind()193 combineAsString(first, second, third)194 }195 arb.edgecases() shouldContainExactlyInAnyOrder setOf(196 "edge1 5 105",197 "edge2 5 105",198 "edge1 5 109",199 "edge2 5 109",200 )201 }202 test("should preserve edgecases of dependent arbs, even when intermideary arb(s) have no edgecases") {203 val arb: Arb<String> = generateArbitrary {204 val first = Arb.string(5, Codepoint.alphanumeric()).withEdgecases("edge1", "edge2").bind()205 val second = Arb.int(1..4).withEdgecases(emptyList()).bind()206 val third = Arb.int(101..109).withEdgecases(100 + second).bind()207 combineAsString(first, second, third)208 }209 arb.edgecases() shouldContainExactlyInAnyOrder setOf(210 "edge1 1 101",211 "edge1 2 102",212 "edge1 3 103",213 "edge1 4 104",214 "edge2 1 101",215 "edge2 2 102",216 "edge2 3 103",217 "edge2 4 104"218 )219 }220 test("should propagate exception") {221 val throwingArb = generateArbitrary {222 val number = Arb.int(1..4).withEdgecases(emptyList()).bind()223 // try to throw something inside the arb224 number shouldBeGreaterThan 5225 }226 val assertionError = shouldThrow<AssertionError> { execute(RandomSource.seeded(1234L), throwingArb) }227 assertionError.message shouldBe "4 should be > 5"228 }229 test("should assign edgecases") {230 val edges = setOf("edge1", "edge2")231 val arb = generateArbitrary(edges.toList()) { "abcd" }232 arb.edgecases() shouldContainExactlyInAnyOrder edges233 }234 test("should assign edgecases and shrinker") {235 val shrinker = IntShrinker(1..5)236 val edges = setOf(1, 2)237 val arb = generateArbitrary(edges.toList(), shrinker) { 5 }238 arb.edgecases() shouldContainExactlyInAnyOrder edges239 arb.sample(RandomSource.seeded(1234L)).shrinks.children.value.map { it.value() } shouldBe shrinker.shrink(5)240 }241 test("should use shrinker when provided") {242 val shrinker = IntShrinker(1..5)243 val arb = generateArbitrary(shrinker) { 5 }244 arb.classifier.shouldBeNull()245 val shrinks = arb.sample(RandomSource.seeded(1234L)).shrinks246 shrinks.children.value.map { it.value() } shouldContainExactly shrinker.shrink(5)247 }248 test("should use classifier when provided") {249 val classifier = IntClassifier(1..5)250 val arb = generateArbitrary(classifier) { 5 }251 arb.classifier shouldBeSameInstanceAs classifier252 }253 test("should use classifier and shrinker when provided") {254 val shrinker = IntShrinker(1..5)255 val classifier = IntClassifier(1..5)256 val arb = generateArbitrary(shrinker, classifier) { 5 }257 arb.classifier shouldBeSameInstanceAs classifier258 val shrinks = arb.sample(RandomSource.seeded(1234L)).shrinks259 shrinks.children.value.map { it.value() } shouldContainExactly shrinker.shrink(5)260 }261 test("should use edgecase function when provided") {262 val arb = generateArbitrary({ 5 }) { 10 }263 arb.edgecases() shouldContainExactlyInAnyOrder setOf(5)264 }265 test("should use edgecase function and shrinker when provided") {266 val shrinker = IntShrinker(1..5)267 val arb = generateArbitrary({ 5 }, shrinker) { 10 }268 arb.edgecases() shouldContainExactlyInAnyOrder setOf(5)269 val shrinks = arb.sample(RandomSource.seeded(1234L)).shrinks270 shrinks.children.value.map { it.value() } shouldContainExactly shrinker.shrink(10)271 }272 test("should support .bind() syntax") {273 val arb = Arb.constant(5)274 val shrinker = IntShrinker(1..5)275 val classifier = IntClassifier(1..5)276 generateArbitrary { arb.bind() }.single() shouldBe 5277 generateArbitrary(shrinker) { arb.bind() }.single() shouldBe 5278 generateArbitrary(classifier) { arb.bind() }.single() shouldBe 5279 generateArbitrary(shrinker, classifier) { arb.bind() }.single() shouldBe 5280 generateArbitrary(listOf(5)) { arb.bind() }.single() shouldBe 5281 generateArbitrary({ 5 }) { arb.bind() }.single() shouldBe 5282 generateArbitrary({ 5 }, shrinker) { arb.bind() }.single() shouldBe 5283 }284 }285 }286 private data class Foo(val value: String) : CoroutineContext.Element {287 companion object : CoroutineContext.Key<Foo>288 override val key: CoroutineContext.Key<*> = Foo289 }290 private suspend fun execute(rs: RandomSource, arb: Arb<*>): Unit {291 arb.generate(rs).take(1000).last()292 }293}...

Full Screen

Full Screen

PropertySpec.kt

Source:PropertySpec.kt Github

copy

Full Screen

1package ru.iopump.qa.sample.property2import com.github.f4b6a3.uuid.UuidCreator3import io.kotest.core.spec.style.FreeSpec4import io.kotest.matchers.booleans.shouldBeTrue5import io.kotest.matchers.shouldBe6import io.kotest.matchers.string.UUIDVersion7import io.kotest.matchers.string.shouldBeUUID8import io.kotest.property.Arb9import io.kotest.property.Exhaustive10import io.kotest.property.arbitrary.int11import io.kotest.property.arbitrary.withEdgecases12import io.kotest.property.checkAll13import io.kotest.property.exhaustive.andNull14import io.kotest.property.exhaustive.enum15import io.kotest.property.forAll16import java.util.*17import kotlin.math.sqrt18class PropertySpec : FreeSpec() {19 init {20 "Basic theorem of arithmetic. Any number can be factorized to list of prime" {21 /*1*/Arb.int(2..Int.MAX_VALUE).withEdgecases(2, Int.MAX_VALUE).forAll(1000) { number ->22 val primeFactors = number.primeFactors23 println("#${attempts()} Source number '$number' = $primeFactors")24 /*2*/primeFactors.all(Int::isPrime) && primeFactors.reduce(Int::times) == number25 }26 /*3*/Arb.int(2..Int.MAX_VALUE).checkAll(1000) { number ->27 val primeFactors = number.primeFactors28 println("#${attempts()} Source number '$number' = $primeFactors")29 /*4*/primeFactors.onEach { it.isPrime.shouldBeTrue() }.reduce(Int::times) shouldBe number30 }31 }32 "UUIDVersion should be matched with regexp" {33 /*1*/Exhaustive.enum<UUIDVersion>().andNull().checkAll { uuidVersion ->34 /*2*/uuidVersion.generateUuid().toString()35 /*3*/.shouldBeUUID(uuidVersion ?: UUIDVersion.ANY)36 .also { println("${attempts()} $uuidVersion: $it") }37 }38 }39 }40}41val Int.isPrime get() = toBigInteger().isProbablePrime(1)42val Int.primeFactors: Collection<Int>43 get() {44 // Array that contains all the prime factors of given number.45 val arr: ArrayList<Int> = arrayListOf()46 var n = this47 if (n in (0..1)) throw IllegalArgumentException("Factorized number must be grater then 1")48 // At first check for divisibility by 2. add it in arr till it is divisible49 while (n % 2 == 0) {50 arr.add(2)51 n /= 252 }53 val squareRoot = sqrt(n.toDouble()).toInt()54 // Run loop from 3 to square root of n. Check for divisibility by i. Add i in arr till it is divisible by i.55 for (i in 3..squareRoot step 2) {56 while (n % i == 0) {57 arr.add(i)58 n /= i59 }60 }61 // If n is a prime number greater than 2.62 if (n > 2) {63 arr.add(n)64 }65 return arr66 }67/** Using [uuid-creator](https://github.com/f4b6a3/uuid-creator) */68fun UUIDVersion?.generateUuid(): UUID =69 when (this) {70 null -> UUID.randomUUID()71 UUIDVersion.ANY -> UUID.randomUUID()72 UUIDVersion.V1 -> UuidCreator.getTimeBased()73 UUIDVersion.V2 -> UuidCreator.getDceSecurity(1, 1)74 UUIDVersion.V3 -> UuidCreator.getNameBasedMd5("666")75 UUIDVersion.V4 -> UuidCreator.getRandomBased()76 UUIDVersion.V5 -> UuidCreator.getNameBasedSha1("666")77 }...

Full Screen

Full Screen

ItemGens.kt

Source:ItemGens.kt Github

copy

Full Screen

1package dev.adamko.gildedrose.testdata2import com.gildedrose.Item3import dev.adamko.config.KotestConfig.Companion.intEdgecases4import dev.adamko.config.KotestConfig.Companion.mergeAll5import io.kotest.property.Arb6import io.kotest.property.Gen7import io.kotest.property.arbitrary.alphanumeric8import io.kotest.property.arbitrary.bind9import io.kotest.property.arbitrary.filterNot10import io.kotest.property.arbitrary.map11import io.kotest.property.arbitrary.string12import io.kotest.property.arbitrary.withEdgecases13import io.kotest.property.exhaustive.exhaustive14object ItemGens {15 object Names {16 val regular = Arb.string(10, Arb.alphanumeric()).withEdgecases(17 "+5 Dexterity Vest",18 "Elixir of the Mongoose",19 )20 val aged = listOf("Aged Brie").exhaustive()21 val tickets = listOf("Backstage passes to a TAFKAL80ETC concert").exhaustive()22 val legendary = listOf("Sulfuras, Hand of Ragnaros").exhaustive()23 val conjured = listOf(regular, aged, tickets, legendary).mergeAll().map { "Conjured $it" }24 val all = listOf(regular, aged, tickets, conjured, legendary).mergeAll()25 val nonLegendary = listOf(regular, aged, tickets, conjured).mergeAll()26 }27 object SellIn {28 /**29 * Edgecases for the minimum and maximum values, as well as some that30 * are centered around the expiration date of 0.31 */32 private val edgecases: List<Int> = (-2..2) + (Int.MAX_VALUE - 1) + (Int.MIN_VALUE + 1)33 // note- ignore integer overflow for now34 val nonExpired = Arb.intEdgecases(1, Int.MAX_VALUE - 1, edgecases)35 val expired = Arb.intEdgecases(Int.MIN_VALUE + 1, 0, edgecases)36 val any = Arb.intEdgecases(Int.MIN_VALUE + 1 until Int.MAX_VALUE, edgecases)37 }38 object Quality {39 val regularValidRange = 0..5040 /** Some additional edgecases around the min/max quality range */41 private val edgecases: List<Int> =42 regularValidRange.first.let { (it - 3)..(it + 3) } +43 regularValidRange.last.let { (it - 3)..(it + 3) }44 val any = Arb.intEdgecases(Int.MIN_VALUE + 1 until Int.MAX_VALUE, edgecases)45 val validRegular = Arb.intEdgecases(regularValidRange, edgecases)46 // note- ignore integer overflow for now47 val invalidRegular = any.filterNot { it in regularValidRange }48 }49 object Binds {50 fun itemArb(51 nameGen: Gen<String> = Names.all,52 sellInGen: Gen<Int> = SellIn.any,53 qualityGen: Gen<Int> = Quality.any,54 ) = Arb.bind(nameGen, sellInGen, qualityGen) { name, sellIn, quality ->55 Item(name, sellIn, quality)56 }57 }58}...

Full Screen

Full Screen

FilterTest.kt

Source:FilterTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.property.arbitrary2import io.kotest.assertions.throwables.shouldNotThrow3import io.kotest.assertions.throwables.shouldNotThrowAny4import io.kotest.core.spec.style.FunSpec5import io.kotest.inspectors.forAll6import io.kotest.matchers.collections.shouldContainExactly7import io.kotest.matchers.collections.shouldNotBeIn8import io.kotest.matchers.shouldBe9import io.kotest.property.Arb10import io.kotest.property.EdgeConfig11import io.kotest.property.RandomSource12import io.kotest.property.Sample13import io.kotest.property.arbitrary.filter14import io.kotest.property.arbitrary.int15import io.kotest.property.arbitrary.map16import io.kotest.property.arbitrary.of17import io.kotest.property.arbitrary.single18import io.kotest.property.arbitrary.take19import io.kotest.property.arbitrary.withEdgecases20class FilterTest : FunSpec({21 test("should filter elements") {22 Arb.int(1..10).withEdgecases(2, 4, 6).filter { it % 2 == 0 }23 .take(1000, RandomSource.seeded(3242344L))24 .toList().distinct().sorted() shouldContainExactly listOf(2, 4, 6, 8, 10)25 }26 test("should filter edge cases") {27 val arb = Arb.int(1..10).withEdgecases(1, 2, 3).filter { it % 2 == 0 }28 val edgeCases = arb29 .generate(RandomSource.seeded(1234L), EdgeConfig(edgecasesGenerationProbability = 1.0))30 .take(5)31 .map { it.value }32 .toList()33 edgeCases shouldContainExactly listOf(2, 2, 2, 2, 2)34 }35 test("should be stack safe") {36 val arb = object : Arb<Int>() {37 override fun edgecase(rs: RandomSource): Int? = null38 override fun sample(rs: RandomSource): Sample<Int> = Sample(rs.random.nextInt())39 }40 shouldNotThrow<StackOverflowError> {41 arb.filter { it % 2 == 0 }.take(1000000).toList()42 }43 }44 test("should apply filter to shrinks") {45 val arbEvenInts = Arb.int(-100..100).filter { it % 2 == 0 }46 val oddNumbers = (-100..100).filter { it % 2 != 0 }47 arbEvenInts.samples().take(100).forAll { sample ->48 sample.shrinks.value() shouldNotBeIn oddNumbers49 sample.shrinks.children.value.forAll {50 it.value() shouldNotBeIn oddNumbers51 }52 }53 }54 test("Arb.filter composition should not exhaust call stack") {55 var arb: Arb<Int> = Arb.of(0, 1)56 repeat(10000) {57 arb = arb.filter { it == 0 }58 }59 val result = shouldNotThrowAny { arb.single(RandomSource.seeded(1234L)) }60 result shouldBe 061 }62})...

Full Screen

Full Screen

edgecases.kt

Source:edgecases.kt Github

copy

Full Screen

1package io.kotest.property.arbitrary2import io.kotest.property.Arb3import io.kotest.property.EdgeConfig4import io.kotest.property.RandomSource5import io.kotest.property.Sample6/**7 * Randomly chooses an [Arb] and then generates an edge case from that [Arb].8 * If the chosen arb has no edge cases, then another arb will be chosen.9 * If all [Arb]s have no edge cases, then returns null.10 */11tailrec fun <A> List<Arb<A>>.edgecase(rs: RandomSource): A? {12 if (this.isEmpty()) return null13 val shuffled = this.shuffled(rs.random)14 return when (val edge = shuffled.first().edgecase(rs)) {15 null -> this.drop(1).edgecase(rs)16 else -> edge17 }18}19/**20 * Collects the edge cases from this arb.21 * Will stop after the given number of iterations.22 * This function is mainly used for testing.23 */24fun <A> Arb<A>.edgecases(iterations: Int = 100, rs: RandomSource = RandomSource.default()): Set<A> =25 generate(rs, EdgeConfig(edgecasesGenerationProbability = 1.0))26 .take(iterations)27 .map { it.value }28 .toSet()29/**30 * Returns a new [Arb] with the supplied edge cases replacing any existing edge cases.31 */32fun <A> Arb<A>.withEdgecases(edgecases: List<A>): Arb<A> = arbitrary(edgecases) { this@withEdgecases.next(it) }33/**34 * Returns a new [Arb] with the supplied edge cases replacing any existing edge cases.35 */36fun <A> Arb<A>.withEdgecases(vararg edgecases: A): Arb<A> = this.withEdgecases(edgecases.toList())37fun <A> Arb<A>.removeEdgecases(): Arb<A> = this.withEdgecases(emptyList())38/**39 * Returns a new [Arb] with the edge cases from this arb transformed by the given function [f].40 */41fun <A> Arb<A>.modifyEdgecases(f: (A) -> A?): Arb<A> = object : Arb<A>() {42 override fun edgecase(rs: RandomSource): A? = this@modifyEdgecases.edgecase(rs)?.let(f)43 override fun sample(rs: RandomSource): Sample<A> = this@modifyEdgecases.sample(rs)44}...

Full Screen

Full Screen

WithEdgecasesTest.kt

Source:WithEdgecasesTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.property.arbitrary2import io.kotest.core.spec.style.FunSpec3import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder4import io.kotest.property.arbitrary.arbitrary5import io.kotest.property.arbitrary.edgecases6import io.kotest.property.arbitrary.modifyEdgecases7import io.kotest.property.arbitrary.withEdgecases8class WithEdgecasesTest : FunSpec({9 context("Arb<A>.withEdgecases") {10 test("should override the initial edge cases") {11 val arbInt = arbitrary(listOf(1)) { it.random.nextInt() }12 arbInt.withEdgecases(2, 3).edgecases() shouldContainExactlyInAnyOrder listOf(2, 3)13 }14 test("should override the initial edge cases when specified a list") {15 val arbInt = arbitrary(listOf(1)) { it.random.nextInt() }16 arbInt.withEdgecases(listOf(2, 3)).edgecases() shouldContainExactlyInAnyOrder listOf(2, 3)17 }18 }19 context("Arb<A>.modifyEdgecases") {20 test("should modify the each edge case") {21 val arbInt = arbitrary(listOf(1, 2, 3)) { it.random.nextInt() }22 arbInt.modifyEdgecases { it * 2 }.edgecases() shouldContainExactlyInAnyOrder listOf(2, 4, 6)23 }24 }25})...

Full Screen

Full Screen

PulsarUrnTest.kt

Source:PulsarUrnTest.kt Github

copy

Full Screen

1package com.octaldata.session.pulsar2import com.octaldata.domain.topics.TopicName3import com.octaldata.domain.structure.DataRecordUrn4import io.kotest.core.spec.style.FunSpec5import io.kotest.matchers.shouldBe6import io.kotest.property.Arb7import io.kotest.property.arbitrary.positiveInt8import io.kotest.property.arbitrary.positiveLong9import io.kotest.property.arbitrary.string10import io.kotest.property.arbitrary.withEdgecases11import io.kotest.property.checkAll12class PulsarUrnTest : FunSpec({13 test("parse urn") {14 checkAll(15 100,16 Arb.string(1, 100),17 Arb.positiveInt().withEdgecases(-1),18 Arb.positiveLong().withEdgecases(-1),19 Arb.positiveLong().withEdgecases(-1),20 ) { topic, part, ledge, entryId ->21 parseUrn(DataRecordUrn("urn:pulsar:$topic:$part:$ledge:$entryId")).getOrThrow() shouldBe22 MessageIdentifier(TopicName(topic), part, ledge, entryId)23 }24 }25})...

Full Screen

Full Screen

Arb.withEdgecases

Using AI Code Generation

copy

Full Screen

1val arb = Arb.withEdgecases(1..10, listOf(1, 10))2val arb = Arb.withEdgecases(1..10, listOf(1, 10))3val arb = Arb.withEdgecases(1..10, listOf(1, 10))4val arb = Arb.withEdgecases(1..10, listOf(1, 10))5val arb = Arb.withEdgecases(1..10, listOf(1, 10))6val arb = Arb.withEdgecases(1..10, listOf(1, 10))7val arb = Arb.withEdgecases(1..10, listOf(1, 10))8val arb = Arb.withEdgecases(1..10, listOf(1, 10))9val arb = Arb.withEdgecases(1..10, listOf(1, 10))10val arb = Arb.withEdgecases(1..10, listOf(1, 10))11val arb = Arb.withEdgecases(1..10, listOf(1, 10))12val arb = Arb.withEdgecases(1..10, listOf(1, 10))13val arb = Arb.withEdgecases(1..10, listOf(1, 10

Full Screen

Full Screen

Arb.withEdgecases

Using AI Code Generation

copy

Full Screen

1val arb = Arb.withEdgecases(1..100, listOf(1, 2, 3))2val arb = Arb.withEdgecases(1..100, listOf(1, 2, 3))3val arb = Arb.withEdgecases(1..100, listOf(1, 2, 3))4val arb = Arb.withEdgecases(1..100, listOf(1, 2, 3))5val arb = Arb.withEdgecases(1..100, listOf(1, 2, 3))6val arb = Arb.withEdgecases(1..100, listOf(1, 2, 3))7val arb = Arb.withEdgecases(1..100, listOf(1, 2, 3))8val arb = Arb.withEdgecases(1..100, listOf(1, 2, 3))9val arb = Arb.withEdgecases(1..100, listOf(1, 2, 3))10val arb = Arb.withEdgecases(1..100, listOf(1, 2, 3))11val arb = Arb.withEdgecases(1..100, listOf(1, 2, 3))12val arb = Arb.withEdgecases(1..100, listOf(1, 2, 3))

Full Screen

Full Screen

Arb.withEdgecases

Using AI Code Generation

copy

Full Screen

1val arb = Arb.withEdgecases(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))2arb.take(10).forEach { println(it) }3val arb = Arb.withEdgecases(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))4arb.take(10).forEach { println(it) }5val arb = Arb.withEdgecases(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))6arb.take(10).forEach { println(it) }7val arb = Arb.withEdgecases(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))8arb.take(10).forEach { println(it) }9val arb = Arb.withEdgecases(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))10arb.take(10).forEach { println(it) }11val arb = Arb.withEdgecases(listOf(1, 2, 3, 4, 5, 6,

Full Screen

Full Screen

Arb.withEdgecases

Using AI Code Generation

copy

Full Screen

1val arb = Arb.withEdgecases ( Arb . int ( 1 .. 10 ), listOf ( 0 , 10 ))2val arb = Arb . withEdgecases ( Arb . int ( 1 .. 10 ), listOf ( 0 , 10 ))3val arb = Arb . withEdgecases ( Arb . int ( 1 .. 10 ), listOf ( 0 , 10 ))4val arb = Arb . withEdgecases ( Arb . int ( 1 .. 10 ), listOf ( 0 , 10 ))5val arb = Arb . withEdgecases ( Arb . int ( 1 .. 10 ), listOf ( 0 , 10 ))6val arb = Arb . withEdgecases ( Arb . int ( 1 .. 10 ), listOf ( 0 , 10 ))7val arb = Arb . withEdgecases ( Arb . int ( 1 .. 10 ), listOf ( 0 , 10 ))8val arb = Arb . withEdgecases ( Arb . int ( 1 .. 10 ), listOf ( 0 , 10 ))9val arb = Arb . withEdgecases ( Arb . int ( 1 .. 10 ), listOf ( 0 , 10 ))10val arb = Arb . withEdgecases ( Arb . int ( 1 .. 10 ), listOf ( 0 , 10 ))11val arb = Arb . withEdgecases ( Arb . int ( 1 .. 10 ),

Full Screen

Full Screen

Arb.withEdgecases

Using AI Code Generation

copy

Full Screen

1val arb = Arb.string().withEdgecases("a", "b", "c")2val arb = Arb.string().withEdgecases(listOf("a", "b", "c"))3val arb = Arb.string().withEdgecases(emptyList())4val arb = Arb.string().withEdgecases("a", "b", "c", listOf("d", "e", "f"))5val arb = Arb.string().withEdgecases("a", "b", "c", emptyList())6val arb = Arb.string().withEdgecases("a", "b", "c", null)7val arb = Arb.string().withEdgecases(listOf("a", "b", "c"), emptyList())8val arb = Arb.string().withEdgecases(listOf("a", "b", "c"), null)9val arb = Arb.string().withEdgecases(emptyList(), null)10val arb = Arb.string().withEdgecases("a", "b", "c", listOf("

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