Best Kotest code snippet using io.kotest.property.arbitrary.distinct.sample
FBSTreeIMCollectionTest.kt
Source:FBSTreeIMCollectionTest.kt
...123 test("fcontains (B)") {124 iiTreeOfNone.fcontains(TKVEntry.ofkv(1, 1)) shouldBe false125 Arb.fbstree(Arb.int(1..repeatsHigh.second)).checkAll(repeatsHigh.first) { fbst ->126 val ts = fbst.size127 val sample = if (1 < ts) fbst.inorder().fdrop(ts / 2).fhead()!! else null128 val aut = fbst as IMCollection<TKVEntry<Int,Int>>129 aut.fcontains(TKVEntry.ofkv(0, 0)) shouldBe false130 sample?.let { aut.fcontains(sample) shouldBe true }131 }132 }133 test("fcount") {134 iiTreeOfNone.fcount { true } shouldBe 0135 iiTreeOfNone.fcount { false } shouldBe 0136 Arb.fbstree(Arb.int(0..repeatsHigh.second)).checkAll(repeatsHigh.first) { fbst ->137 val mm = fbst.copyToMutableMap()138 val ss = mm.size // size without duplicates139 val ds = fbst.size // size with duplicates140 val aut = fbst as IMCollection<TKVEntry<Int,Int>>141 var tot = 0142 var totDups = 0143 var nonDistinct = 0144 for (entry in mm) {145 val aux = TKVEntry.ofme(entry)146 val counter = aut.fcount { it == aux }147 tot += counter148 if (fbst.fisDup(aux)) {149 nonDistinct += 1150 totDups += counter151 }152 }153 tot shouldBe ds154 (ss + totDups - nonDistinct) shouldBe ds155 }156 }157 test("dropAll (nil)") {158 nul<Int, Int>().fdropAll(FList.emptyIMList<TKVEntry<Int, Int>>()) shouldBe emptyIMBTree()159 nul<Int, Int>().fdropAll(FLCons(1.toIAEntry(), FLNil)) shouldBe emptyIMBTree()160 }161 test("fdropAll") {162 FBSTree.ofvi(1, 2, 3).fdropAll(FList.emptyIMList()) shouldBe FBSTree.ofvi(1, 2, 3)163 FBSTree.ofvi(1, 2, 3).fdropAll(FList.of(1.toIAEntry(), 2.toIAEntry())) shouldBe FBSTree.ofvi(3)164 FBSTree.ofvi(1, 2, 3).fdropAll(iiTreeOfTwo) shouldBe FBSTree.ofvi(3)165 FBSTree.ofvi(1, 2, 3, 4).fdropAll(FList.of(1.toIAEntry(), 2.toIAEntry())) shouldBe FBSTree.ofvi(3, 4)166 FBSTree.ofvi(1, 2, 3).fdropAll(FList.of(2.toIAEntry(), 3.toIAEntry())) shouldBe FBSTree.ofvi(1)167 FBSTree.ofvi(1, 2, 3, 4).fdropAll(FList.of(2.toIAEntry(), 3.toIAEntry())) shouldBe FBSTree.ofvi(1, 4)168 FBSTree.ofvi(1, 2, 3).fdropAll(FList.of(1.toIAEntry(), 3.toIAEntry())) shouldBe FBSTree.ofvi(2)169 FBSTree.ofvi(1, 2, 3, 4).fdropAll(FList.of(1.toIAEntry(), 3.toIAEntry())) shouldBe FBSTree.ofvi(2, 4)170 FBSTree.ofvi(4, 3, 1, 2).fdropAll(FList.of(1.toIAEntry(), 2.toIAEntry())).equals(FBSTree.ofvi(3, 4)) shouldBe true171 FBSTree.ofvi(4, 3, 1, 2).fdropAll(iiTreeOfTwo).equals(FBSTree.ofvi(3, 4)) shouldBe true172 }173 test("dropItem") {174 nul<Int, Int>().fdropItem(1.toIAEntry()) shouldBe emptyIMBTree()175 goDropItemAll(wikiTree, wikiPreorder, wikiInorder)176 goDropItemAll(wikiTree, wikiInorder, wikiInorder)177 goDropItemAll(wikiTree, wikiPostorder, wikiInorder)178 goDropItemAll(wikiTree, wikiPreorder.freverse(), wikiInorder)179 goDropItemAll(wikiTree, wikiInorder.freverse(), wikiInorder)180 goDropItemAll(wikiTree, wikiPostorder.freverse(), wikiInorder)181 wikiTree.fdropItem(zEntry) shouldBe wikiTree182 goDropItemTele(wikiTree, wikiPreorder, wikiInorder)183 goDropItemTele(wikiTree, wikiInorder, wikiInorder)184 goDropItemTele(wikiTree, wikiPostorder, wikiInorder)185 goDropItemTele(wikiTree, wikiPreorder.freverse(), wikiInorder)186 goDropItemTele(wikiTree, wikiInorder.freverse(), wikiInorder)187 goDropItemTele(wikiTree, wikiPostorder.freverse(), wikiInorder)188 goDropItemAll(slideShareTree, slideSharePreorder, slideShareInorder)189 goDropItemAll(slideShareTree, slideShareInorder, slideShareInorder)190 goDropItemAll(slideShareTree, slideSharePostorder, slideShareInorder)191 goDropItemAll(slideShareTree, slideShareBreadthFirst, slideShareInorder)192 goDropItemAll(slideShareTree, slideSharePreorder.freverse(), slideShareInorder)193 goDropItemAll(slideShareTree, slideShareInorder.freverse(), slideShareInorder)194 goDropItemAll(slideShareTree, slideSharePostorder.freverse(), slideShareInorder)195 goDropItemAll(slideShareTree, slideShareBreadthFirst.freverse(), slideShareInorder)196 slideShareTree.fdropItem(TKVEntry.ofIntKey(100)) shouldBe slideShareTree197 goDropItemTele(slideShareTree, slideSharePreorder, slideShareInorder)198 goDropItemTele(slideShareTree, slideShareInorder, slideShareInorder)199 goDropItemTele(slideShareTree, slideSharePostorder, slideShareInorder)200 goDropItemTele(slideShareTree, slideShareBreadthFirst, slideShareInorder)201 goDropItemTele(slideShareTree, slideSharePreorder.freverse(), slideShareInorder)202 goDropItemTele(slideShareTree, slideShareInorder.freverse(), slideShareInorder)203 goDropItemTele(slideShareTree, slideSharePostorder.freverse(), slideShareInorder)204 goDropItemTele(slideShareTree, slideShareBreadthFirst.freverse(), slideShareInorder)205 // remove only one206 val aux5a = slideShareTreeLoose.finsert(slideShareTree.fleftMost()!!)207 val aux5b = aux5a.finsert(slideShareTree.fleftMost()!!)208 IMBTreeEqual2(aux5b.fdropItem(slideShareTree.fleftMost()!!), aux5a) shouldBe true209 }210 test("ffdropItemAll") {211 nul<Int, Int>().fdropItemAll(1.toIAEntry()) shouldBe emptyIMBTree()212 (nul<Int, Int>().fdropItemAll(1.toIAEntry()) === emptyIMBTree<Int,Int>()) shouldBe true213 val aux1 = wikiTreeLoose.finsert(wikiTree.froot()!!)214 goDropItemAll(aux1, wikiPreorder, aux1.inorder())215 val aux2 = wikiTreeLoose.finsert(wikiTree.froot()!!).finsert(wikiTree.froot()!!)216 goDropItemAll(aux2, wikiPreorder, aux2.inorder())217 val aux3 = wikiTreeLoose.finsert(wikiTree.fleftMost()!!)218 goDropItemAll(aux3, wikiPreorder, aux3.inorder())219 val aux4 = wikiTreeLoose.finsert(wikiTree.frightMost()!!)220 goDropItemAll(aux4, wikiPreorder, aux4.inorder())221 val aux5 = slideShareTree.finsert(slideShareTree.fleftMost()!!).finsert(slideShareTree.fleftMost()!!)222 goDropItemAll(aux5, slideShareBreadthFirst, aux5.inorder())223 val aux6 = slideShareTree.finsert(slideShareTree.frightMost()!!).finsert(slideShareTree.frightMost()!!)224 goDropItemAll(aux6, slideShareBreadthFirst, aux6.inorder())225 }226 test("ffdropItem with dups") {227 nul<Int, Int>().fdropItem(1.toIAEntry()) shouldBe emptyIMBTree()228 (nul<Int, Int>().fdropItem(1.toIAEntry()) === emptyIMBTree<Int,Int>()) shouldBe true229 val aux1 = wikiTreeLoose.finsert(wikiTree.froot()!!)230 goDropItemTele(aux1, wikiPreorder, aux1.inorder())231 val aux2 = wikiTreeLoose.finsert(wikiTree.froot()!!).finsert(wikiTree.froot()!!)232 goDropItemTele(aux2, wikiPreorder, aux2.inorder())233 val aux3 = wikiTreeLoose.finsert(wikiTree.fleftMost()!!)234 goDropItemTele(aux3, wikiPreorder, aux3.inorder())235 val aux4 = wikiTreeLoose.finsert(wikiTree.frightMost()!!)236 goDropItemTele(aux4, wikiPreorder, aux4.inorder())237 val aux5 = slideShareTree.finsert(slideShareTree.fleftMost()!!).finsert(slideShareTree.fleftMost()!!)238 goDropItemTele(aux5, slideShareBreadthFirst, aux5.inorder())239 val aux6 = slideShareTree.finsert(slideShareTree.frightMost()!!).finsert(slideShareTree.frightMost()!!)240 goDropItemTele(aux6, slideShareBreadthFirst, aux6.inorder())241 }242 test("fdropItem (property), sorted asc") {243 checkAll(repeatsMid.first, Arb.int(repeatsMid.second..repeatsMid.third)) { n ->244 val values = Array(n) { i: Int -> TKVEntry.ofkk(i, i) }245 val ix1 = Random.nextInt(0, n)246 val fbsTree = FBSTree.of(values.iterator())247 val aut = fbsTree.fdropItem(TKVEntry.ofIntKey(ix1))248 aut.size shouldBe n - 1249 FBSTree.fbtAssertNodeInvariant(aut as FBSTNode<Int, Int>)250 val testOracle = FList.of(values.iterator())251 .ffilterNot { it == TKVEntry.ofIntKey(ix1) }252 aut.inorder() shouldBe testOracle253 }254 }255 test("fdropItem (property), sorted desc") {256 checkAll(repeatsMid.first, Arb.int(repeatsMid.second..repeatsMid.third)) { n ->257 val values = Array(n) { i: Int -> TKVEntry.ofkk(i, i) }258 val reversed = Array(n) { i: Int -> TKVEntry.ofkk(i, i) }259 reversed.reverse()260 val ix1 = Random.nextInt(0, n)261 val fbsTree = FBSTree.of(values.iterator())262 val aut = fbsTree.fdropItem(TKVEntry.ofIntKey(ix1))263 aut.size shouldBe n - 1264 FBSTree.fbtAssertNodeInvariant(aut as FBSTNode<Int, Int>)265 val testOracle = FList.of(values.iterator())266 .ffilterNot { it == TKVEntry.ofIntKey(ix1) }267 aut.inorder() shouldBe testOracle268 }269 }270 test("fdropItem (property), shuffled") {271 var count = 0272 checkAll(PropTestConfig(iterations = repeatsMid.first), Arb.int(repeatsMid.second..repeatsMid.third)) { n ->273 count += 1274 val values = Array(n) { i: Int -> TKVEntry.ofkk(i, i) }275 val shuffled = Array(n) { i: Int -> TKVEntry.ofkk(i, i) }276 val rs = RandomSource.seeded(7979028980642872582)277 shuffled.shuffle(rs.random)278 val randoms = IntArray((n/10).coerceAtLeast(3)) { i: Int -> i }279 randoms.shuffle(rs.random)280 val ix1 = randoms[0]281 val ix2 = randoms[1]282 val ix3 = randoms[2]283 val fbsTree = FBSTree.of(shuffled.iterator())284 val aux0 = fbsTree.fdropItem(TKVEntry.ofIntKey(ix1))285 if (11 == count)286 println("from test file< count=$count")287 val aux1 = aux0.fdropItem(TKVEntry.ofIntKey(ix2))288 val aut = aux1.fdropItem(TKVEntry.ofIntKey(ix3))289 aut.size shouldBe n - 3290 FBSTree.fbtAssertNodeInvariant(aut as FBSTNode<Int, Int>)291 val testOracle = FList.of(values.iterator())292 .ffilterNot { it == TKVEntry.ofIntKey(ix1) }293 .ffilterNot { it == TKVEntry.ofIntKey(ix2) }294 .ffilterNot { it == TKVEntry.ofIntKey(ix3) }295 val autInorder = aut.inorder()296 autInorder shouldBe testOracle297 }298 }299 test("fdropItem (tree property)") {300 checkAll(PropTestConfig(iterations = repeatsLow.first), Arb.fbstree(Arb.int(),repeatsLow.second..repeatsLow.third)) { fbst ->301 goDropItemTele(fbst, fbst.breadthFirst(), fbst.inorder())302 }303 }304 test("fdropItemAll (tree property)") {305 checkAll(PropTestConfig(iterations = repeatsLow.first), Arb.fbstree(Arb.int(),repeatsLow.second..repeatsLow.third)) { fbst ->306 goDropItemAll(fbst, fbst.breadthFirst(), fbst.inorder())307 }308 }309 test("fdropItem with dups (tree property)") {310 // seed = 7180391588938833052)311 checkAll(PropTestConfig(iterations = repeatsLow.first), Arb.fbstreeWithDups(Arb.int(),repeatsLow.second..repeatsLow.third)) { fbst ->312 goDropItemTele(fbst, fbst.breadthFirst(), fbst.inorder())313 }314 }315 test("fdropItemAll with dups (tree property)") {316 checkAll(PropTestConfig(iterations = repeatsLow.first), Arb.fbstreeWithDups(Arb.int(),repeatsLow.second..repeatsLow.third)) { fbst ->317 goDropItemAll(fbst, fbst.breadthFirst(), fbst.inorder())318 }319 }320 test("fempty") {321 iiTreeOfNone.fempty() shouldBe true322 FBSTGeneric.empty.fempty() shouldBe true323 FBSTUnique.empty.fempty() shouldBe true324 FBSTree.ofvi(1).fempty() shouldBe false325 }326 test("ffilter, filterNot (nil)") {327 nul<Int, Int>().ffilter { true } shouldBe FRBTree.emptyIMBTree()328 (nul<Int, Int>().ffilter { true } === emptyIMBTree<Int,Int>()) shouldBe true329 (nul<Int, Int>().ffilter { true } === FRBTree.emptyIMBTree<Int,Int>()) shouldBe false330 nul<Int, Int>().ffilterNot { false } shouldBe FRBTree.emptyIMBTree()331 }332 test ("ffilter (A), ffilterNot, dropWhen") {333 fun pickIfLess(n: Int): (TKVEntry<Int, Int>) -> Boolean = { it.getv() < n }334 fun pickIfMore(n: Int): (TKVEntry<Int, Int>) -> Boolean = { n < it.getv() }335 checkAll(repeatsHigh.first, Arb.int(20..repeatsHigh.second)) { n ->336 val values = Array(n) { i: Int -> TKVEntry.ofkk(i, i) }337 val svalues = values + values338 val ora1 = values.size339 svalues.size shouldBe (ora1 * 2)340 val tree: IMCollection<TKVEntry<Int,Int>> = FBSTree.of(svalues.iterator())341 tree.fsize() shouldBe ora1342 val sAll1 = tree.ffilter(pickIfLess(ora1))343 val snAll1 = tree.ffilterNot(pickIfLess(ora1))344 snAll1.fsize() shouldBe 0345 sAll1.fsize() shouldBe ora1346 snAll1.equals(tree.fdropWhen(pickIfLess(ora1))) shouldBe true347 val sEmpty1 = tree.ffilter(pickIfMore(ora1))348 val snEmpty1 = tree.ffilterNot(pickIfMore(ora1))349 sEmpty1.fsize() shouldBe 0350 snEmpty1.fsize() shouldBe ora1351 snEmpty1.equals(tree.fdropWhen(pickIfMore(ora1))) shouldBe true352 val ora2 = ora1 / 2353 val theRestSansOra2 = (ora1 - ora2) - 1354 val sAll2 = tree.ffilter(pickIfLess(ora2))355 val snAll2 = tree.ffilterNot(pickIfLess(ora2))356 sAll2.fsize() shouldBe ora2357 snAll2.fsize() shouldBe theRestSansOra2 + 1358 snAll2.equals(tree.fdropWhen(pickIfLess(ora2))) shouldBe true359 val sEmpty2 = tree.ffilter(pickIfMore(ora2))360 val snEmpty2 = tree.ffilterNot(pickIfMore(ora2))361 sEmpty2.fsize() shouldBe theRestSansOra2362 snEmpty2.fsize() shouldBe ora1 - theRestSansOra2363 snEmpty2.equals(tree.fdropWhen(pickIfMore(ora2))) shouldBe true364 }365 }366 test ("ffilter (B)") {367 fun pickIfLess(n: Int): (TKVEntry<Int, Int>) -> Boolean = { it.getv() < n }368 fun pickIfMore(n: Int): (TKVEntry<Int, Int>) -> Boolean = { n < it.getv() }369 checkAll(repeatsHigh.first, Arb.int(20..repeatsHigh.second)) { n ->370 val shuffled = Array(n) { i: Int -> TKVEntry.ofkk(i, i) }371 shuffled.shuffle()372 val svalues = shuffled + shuffled373 val ora1 = shuffled.size374 svalues.size shouldBe (ora1 * 2)375 val tree: IMCollection<TKVEntry<Int,Int>> = FBSTree.of(svalues.iterator())376 tree.fsize() shouldBe ora1377 val sAll1 = tree.ffilter(pickIfLess(ora1))378 sAll1.fsize() shouldBe ora1379 val sEmpty1 = tree.ffilter(pickIfMore(ora1))380 sEmpty1.fsize() shouldBe 0381 val ora2 = ora1 / 2382 val theRestSansOra2 = (ora1 - ora2) - 1383 val sAll2 = tree.ffilter(pickIfLess(ora2))384 sAll2.fsize() shouldBe ora2385 val sEmpty2 = tree.ffilter(pickIfMore(ora2))386 sEmpty2.fsize() shouldBe theRestSansOra2387 }388 }389 test ("ffilter (C)") {390 fun pickIfLess(n: Int): (TKVEntry<Int, Int>) -> Boolean = { it.getv() < n }391 fun pickIfMore(n: Int): (TKVEntry<Int, Int>) -> Boolean = { n < it.getv() }392 checkAll(repeatsHigh.first, Arb.int(20..repeatsHigh.second)) { n ->393 val reversed = Array(n) { i: Int -> TKVEntry.ofkk(i, i) }394 reversed.reverse()395 val svalues = reversed + reversed396 val ora1 = reversed.size397 svalues.size shouldBe (ora1 * 2)398 val tree: IMCollection<TKVEntry<Int,Int>> = FBSTree.of(svalues.iterator())399 tree.fsize() shouldBe ora1400 val sAll1 = tree.ffilter(pickIfLess(ora1))401 sAll1.fsize() shouldBe ora1402 val sEmpty1 = tree.ffilter(pickIfMore(ora1))403 sEmpty1.fsize() shouldBe 0404 val ora2 = ora1 / 2405 val theRestSansOra2 = (ora1 - ora2) - 1406 val sAll2 = tree.ffilter(pickIfLess(ora2))407 sAll2.fsize() shouldBe ora2408 val sEmpty2 = tree.ffilter(pickIfMore(ora2))409 sEmpty2.fsize() shouldBe theRestSansOra2410 }411 }412 test("ffindAny") {413 iiTreeOfNone.ffindAny { true } shouldBe null414 iiTreeOfNone.ffindAny { false } shouldBe null415 Arb.fbstree(Arb.int(1..repeatsHigh.second)).checkAll(repeatsHigh.first) { fbst ->416 val ts = fbst.size417 var count: Int = 0418 fbst.ffindAny{ count+=1; it == TKVEntry.ofkv(0, 0) } shouldBe null419 count shouldBe ts420 count = 0421 fbst.ffindAny{ count+=1; it > TKVEntry.ofkv(0, 0) } shouldNotBe null422 count shouldBe 1423 count = 0424 fbst.ffindAny{ count+=1; it > repeatsHigh.second.toIAEntry() } shouldBe null425 count shouldBe ts426 count = 0427 fbst.ffindAny{ count+=1; it <= repeatsHigh.second.toIAEntry() } shouldNotBe null428 count shouldBe 1429 count = 0430 if (1 < ts) {431 val sample = fbst.inorder().fdrop(ts / 2).fhead()!!432 count = 0433 fbst.ffindAny{ count+=1; it == sample } shouldNotBe null434 (count >= 1) shouldBe true435 (count <= ts) shouldBe true436 }437 }438 }439 test("ffindAny (B)") {440 tailrec fun <A: Comparable<A>, B: Any> go(t: FBSTree<A, B>, acc: FList<TKVEntry<A, B>>): FList<A> =441 when (acc) {442 is FLNil -> FLNil443 is FLCons -> {444 if (t.ffindAny{ it == acc.head }?.let{ itAny -> itAny == acc.head } != true) fail("not found: ${acc.head}")445 go(t, acc.tail)446 }447 }...
FRBTreeIMCollectionTest.kt
Source:FRBTreeIMCollectionTest.kt
...107 test("fcontains") {108 iiTreeOfNone.fcontains(TKVEntry.ofkv(1, 1)) shouldBe false109 Arb.frbtree(Arb.int(1..repeatsHigh.second)).checkAll(repeatsHigh.first) { frbt ->110 val ts = frbt.size111 val sample = if (1 < ts) frbt.inorder().fdrop(ts / 2).fhead()!! else null112 val aut = frbt as IMCollection<TKVEntry<Int,Int>>113 aut.fcontains(TKVEntry.ofkv(0, 0)) shouldBe false114 sample?.let { aut.fcontains(sample) shouldBe true }115 }116 }117 test("fcount") {118 iiTreeOfNone.fcount { true } shouldBe 0119 iiTreeOfNone.fcount { false } shouldBe 0120 Arb.frbtree(Arb.int(0..repeatsHigh.second)).checkAll(repeatsHigh.first) { frbt ->121 val mm = frbt.copyToMutableMap()122 val ss = mm.size // size without duplicates123 val ds = frbt.size // size with duplicates124 val aut = frbt as IMCollection<TKVEntry<Int,Int>>125 var tot = 0126 var totDups = 0127 var nonDistinct = 0128 for (entry in mm) {129 val aux = TKVEntry.ofme(entry)130 val counter = aut.fcount { it == aux }131 tot += counter132 if (frbt.fisDup(aux)) {133 nonDistinct += 1134 totDups += counter135 }136 }137 tot shouldBe ds138 (ss + totDups - nonDistinct) shouldBe ds139 }140 }141 test("dropAll (nil)") {142 FBSTree.nul<Int, Int>().fdropAll(FList.emptyIMList<TKVEntry<Int, Int>>()) shouldBe FRBTree.emptyIMBTree()143 FBSTree.nul<Int, Int>().fdropAll(FLCons(1.toIAEntry(), FLNil)) shouldBe FRBTree.emptyIMBTree()144 }145 test("fdropAll") {146 FRBTree.ofvi(1, 2, 3).fdropAll(FList.emptyIMList()) shouldBe FRBTree.ofvi(1, 2, 3)147 FRBTree.ofvi(1, 2, 3).fdropAll(FList.of(1.toIAEntry(), 2.toIAEntry())) shouldBe FRBTree.ofvi(3)148 FRBTree.ofvi(1, 2, 3).fdropAll(iiTreeOfTwo) shouldBe FRBTree.ofvi(3)149 FRBTree.ofvi(1, 2, 3, 4).fdropAll(FList.of(1.toIAEntry(), 2.toIAEntry())) shouldBe FRBTree.ofvi(3, 4)150 FRBTree.ofvi(1, 2, 3).fdropAll(FList.of(2.toIAEntry(), 3.toIAEntry())) shouldBe FRBTree.ofvi(1)151 FRBTree.ofvi(1, 2, 3, 4).fdropAll(FList.of(2.toIAEntry(), 3.toIAEntry())) shouldBe FRBTree.ofvi(1, 4)152 FRBTree.ofvi(1, 2, 3).fdropAll(FList.of(1.toIAEntry(), 3.toIAEntry())) shouldBe FRBTree.ofvi(2)153 FRBTree.ofvi(1, 2, 3, 4).fdropAll(FList.of(1.toIAEntry(), 3.toIAEntry())) shouldBe FRBTree.ofvi(2, 4)154 FRBTree.ofvi(4, 3, 1, 2).fdropAll(FList.of(1.toIAEntry(), 2.toIAEntry())).equals(FRBTree.ofvi(3, 4)) shouldBe true155 FRBTree.ofvi(4, 3, 1, 2).fdropAll(iiTreeOfTwo).equals(FRBTree.ofvi(3, 4)) shouldBe true156 }157 test("fdropItem") {158 FRBTree.nul<Int, Int>().fdropItem(1.toIAEntry()) shouldBe FRBTree.emptyIMBTree()159 tailrec fun goAllWiki(frb: FRBTree<Int, String>, acc: FList<TKVEntry<Int, String>>, inorder: FList<TKVEntry<Int, String>>): FList<TKVEntry<Int, String>> =160 when (acc) {161 is FLNil -> FLNil162 is FLCons -> {163 val rbDeleted: RBTree<Int, String> = rbWikiTree.copy()164 rbDeleted.rbDelete(TKVEntry.ofkv(acc.head.getk(), acc.head.getv()))165 when (val deleted = frb.fdropItem(acc.head)) {166 is FRBTNode -> {167 FRBTree.rbRootInvariant(deleted) shouldBe true168 val aut1in = deleted.inorder()169 val oracle = inorder.ffilterNot { it == acc.head }170 aut1in shouldBe oracle171 IMBTreeUtility.strongEqual(deleted, rbDeleted) shouldBe true172 }173 is FRBTNil -> {174 true shouldBe false175 }176 }177 goAllWiki(frb, acc.tail, inorder)178 }179 }180 // tailrec fun <A: Comparable<A>, B: Any> goAllSS(frb: FRBTree<A,B>, acc: FList<TKVEntry<A,B>>, inorder: FList<TKVEntry<A,B>>): FList<TKVEntry<A,B>> =181 tailrec fun goAllSS(frb: FRBTree<Int, Int>, acc: FList<TKVEntry<Int, Int>>, inorder: FList<TKVEntry<Int, Int>>): FList<TKVEntry<Int, Int>> =182 when (acc) {183 is FLNil -> FLNil184 is FLCons -> {185 val rbDeleted: RBTree<Int, Int> = rbSlideShareTree.copy()186 rbDeleted.rbDelete(TKVEntry.ofkk(acc.head.getk(), acc.head.getv()))187 when (val deleted = frb.fdropItem(acc.head)) {188 is FRBTNode -> {189 FRBTree.rbRootInvariant(deleted) shouldBe true190 val aut1in = deleted.inorder()191 val oracle = inorder.ffilterNot { it == acc.head }192 aut1in shouldBe oracle193 IMBTreeUtility.strongEqual(deleted, rbDeleted) shouldBe true194 }195 is FRBTNil -> {196 true shouldBe false197 }198 }199 goAllSS(frb, acc.tail, inorder)200 }201 }202 tailrec fun <A: Comparable<A>, B: Any> goTele(t: FRBTree<A, B>, rbDeleted: RBTree<A, B>, acc: FList<TKVEntry<A, B>>, inorder: FList<TKVEntry<A, B>>): FList<TKVEntry<A, B>> =203 when (acc) {204 is FLNil -> FLNil205 is FLCons -> {206 rbDeleted.rbDelete(acc.head)207 val deleted = t.fdropItem(acc.head)208 val oracle = inorder.ffilterNot { it == acc.head }209 when (deleted) {210 is FRBTNode -> {211 FRBTree.rbRootInvariant(deleted) shouldBe true212 val aut1in = deleted.inorder()213 aut1in shouldBe oracle214 IMBTreeUtility.strongEqual(deleted, rbDeleted) shouldBe true215 }216 is FRBTNil -> {217 deleted.size shouldBe 0218 rbDeleted.size() shouldBe 0219 }220 }221 goTele(deleted, rbDeleted, acc.tail, oracle)222 }223 }224 goAllWiki(frbWikiTree, frbWikiPreorder, frbWikiInorder)225 goAllWiki(frbWikiTree, frbWikiPostorder, frbWikiInorder)226 goAllWiki(frbWikiTree, frbWikiInorder, frbWikiInorder)227 goAllWiki(frbWikiTree, frbWikiBreadthFirst, frbWikiInorder)228 goAllWiki(frbWikiTree, frbWikiPreorder.freverse(), frbWikiInorder)229 goAllWiki(frbWikiTree, frbWikiPostorder.freverse(), frbWikiInorder)230 goAllWiki(frbWikiTree, frbWikiInorder.freverse(), frbWikiInorder)231 goAllWiki(frbWikiTree, frbWikiBreadthFirst.freverse(), frbWikiInorder)232 var rbMutable = rbWikiTree.copy()233 goTele(frbWikiTree, rbMutable, frbWikiPreorder, frbWikiInorder)234 rbMutable = rbWikiTree.copy()235 goTele(frbWikiTree, rbMutable, frbWikiPostorder, frbWikiInorder)236 rbMutable = rbWikiTree.copy()237 goTele(frbWikiTree, rbMutable, frbWikiInorder, frbWikiInorder)238 rbMutable = rbWikiTree.copy()239 goTele(frbWikiTree, rbMutable, frbWikiBreadthFirst, frbWikiInorder)240 rbMutable = rbWikiTree.copy()241 goTele(frbWikiTree, rbMutable, frbWikiPreorder.freverse(), frbWikiInorder)242 rbMutable = rbWikiTree.copy()243 goTele(frbWikiTree, rbMutable, frbWikiPostorder.freverse(), frbWikiInorder)244 rbMutable = rbWikiTree.copy()245 goTele(frbWikiTree, rbMutable, frbWikiInorder.freverse(), frbWikiInorder)246 rbMutable = rbWikiTree.copy()247 goTele(frbWikiTree, rbMutable, frbWikiBreadthFirst.freverse(), frbWikiInorder)248 frbWikiTree.fdropItem(zEntry) shouldBe frbWikiTree249 goAllSS(frbSlideShareTree, frbSlideSharePreorder, frbSlideShareInorder)250 goAllSS(frbSlideShareTree, frbSlideSharePostorder, frbSlideShareInorder)251 goAllSS(frbSlideShareTree, frbSlideShareInorder, frbSlideShareInorder)252 goAllSS(frbSlideShareTree, frbSlideShareBreadthFirst, frbSlideShareInorder)253 goAllSS(frbSlideShareTree, frbSlideSharePreorder.freverse(), frbSlideShareInorder)254 goAllSS(frbSlideShareTree, frbSlideSharePostorder.freverse(), frbSlideShareInorder)255 goAllSS(frbSlideShareTree, frbSlideShareInorder.freverse(), frbSlideShareInorder)256 goAllSS(frbSlideShareTree, frbSlideShareBreadthFirst.freverse(), frbSlideShareInorder)257 var rbMutableSs = rbSlideShareTree.copy()258 goTele(frbSlideShareTree, rbMutableSs, frbSlideSharePreorder, frbSlideShareInorder)259 rbMutableSs = rbSlideShareTree.copy()260 goTele(frbSlideShareTree, rbMutableSs, frbSlideSharePostorder, frbSlideShareInorder)261 rbMutableSs = rbSlideShareTree.copy()262 goTele(frbSlideShareTree, rbMutableSs, frbSlideShareInorder, frbSlideShareInorder)263 rbMutableSs = rbSlideShareTree.copy()264 goTele(frbSlideShareTree, rbMutableSs, frbSlideShareBreadthFirst, frbSlideShareInorder)265 rbMutableSs = rbSlideShareTree.copy()266 goTele(frbSlideShareTree, rbMutableSs, frbSlideSharePreorder.freverse(), frbSlideShareInorder)267 rbMutableSs = rbSlideShareTree.copy()268 goTele(frbSlideShareTree, rbMutableSs, frbSlideSharePostorder.freverse(), frbSlideShareInorder)269 rbMutableSs = rbSlideShareTree.copy()270 goTele(frbSlideShareTree, rbMutableSs, frbSlideShareInorder.freverse(), frbSlideShareInorder)271 rbMutableSs = rbSlideShareTree.copy()272 goTele(frbSlideShareTree, rbMutableSs, frbSlideShareBreadthFirst.freverse(), frbSlideShareInorder)273 frbSlideShareTree.fdropItem(TKVEntry.ofIntKey(100)) shouldBe frbSlideShareTree274 }275 test("fdropItem (property), sorted asc") {276 checkAll(repeatsMid.first, Arb.int(30..repeatsMid.second)) { n ->277 val values = Array(n) { i: Int -> TKVEntry.ofkk(i, i) }278 val ix1 = Random.nextInt(0, n)279 val frbTree = FRBTree.of(values.iterator())280 val aut = frbTree.fdropItem(TKVEntry.ofIntKey(ix1))281 aut.size shouldBe n - 1282 FRBTree.rbRootInvariant(aut) shouldBe true283 val testOracle = FList.of(values.iterator())284 .ffilterNot { it == TKVEntry.ofIntKey(ix1) }285 aut.inorder() shouldBe testOracle286 }287 }288 test("fdropItem (property), sorted desc") {289 checkAll(repeatsMid.first, Arb.int(30..repeatsMid.second)) { n ->290 val values = Array(n) { i: Int -> TKVEntry.ofkk(i, i) }291 val reversed = Array(n) { i: Int -> TKVEntry.ofkk(i, i) }292 reversed.reverse()293 val ix1 = Random.nextInt(0, n)294 val frbTree = FRBTree.of(values.iterator())295 val aut = frbTree.fdropItem(TKVEntry.ofIntKey(ix1))296 aut.size shouldBe n - 1297 FRBTree.rbRootInvariant(aut) shouldBe true298 val testOracle = FList.of(values.iterator())299 .ffilterNot { it == TKVEntry.ofIntKey(ix1) }300 aut.inorder() shouldBe testOracle301 }302 }303 test("fdropItem (property), shuffled") {304 checkAll(PropTestConfig(iterations = repeatsMid.first), Arb.int(30..repeatsMid.second)) { n ->305 val values = Array(n) { i: Int -> TKVEntry.ofkk(i, i) }306 val shuffled = Array(n) { i: Int -> TKVEntry.ofkk(i, i) }307 val rs = RandomSource.seeded(7979028980642872582)308 shuffled.shuffle(rs.random)309 val randoms = IntArray(n/10) { i: Int -> i }310 randoms.shuffle(rs.random)311 val ix1 = randoms[0]312 val ix2 = randoms[1]313 val ix3 = randoms[2]314 val frbTree = FRBTree.of(shuffled.iterator())315 val aux0 = frbTree.fdropItem(TKVEntry.ofIntKey(ix1))316 val aux1 = aux0.fdropItem(TKVEntry.ofIntKey(ix2))317 val aut = aux1.fdropItem(TKVEntry.ofIntKey(ix3))318 aut.size shouldBe n - 3319 FRBTree.rbRootInvariant(aut) shouldBe true320 val testOracle = FList.of(values.iterator())321 .ffilterNot { it == TKVEntry.ofIntKey(ix1) }322 .ffilterNot { it == TKVEntry.ofIntKey(ix2) }323 .ffilterNot { it == TKVEntry.ofIntKey(ix3) }324 val autInorder = aut.inorder()325 autInorder shouldBe testOracle326 goDropItemTele(aut, aut.breadthFirst(), autInorder)327 }328 }329 test("fempty") {330 iiTreeOfNone.fempty() shouldBe true331 FRBTNil.fempty() shouldBe true332 FRBTree.ofvi(1).fempty() shouldBe false333 }334 test("ffilter, filterNot (nil)") {335 nul<Int, Int>().ffilter { true } shouldBe emptyIMBTree()336 (nul<Int, Int>().ffilter { true } === emptyIMBTree<Int,Int>()) shouldBe true337 nul<Int, Int>().ffilterNot { false } shouldBe emptyIMBTree()338 }339 test ("ffilter (A), ffilterNot, dropWhen") {340 fun pickIfLess(n: Int): (TKVEntry<Int, Int>) -> Boolean = { it.getv() < n }341 fun pickIfMore(n: Int): (TKVEntry<Int, Int>) -> Boolean = { n < it.getv() }342 checkAll(repeatsHigh.first, Arb.int(20..repeatsHigh.second)) { n ->343 val values = Array(n) { i: Int -> TKVEntry.ofkk(i, i) }344 val svalues = values + values345 val ora1 = values.size346 svalues.size shouldBe (ora1 * 2)347 val tree: IMCollection<TKVEntry<Int,Int>> = FRBTree.of(svalues.iterator())348 tree.fsize() shouldBe ora1349 val sAll1 = tree.ffilter(pickIfLess(ora1))350 val snAll1 = tree.ffilterNot(pickIfLess(ora1))351 snAll1.fsize() shouldBe 0352 sAll1.fsize() shouldBe ora1353 snAll1.equals(tree.fdropWhen(pickIfLess(ora1))) shouldBe true354 val sEmpty1 = tree.ffilter(pickIfMore(ora1))355 val snEmpty1 = tree.ffilterNot(pickIfMore(ora1))356 sEmpty1.fsize() shouldBe 0357 snEmpty1.fsize() shouldBe ora1358 snEmpty1.equals(tree.fdropWhen(pickIfMore(ora1))) shouldBe true359 val ora2 = ora1 / 2360 val theRestSansOra2 = (ora1 - ora2) - 1361 val sAll2 = tree.ffilter(pickIfLess(ora2))362 val snAll2 = tree.ffilterNot(pickIfLess(ora2))363 sAll2.fsize() shouldBe ora2364 snAll2.fsize() shouldBe theRestSansOra2 + 1365 snAll2.equals(tree.fdropWhen(pickIfLess(ora2))) shouldBe true366 val sEmpty2 = tree.ffilter(pickIfMore(ora2))367 val snEmpty2 = tree.ffilterNot(pickIfMore(ora2))368 sEmpty2.fsize() shouldBe theRestSansOra2369 snEmpty2.fsize() shouldBe ora1 - theRestSansOra2370 snEmpty2.equals(tree.fdropWhen(pickIfMore(ora2))) shouldBe true371 }372 }373 test ("ffilter (B)") {374 fun pickIfLess(n: Int): (TKVEntry<Int, Int>) -> Boolean = { it.getv() < n }375 fun pickIfMore(n: Int): (TKVEntry<Int, Int>) -> Boolean = { n < it.getv() }376 checkAll(repeatsHigh.first, Arb.int(20..repeatsHigh.second)) { n ->377 val shuffled = Array(n) { i: Int -> TKVEntry.ofkk(i, i) }378 shuffled.shuffle()379 val svalues = shuffled + shuffled380 val ora1 = shuffled.size381 svalues.size shouldBe (ora1 * 2)382 val tree: IMCollection<TKVEntry<Int,Int>> = FRBTree.of(svalues.iterator())383 tree.fsize() shouldBe ora1384 val sAll1 = tree.ffilter(pickIfLess(ora1))385 sAll1.fsize() shouldBe ora1386 val sEmpty1 = tree.ffilter(pickIfMore(ora1))387 sEmpty1.fsize() shouldBe 0388 val ora2 = ora1 / 2389 val theRestSansOra2 = (ora1 - ora2) - 1390 val sAll2 = tree.ffilter(pickIfLess(ora2))391 sAll2.fsize() shouldBe ora2392 val sEmpty2 = tree.ffilter(pickIfMore(ora2))393 sEmpty2.fsize() shouldBe theRestSansOra2394 }395 }396 test ("ffilter (C)") {397 fun pickIfLess(n: Int): (TKVEntry<Int, Int>) -> Boolean = { it.getv() < n }398 fun pickIfMore(n: Int): (TKVEntry<Int, Int>) -> Boolean = { n < it.getv() }399 checkAll(repeatsHigh.first, Arb.int(20..repeatsHigh.second)) { n ->400 val reversed = Array(n) { i: Int -> TKVEntry.ofkk(i, i) }401 reversed.reverse()402 val svalues = reversed + reversed403 val ora1 = reversed.size404 svalues.size shouldBe (ora1 * 2)405 val tree: IMCollection<TKVEntry<Int,Int>> = FRBTree.of(svalues.iterator())406 tree.fsize() shouldBe ora1407 val sAll1 = tree.ffilter(pickIfLess(ora1))408 sAll1.fsize() shouldBe ora1409 val sEmpty1 = tree.ffilter(pickIfMore(ora1))410 sEmpty1.fsize() shouldBe 0411 val ora2 = ora1 / 2412 val theRestSansOra2 = (ora1 - ora2) - 1413 val sAll2 = tree.ffilter(pickIfLess(ora2))414 sAll2.fsize() shouldBe ora2415 val sEmpty2 = tree.ffilter(pickIfMore(ora2))416 sEmpty2.fsize() shouldBe theRestSansOra2417 }418 }419 test("ffindAny") {420 iiTreeOfNone.ffindAny { true } shouldBe null421 iiTreeOfNone.ffindAny { false } shouldBe null422 Arb.frbtree(Arb.int(1..repeatsHigh.second)).checkAll(repeatsHigh.first) { frbt ->423 val ts = frbt.size424 var count: Int = 0425 frbt.ffindAny{ count+=1; it == TKVEntry.ofkv(0, 0) } shouldBe null426 count shouldBe ts427 count = 0428 frbt.ffindAny{ count+=1; it > TKVEntry.ofkv(0, 0) } shouldNotBe null429 count shouldBe 1430 count = 0431 frbt.ffindAny{ count+=1; it > repeatsHigh.second.toIAEntry() } shouldBe null432 count shouldBe ts433 count = 0434 frbt.ffindAny{ count+=1; it <= repeatsHigh.second.toIAEntry() } shouldNotBe null435 count shouldBe 1436 count = 0437 if (1 < ts) {438 val sample = frbt.inorder().fdrop(ts / 2).fhead()!!439 count = 0440 frbt.ffindAny{ count+=1; it == sample } shouldNotBe null441 (count >= 1) shouldBe true442 (count <= ts) shouldBe true443 }444 }445 }446 test("fisStrict") {447 iiTreeOfNone.fisStrict() shouldBe true448 iiTreeOfTwo.fisStrict() shouldBe true449 ixTreeOfTwo.fisStrict() shouldBe false450 ixxTreeOfTwo.fisStrict() shouldBe false451 iyxTreeOfTwo.fisStrict() shouldBe true452 ixxsTreeOfTwo.fisStrict() shouldBe false453 ixxmTreeOfTwo.fisStrict() shouldBe false454 imTreeOfTwoA.fisStrict() shouldBe false...
GraphProperties.kt
Source:GraphProperties.kt
...173 }.toPersistentMap()174 }175val Arb.Companion.graphWithPairOfVertices176 get() = arbitrary { rs ->177 val graph = connectedGraph.sample(rs)178 val from = Arb.int(0 until graph.value.size).next(rs)179 val to = Arb.int(0 until graph.value.size).filter { it != from }.next(rs)180 graph.value to (from to to)181 }182val Arb.Companion.graphWithSubgraph: Arb<Pair<Graph<Int>, Graph<Int>>>183 get() = arbitrary { rs ->184 connectedGraph.sample(rs).let { graph ->185 graph.value to graph.value.mutate { g ->186 val subgraphSize = Arb.int(4 until graph.value.size).next(rs)187 g.keys.removeIf { it >= subgraphSize }188 g.replaceAll { _, v -> v.mutate { it.keys.removeIf { it >= subgraphSize } } }189 }190 }191 }...
collections.kt
Source:collections.kt
...58 set.add(genIter.next().value)59 if (set.size == size) iterations++60 }61 check(set.size == targetSize) {62 "the target size requirement of $targetSize could not be satisfied after $iterations consecutive samples"63 }64 set65 }66}67/**68 * Returns an [Arb] which returns lists that contain values generated by the given generator.69 * The size of each list is determined randomly within the specified [range].70 *71 * The edge cases are the empty list, if the range includes zero, and a list with a repeated element (taken72 * as the first edge case from the underlying gen).73 *74 * Shrinking is performed by removing elements from the list until the empty list is reached.75 */76@JvmOverloads77fun <A> Arb.Companion.list(gen: Gen<A>, range: IntRange = 0..100): Arb<List<A>> {78 check(!range.isEmpty())79 check(range.first >= 0)80 return arbitrary(81 edgecaseFn = { rs ->82 val emptyList = emptyList<A>()83 val singleList: List<A>? = when (gen) {84 is Arb -> (gen.edgecase(rs) ?: gen.next(rs))?.let { listOf(it) }85 is Exhaustive -> gen.values.firstOrNull()?.let { listOf(it) }86 }87 val repeatedList: List<A>? = when {88 range.last < 2 -> null // too small for repeats89 gen is Arb -> (gen.edgecase(rs) ?: gen.next(rs))?.let { a -> List(max(2, range.first)) { a } }90 gen is Exhaustive -> gen.values.firstOrNull()?.let { a -> List(max(2, range.first)) { a } }91 else -> null92 }93 listOfNotNull(emptyList, singleList, repeatedList).filter { it.size in range }.distinct().random(rs.random)94 },95 shrinker = ListShrinker(range),96 sampleFn = { rs ->97 val targetSize = rs.random.nextInt(range)98 gen.generate(rs).take(targetSize).toList().map { it.value }99 }100 )101}102/**103 * Returns an [Arb] whose of values are a list of values generated by the current arb.104 * The size of each list is determined randomly by the specified [size].105 *106 * Shrinking is performed by removing elements from the list until the empty list.107 *108 * This function is a convenience for Arb.list(gen, range)109 *110 * @param size minimum and maximum number of items in the lists produced by the returned [Arb]...
FilterTest.kt
Source:FilterTest.kt
...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})...
gen.kt
Source:gen.kt
...6 require(1 <= tokenTypes)7 require(1 <= ruleTypes)8 return arbitrary { rs ->9 val names = string(minSize = 1, maxSize = 15)10 .samples(rs)11 .distinct()12 .take(tokenTypes + ruleTypes)13 .mapIndexed { index, it -> index to it.value }14 .toList()15 val tokens = names.takeLast(tokenTypes).map { (index, name) -> TokenType(index, name) }16 val rules = names.take(ruleTypes).map { (index, name) -> RuleType(index, name) }17 NodeTypePool.of(18 grammarName = string(minSize = 1, maxSize = 10).sample(rs).value,19 tokenTypes = tokens,20 ruleTypes = rules21 )22 }23}...
distinct.kt
Source:distinct.kt
...6@DelicateKotest7fun <A> Arb<A>.distinct(attempts: Int = 100) = object : Arb<A>() {8 private val seen = mutableSetOf<A>()9 override fun edgecase(rs: RandomSource): A? = this@distinct.edgecase(rs)10 override fun sample(rs: RandomSource): Sample<A> {11 var iterations = 012 return generateSequence {13 if (iterations++ < attempts) this@distinct.sample(rs) else null14 }.filter { seen.add(it.value) }.first()15 }16}...
sample
Using AI Code Generation
1+import io.kotest.assertions.throwables.shouldThrow2+import io.kotest.core.spec.style.StringSpec3+import io.kotest.matchers.shouldBe4+import io.kotest.property.Arb5+import io.kotest.property.arbitrary.distinct6+import io.kotest.property.arbitrary.int7+import io.kotest.property.arbitrary.string8+class DistinctTest : StringSpec({9+ "distinct sample" {10+ val arb = Arb.int(0..10).distinct()11+ arb.values().take(100).toSet().size shouldBe 1112+ }13+ "distinct should fail if size is greater than max" {14+ val arb = Arb.int(0..10).distinct()15+ shouldThrow<IllegalArgumentException> {16+ arb.values().take(20).toSet().size shouldBe 1117+ }18+ }19+ "distinct should fail if size is greater than max" {20+ val arb = Arb.string().distinct()21+ shouldThrow<IllegalArgumentException> {22+ arb.values().take(20).toSet().size shouldBe 1123+ }24+ }25+})26+import io.kotest.assertions.throwables.shouldThrow27+import io.kotest.core.spec.style.StringSpec28+import io.kotest.matchers.shouldBe29+import io.kotest.property.Arb30+import io.kotest.property.arbitrary.distinctBy31+import io.kotest.property.arbitrary.int32+import io.kotest.property.arbitrary.string33+class DistinctByTest : StringSpec({34+ "distinctBy sample" {35+ val arb = Arb.int(0..10).distinctBy { it % 2 }36+ arb.values().take(100).toSet().size shouldBe 237+ }38+ "distinctBy should fail if size is greater than max" {39+ val arb = Arb.int(0..10).distinctBy { it % 2 }40+ shouldThrow<IllegalArgumentException> {41+ arb.values().take(20).toSet().size shouldBe 242+ }43+ }
sample
Using AI Code Generation
1fun distinctSample() {2 val distinctInts = Arb.distinct(Arb.int())3 val distinctInts1 = Arb.distinct(Arb.int(), 3)4 val distinctInts2 = Arb.distinct(Arb.int(), 3, 4)5 val distinctInts3 = Arb.distinct(Arb.int(), 3, 4, 5)6 val distinctInts4 = Arb.distinct(Arb.int(), 3, 4, 5, 6)7 val distinctInts5 = Arb.distinct(Arb.int(), 3, 4, 5, 6, 7)8 val distinctInts6 = Arb.distinct(Arb.int(), 3, 4, 5, 6, 7, 8)9 val distinctInts7 = Arb.distinct(Arb.int(), 3, 4, 5, 6, 7, 8, 9)10 val distinctInts8 = Arb.distinct(Arb.int(), 3, 4, 5, 6, 7, 8, 9, 10)11 val distinctInts9 = Arb.distinct(Arb.int(), 3, 4, 5, 6, 7, 8, 9, 10, 11)12 val distinctInts10 = Arb.distinct(Arb.int(), 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)13 val distinctInts11 = Arb.distinct(Arb.int(), 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)14 val distinctInts12 = Arb.distinct(Arb.int(), 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)15 val distinctInts13 = Arb.distinct(Arb.int(), 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)16 val distinctInts14 = Arb.distinct(Arb.int(), 3, 4, 5, 6
sample
Using AI Code Generation
1 val distinct = Arb.distinct(listOf(1, 2, 3, 4, 5))2 for (i in 1..100) {3 println(distinct.sample())4 }5 val distinct = Arb.distinct(listOf(1, 2, 3, 4, 5))6 for (i in 1..100) {7 println(distinct.sample())8 }9 val distinct = Arb.distinct(listOf(1, 2, 3, 4, 5))10 for (i in 1..100) {11 println(distinct.sample())12 }13 val distinct = Arb.distinct(listOf(1, 2, 3, 4, 5))14 for (i in 1..100) {15 println(distinct.sample())16 }17 val distinct = Arb.distinct(listOf(1, 2, 3, 4, 5))18 for (i in 1..100) {19 println(distinct.sample())20 }21 val distinct = Arb.distinct(listOf(1, 2, 3, 4, 5))22 for (i in 1..100) {23 println(distinct.sample())24 }25 val distinct = Arb.distinct(listOf(1, 2, 3, 4, 5))26 for (i in 1..100) {27 println(distinct.sample())28 }
sample
Using AI Code Generation
1+class DistinctRandomValuesTest : FunSpec({2+ test("distinct random values") {3+ val distinctValues = distinctValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)4+ val distinctValuesSample = distinctValues.sample()5+ distinctValuesSample.distinct().size shouldBe 106+ }7+})8+class DistinctRandomStringsTest : FunSpec({9+ test("distinct random strings") {10+ val distinctStrings = distinctStrings(10, "abcdefghijklmnopqrstuvwxyz")11+ val distinctStringsSample = distinctStrings.sample()12+ distinctStringsSample.distinct().size shouldBe 1013+ }14+})
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!