How to use lengths class of io.kotest.matchers.string package

Best Kotest code snippet using io.kotest.matchers.string.lengths

BitMapIndexedNodeTest.kt

Source:BitMapIndexedNodeTest.kt Github

copy

Full Screen

1package com.github.whyrising.y.collections.map.hashmap2import com.github.whyrising.y.collections.Edit3import com.github.whyrising.y.collections.concretions.list.PersistentList4import com.github.whyrising.y.collections.concretions.map.MapEntry5import com.github.whyrising.y.collections.concretions.map.PersistentHashMap6import com.github.whyrising.y.collections.concretions.map.PersistentHashMap.BitMapIndexedNode7import com.github.whyrising.y.collections.concretions.map.PersistentHashMap.BitMapIndexedNode.EmptyBitMapIndexedNode8import com.github.whyrising.y.collections.concretions.map.PersistentHashMap.Node9import com.github.whyrising.y.collections.concretions.map.PersistentHashMap.NodeSeq10import com.github.whyrising.y.util.Box11import com.github.whyrising.y.util.hasheq12import io.kotest.core.spec.style.FreeSpec13import io.kotest.matchers.booleans.shouldBeFalse14import io.kotest.matchers.booleans.shouldBeTrue15import io.kotest.matchers.ints.shouldBeExactly16import io.kotest.matchers.nulls.shouldBeNull17import io.kotest.matchers.nulls.shouldNotBeNull18import io.kotest.matchers.shouldBe19import io.kotest.matchers.types.shouldBeSameInstanceAs20import io.kotest.matchers.types.shouldNotBeSameInstanceAs21class BitMapIndexedNodeTest : FreeSpec({22 "EmptyBitMapIndexedNode" {23 EmptyBitMapIndexedNode.edit.value.shouldBeNull()24 EmptyBitMapIndexedNode.datamap shouldBeExactly 025 EmptyBitMapIndexedNode.nodemap shouldBeExactly 026 EmptyBitMapIndexedNode.array.size shouldBeExactly 027 (45 and (78 - 1)).countOneBits()28 }29 "bitmapNodeIndex(bitmap, bitpos)" {30 BitMapIndexedNode.bitmapNodeIndex(0, 4194304) shouldBeExactly 031 BitMapIndexedNode.bitmapNodeIndex(4194304, 1073741824) shouldBeExactly 132 BitMapIndexedNode.bitmapNodeIndex(1077936128, 1) shouldBeExactly 033 }34 "mergeTwoKeyValuePairs()/pairToSubNode()/subNode()" - {35 """when currentKeyMask < newKeyMask, return a node containing both36 where current entry comes before the new entry37 """ {38 val shift = 539 val edit = Edit(Any())40 val leafFlag = Box(null)41 val currentKey = "4"42 val currentValue = 443 val currentHash = hasheq(currentKey)44 val currentNode = BitMapIndexedNode45 .BMIN<String, Int>(edit, 0, 5, emptyArray()).assoc(46 edit,47 shift,48 currentHash,49 currentKey,50 currentValue,51 leafFlag52 ) as BitMapIndexedNode<String, Int>53 val newKey = "8"54 val newHash = hasheq(newKey)55 val newValue = 856 val newDatamap = PersistentHashMap.bitpos(currentHash, shift) or57 PersistentHashMap.bitpos(newHash, shift)58 val subNode = currentNode.mergeIntoSubNode(59 edit,60 shift,61 currentHash,62 currentKey,63 currentValue,64 newHash,65 newKey,66 newValue67 ) as BitMapIndexedNode<String, Int>68 val array = subNode.array69 subNode.edit shouldBeSameInstanceAs edit70 subNode.nodemap shouldBeExactly 071 subNode.datamap shouldBeExactly newDatamap72 array.size shouldBeExactly 473 array[0] shouldBeSameInstanceAs currentKey74 array[1] shouldBe currentValue75 array[2] shouldBeSameInstanceAs newKey76 array[3] shouldBe newValue77 }78 """when newKeyMask < currentKeyMask, return a node containing both79 where new entry comes before the current entry80 """ {81 val shift = 582 val edit = Edit(Any())83 val leafFlag = Box(null)84 val currentKey = "12"85 val currentValue = 1286 val currentHash = hasheq(currentKey)87 val currentNode = BitMapIndexedNode88 .BMIN<String, Int>(edit, 0, 5, emptyArray()).assoc(89 edit,90 shift,91 currentHash,92 currentKey,93 currentValue,94 leafFlag95 ) as BitMapIndexedNode<String, Int>96 val newKey = "18"97 val newHash = hasheq(newKey)98 val newValue = 1899 val newDatamap = PersistentHashMap.bitpos(currentHash, shift) or100 PersistentHashMap.bitpos(newHash, shift)101 val subNode = currentNode.mergeIntoSubNode(102 edit,103 shift,104 currentHash,105 currentKey,106 currentValue,107 newHash,108 newKey,109 newValue110 ) as BitMapIndexedNode<String, Int>111 val array = subNode.array112 subNode.edit shouldBeSameInstanceAs edit113 subNode.nodemap shouldBeExactly 0114 subNode.datamap shouldBeExactly newDatamap115 array.size shouldBeExactly 4116 array[0] shouldBeSameInstanceAs newKey117 array[1] shouldBe newValue118 array[2] shouldBeSameInstanceAs currentKey119 array[3] shouldBe currentValue120 }121 @Suppress("UNCHECKED_CAST")122 "when newKeyMask = currentKeyMask, it should subNode again" {123 val shift = 10124 val edit = Edit(Any())125 val leafFlag = Box(null)126 val currentKey = "410"127 val currentValue = 410128 val currentHash = hasheq(currentKey)129 val currentNode = BitMapIndexedNode130 .BMIN<String, Int>(edit, 0, 0, emptyArray()).assoc(131 edit,132 shift,133 currentHash,134 currentKey,135 currentValue,136 leafFlag137 ) as BitMapIndexedNode<String, Int>138 val newShift = 15139 val newKey = "1140"140 val newHash = hasheq(newKey)141 val newValue = 1140142 val newDatamap = PersistentHashMap.bitpos(currentHash, newShift) or143 PersistentHashMap.bitpos(newHash, newShift)144 val newNodemap = PersistentHashMap.bitpos(currentHash, shift)145 val node = currentNode.mergeIntoSubNode(146 edit,147 shift,148 currentHash,149 currentKey,150 currentValue,151 newHash,152 newKey,153 newValue154 ) as BitMapIndexedNode<String, Int>155 val array = node.array156 val subNode = array[0] as BitMapIndexedNode<String, Int>157 val subNodeArray = subNode.array158 node.edit shouldBeSameInstanceAs edit159 node.nodemap shouldBeExactly newNodemap160 node.datamap shouldBeExactly 0161 array.size shouldBeExactly 1162 subNode.edit shouldBeSameInstanceAs edit163 subNode.nodemap shouldBeExactly 0164 subNode.datamap shouldBeExactly newDatamap165 subNodeArray.size shouldBeExactly 4166 subNodeArray[0] shouldBeSameInstanceAs currentKey167 subNodeArray[1] shouldBe currentValue168 subNodeArray[2] shouldBeSameInstanceAs newKey169 subNodeArray[3] shouldBe newValue170 }171 """when hash collision and shift > 32, it should return172 a HashCollisionNode""" {173 val shift = 35174 val edit = Edit(Any())175 val currentKey = "RwtM1oQGxE"176 val currentValue = 158135874177 val currentHash = hasheq(currentKey)178 val leafFlag = Box(null)179 val currentNode = BitMapIndexedNode180 .BMIN<String, Int>(edit, 0, 0, emptyArray()).assoc(181 edit,182 shift,183 currentHash,184 currentKey,185 currentValue,186 leafFlag187 ) as BitMapIndexedNode<String, Int>188 val newKey = "J2RCvlt3yJ"189 val newValue = 848159417190 val newHash = hasheq(newKey)191 val collisionNode = currentNode.mergeIntoSubNode(192 edit,193 shift,194 currentHash,195 currentKey,196 currentValue,197 newHash,198 newKey,199 newValue200 ) as PersistentHashMap.HashCollisionNode<String, Int>201 val array = collisionNode.array202 collisionNode.edit shouldBeSameInstanceAs edit203 collisionNode.count shouldBeExactly 2204 collisionNode.hash shouldBeExactly currentHash205 array.size shouldBeExactly 4206 array[0] shouldBeSameInstanceAs currentKey207 array[1] shouldBe currentValue208 array[2] shouldBeSameInstanceAs newKey209 array[3] shouldBe newValue210 }211 }212 "updateArrayByIndex(index, value)" - {213 "when edit flags are not the same, return a new node updated" {214 val shift = 0215 val leafFlag = Box(null)216 val node = BitMapIndexedNode<Number, String>()217 .assoc(Edit(Any()), shift, hasheq(4), 4, "4", leafFlag)218 as BitMapIndexedNode<Number, String>219 val newNode = node.updateArrayByIndex(1, "z", Edit(Any()))220 newNode shouldNotBeSameInstanceAs node221 newNode.datamap shouldBeExactly node.datamap222 newNode.nodemap shouldBeExactly node.nodemap223 newNode.array.size shouldBeExactly 2224 newNode.array[0] shouldBe 4225 newNode.array[1] shouldBe "z"226 }227 """when edit flags are the same but set to false,228 return a new node updated""" {229 val shift = 0230 val leafFlag = Box(null)231 val edit = Edit(null)232 val node = BitMapIndexedNode<Number, String>()233 .assoc(edit, shift, hasheq(4), 4, "4", leafFlag)234 as BitMapIndexedNode<Number, String>235 val newNode = node.updateArrayByIndex(1, "z", edit)236 newNode shouldNotBeSameInstanceAs node237 newNode.datamap shouldBeExactly node.datamap238 newNode.nodemap shouldBeExactly node.nodemap239 newNode.array.size shouldBeExactly 2240 newNode.array[0] shouldBe 4241 newNode.array[1] shouldBe "z"242 }243 "when it's allowed to mutate, update the value in array" {244 val shift = 0245 val leafFlag = Box(null)246 val edit = Edit(Any())247 val node = BitMapIndexedNode<Number, String>()248 .assoc(edit, shift, hasheq(4), 4, "4", leafFlag)249 as BitMapIndexedNode<Number, String>250 val newNode = node.updateArrayByIndex(1, "z", edit)251 newNode shouldBeSameInstanceAs node252 newNode.array.size shouldBeExactly 2253 newNode.array[0] shouldBe 4254 newNode.array[1] shouldBe "z"255 }256 }257 "assoc(edit, shift, keyHash, pair, leafFlag)" - {258 """when collision-free, it should add the pair to the first half259 of the array""" {260 val key = "a"261 val edit = Edit(Any())262 val shift = 0263 val keyHash = hasheq(key)264 val value = 18265 val leafFlag = Box(null)266 val node = BitMapIndexedNode<String, Int>()267 val newNode = node.assoc(268 edit, shift, keyHash, key, value, leafFlag269 ) as BitMapIndexedNode<String, Int>270 val newArray = newNode.array271 newNode.edit shouldBeSameInstanceAs edit272 newNode.datamap shouldBeExactly273 (node.datamap or PersistentHashMap.bitpos(keyHash, shift))274 newNode.nodemap shouldBeExactly node.nodemap275 leafFlag.value shouldBeSameInstanceAs leafFlag276 newArray.size shouldBeExactly node.array.size + 2277 newArray[0] shouldBe key278 newArray[1] shouldBe value279 }280 @Suppress("UNCHECKED_CAST")281 "when there is a collision in the first half of the array" - {282 "when keys are not equiv, it should call mergeIntoSubNode()" {283 val key = "8"284 val value = 8285 val edit = Edit(Any())286 val shift = 0287 val keyHash = hasheq(key)288 val leafFlag = Box(null)289 val bitpos = PersistentHashMap.bitpos(keyHash, shift)290 val node = BitMapIndexedNode<String, Int>()291 .assoc(edit, shift, hasheq("0"), "0", 0, leafFlag)292 .assoc(edit, shift, hasheq("2"), "2", 2, leafFlag)293 .assoc(edit, shift, hasheq("4"), "4", 4, leafFlag)294 as BitMapIndexedNode<String, Int>295 val newNode = node296 .assoc(edit, shift, keyHash, key, value, leafFlag)297 as BitMapIndexedNode<String, Int>298 val newArray = newNode.array299 val subNode = newArray[4] as BitMapIndexedNode<String, Int>300 leafFlag.value shouldBeSameInstanceAs leafFlag301 newArray.size shouldBeExactly 5302 newNode.datamap shouldBeExactly (node.datamap xor bitpos)303 newNode.nodemap shouldBeExactly (node.nodemap or bitpos)304 newArray[0] shouldBe "0"305 newArray[1] shouldBe 0306 newArray[2] shouldBe "2"307 newArray[3] shouldBe 2308 subNode.array.size shouldBeExactly 4309 subNode.array[0] shouldBe "4"310 subNode.array[1] shouldBe 4311 subNode.array[2] shouldBe "8"312 subNode.array[3] shouldBe 8313 }314 "when keys are equiv" - {315 "when it's allowed to mutate, update the value in array" {316 val shift = 0317 val edit = Edit(Any())318 val leafFlag = Box(null)319 val node: Node<Number, String> =320 BitMapIndexedNode<Number, String>().assoc(321 edit, shift, hasheq(4), 4, "4", leafFlag322 )323 val newNode: Node<Number, String> = node.assoc(324 edit, shift, hasheq(4L), 4L, "1", leafFlag325 )326 newNode shouldBeSameInstanceAs node327 newNode.array.size shouldBeExactly 2328 newNode.array[0] shouldBe 4329 newNode.array[1] shouldBe "1"330 }331 "when it's not allowed to mutate, return new node updated" {332 val shift = 0333 val leafFlag = Box(null)334 val node = BitMapIndexedNode<Number, String>().assoc(335 Edit(Any()),336 shift,337 hasheq(4),338 4,339 "4",340 leafFlag341 ) as BitMapIndexedNode<Number, String>342 val newNode = node.assoc(343 Edit(Any()),344 shift,345 hasheq(4L),346 4L,347 "1",348 leafFlag349 ) as BitMapIndexedNode<String, Int>350 node.array.size shouldBeExactly 2351 node.array[0] shouldBe 4352 node.array[1] shouldBe "4"353 newNode shouldNotBeSameInstanceAs node354 newNode.datamap shouldBeExactly node.datamap355 newNode.nodemap shouldBeExactly node.nodemap356 newNode.array.size shouldBeExactly 2357 newNode.array[0] shouldBe 4358 newNode.array[1] shouldBe "1"359 }360 }361 }362 "when there is collision in the second half of the array" - {363 @Suppress("UNCHECKED_CAST")364 "it should add to the subNode and return a new node" {365 val shift = 0366 val edit = Edit(Any())367 val leafFlag = Box(null)368 var i = 0369 var node: Node<String, Int> = BitMapIndexedNode()370 while (i < 36) {371 val key = "$i"372 node = node.assoc(373 edit, shift, hasheq(key), key, i, leafFlag374 )375 i += 1376 }377 val newNode = node.assoc(378 edit, shift, hasheq("36"), "36", 36, leafFlag379 )380 val newArray = newNode.array381 val subNode = newArray[24] as BitMapIndexedNode<String, Int>382 newNode shouldBeSameInstanceAs node383 newArray.size shouldBeExactly node.array.size384 subNode.array[2] shouldBe "36"385 subNode.array[3] shouldBe 36386 }387 @Suppress("UNCHECKED_CAST")388 "it should put the subNode and return this node" {389 val shift = 0390 val edit = Edit(Any())391 val leafFlag = Box(null)392 var i = 0393 var node: Node<String, Int> = BitMapIndexedNode()394 while (i < 424) {395 val key = "$i"396 node = node.assoc(397 edit, shift, hasheq(key), key, i, leafFlag398 )399 i += 2400 }401 val array = (402 (node.array[5] as BitMapIndexedNode<String, Int>)403 .array[12] as BitMapIndexedNode<String, Int>404 ).array405 val newNode = node.assoc(406 edit, shift, hasheq("424"), "424", 424, leafFlag407 )408 val newArray = (409 (newNode.array[5] as BitMapIndexedNode<String, Int>)410 .array[12] as BitMapIndexedNode<String, Int>411 ).array412 newNode shouldBeSameInstanceAs node413 newArray.size shouldBeExactly array.size + 2414 newArray[4] shouldBe "424"415 newArray[5] shouldBe 424416 }417 }418 }419 "hasNodes()" {420 val shift = 0421 val edit = Edit(Any())422 val leafFlag = Box(null)423 val m: Node<String, Int> = BitMapIndexedNode()424 var n = m425 var i = 0426 while (i < 36) {427 val key = "$i"428 n = n.assoc(edit, shift, hasheq(key), key, i, leafFlag)429 i++430 }431 m.hasNodes().shouldBeFalse()432 n.hasNodes().shouldBeTrue()433 }434 "hasData()" {435 val shift = 0436 val edit = Edit(Any())437 val leafFlag = Box(null)438 val node: Node<String, Int> = BitMapIndexedNode()439 val n = node.assoc(edit, shift, hasheq("a"), "a", 15, leafFlag)440 node.hasData().shouldBeFalse()441 n.hasData().shouldBeTrue()442 }443 "nodeArity() should return the count of one bits in nodemap" {444 val shift = 0445 val edit = Edit(Any())446 val leafFlag = Box(null)447 var i = 0448 var n: Node<String, Int> = BitMapIndexedNode()449 while (i < 20) {450 val key = "$i"451 n = n.assoc(edit, shift, hasheq(key), key, i, leafFlag)452 i += 2453 }454 n.nodeArity() shouldBeExactly 2455 }456 "dataArity() should return the count of one bits in datamap" {457 val shift = 0458 val edit = Edit(Any())459 val leafFlag = Box(null)460 var i = 0461 var n: Node<String, Int> = BitMapIndexedNode()462 while (i < 20) {463 val key = "$i"464 n = n.assoc(edit, shift, hasheq(key), key, i, leafFlag)465 i += 2466 }467 n.dataArity() shouldBeExactly 6468 }469 "getNode(index) should return the nth node from the right of array" {470 val shift = 0471 val edit = Edit(Any())472 val leafFlag = Box(null)473 var i = 0474 var n: Node<String, Int> = BitMapIndexedNode()475 while (i < 20) {476 val key = "$i"477 n = n.assoc(edit, shift, hasheq(key), key, i, leafFlag)478 i += 2479 }480 val node1 = n.getNode(1)481 val node2 = n.getNode(2)482 node1.array.size shouldBeExactly 4483 node2.array.size shouldBeExactly 4484 }485 @Suppress("UNCHECKED_CAST")486 "array property" {487 val shift = 0488 val edit = Edit(Any())489 val leafFlag = Box(null)490 var i = 0491 var n: Node<String, Int> = BitMapIndexedNode()492 while (i < 20) {493 val key = "$i"494 n = n.assoc(edit, shift, hasheq(key), key, i, leafFlag)495 i += 2496 }497 n.array.size shouldBeExactly 14498 n.array[0] shouldBe "14"499 n.array[1] shouldBe 14500 n.array[8] shouldBe "16"501 n.array[9] shouldBe 16502 n.array[13] as BitMapIndexedNode<String, Int>503 }504 "singleKV()" {505 val shift = 0506 val edit = Edit(Any())507 val leafFlag = Box(null)508 val n: Node<String, Int> = BitMapIndexedNode()509 val m = n.assoc(edit, shift, hasheq("a"), "a", 12, leafFlag)510 val o = m.assoc(edit, shift, hasheq("b"), "b", 18, leafFlag)511 n.isSingleKV().shouldBeFalse()512 o.isSingleKV().shouldBeFalse()513 m.isSingleKV().shouldBeTrue()514 }515 "without()" - {516 "when key doesn't exist, it should return this" {517 val shift = 0518 val edit = Edit(Any())519 val leafFlag = Box(null)520 val removedLeaf = Box(null)521 var i = 0522 val key = "30"523 var n: Node<String, Int> = BitMapIndexedNode()524 while (i < 20) {525 val k = "$i"526 n = n.assoc(edit, shift, hasheq(k), k, i, leafFlag)527 i += 2528 }529 val newNode: Node<String, Int> = n.without(530 edit, shift, hasheq(key), key, removedLeaf531 )532 newNode shouldBeSameInstanceAs n533 removedLeaf.value.shouldBeNull()534 }535 "when hash exists in the data half of the array" - {536 "when key isn't equiv with key in the array, return this" {537 val shift = 0538 val key = "J2RCvlt3yJ"539 val delKey = "RwtM1oQGxE"540 val edit = Edit(Any())541 val leafFlag = Box(null)542 val removedLeaf = Box(null)543 val n = BitMapIndexedNode<String, Int>()544 .assoc(edit, shift, hasheq(key), key, 15, leafFlag)545 val newNode = n.without(546 edit, shift, hasheq(delKey), delKey, removedLeaf547 )548 newNode shouldBeSameInstanceAs n549 removedLeaf.value.shouldBeNull()550 }551 "when keys are equiv, it should remove key/value form array" - {552 "using copyAndRemove()" {553 val shift = 0554 val edit = Edit(Any())555 val leafFlag = Box(null)556 val removedLeaf = Box(null)557 val key = "6"558 val hash = hasheq(key)559 var n = BitMapIndexedNode<String, Int>()560 var i = 0561 while (i < 20) {562 val k = "$i"563 n = n.assoc(564 edit, shift, hasheq(k), k, i, leafFlag565 ) as BitMapIndexedNode<String, Int>566 i += 2567 }568 val newNode = n.without(569 edit, shift, hash, key, removedLeaf570 ) as BitMapIndexedNode<String, Int>571 newNode.array.size shouldBeExactly n.array.size - 2572 removedLeaf.value shouldBeSameInstanceAs removedLeaf573 newNode.datamap shouldBeExactly574 (n.datamap xor PersistentHashMap.bitpos(hash, shift))575 }576 "when shift == 0 and array size is 4" {577 val shift = 0578 val edit = Edit(Any())579 val leafFlag = Box(null)580 val removedLeaf1 = Box(null)581 val removedLeaf2 = Box(null)582 var n = BitMapIndexedNode<String, Int>()583 val key1 = "0"584 val key2 = "2"585 val keyHash1 = hasheq(key1)586 val keyHash2 = hasheq(key2)587 var i = 0588 while (i < 4) {589 val k = "$i"590 n = n.assoc(591 edit, shift, hasheq(k), k, i, leafFlag592 ) as BitMapIndexedNode<String, Int>593 i += 2594 }595 val newNode1 = n.without(596 edit, shift, keyHash1, key1, removedLeaf1597 ) as BitMapIndexedNode<String, Int>598 val bitpos1 = PersistentHashMap.bitpos(keyHash1, shift)599 val newNode2 = n.without(600 edit, shift, keyHash2, key2, removedLeaf2601 ) as BitMapIndexedNode<String, Int>602 val bitpos2 = PersistentHashMap.bitpos(keyHash2, shift)603 newNode1.array.size shouldBeExactly 2604 removedLeaf1.value shouldBeSameInstanceAs removedLeaf1605 newNode1.nodemap shouldBeExactly 0606 newNode1.datamap shouldBeExactly (n.datamap xor bitpos1)607 newNode1.edit shouldBeSameInstanceAs edit608 newNode2.array.size shouldBeExactly 2609 removedLeaf2.value shouldBeSameInstanceAs removedLeaf2610 newNode2.nodemap shouldBeExactly 0611 newNode2.datamap shouldBeExactly (n.datamap xor bitpos2)612 newNode2.edit shouldBeSameInstanceAs edit613 }614 }615 }616 "when hash exists in nodes half of the array" - {617 """when key exists and and 1 pair left in subNode after removal,618 it should push it up to datamap619 """ {620 val shift = 0621 val edit = Edit(Any())622 val leafFlag = Box(null)623 val removedLeaf = Box(null)624 var n = BitMapIndexedNode<String, Int>()625 val key = "18"626 val keyHash = hasheq(key)627 val bitpos = PersistentHashMap.bitpos(keyHash, shift)628 var i = 0629 while (i < 20) {630 val k = "$i"631 n = n.assoc(632 edit, shift, hasheq(k), k, i, leafFlag633 ) as BitMapIndexedNode<String, Int>634 i += 2635 }636 val newNode = n.without(637 edit, shift, keyHash, key, removedLeaf638 ) as BitMapIndexedNode<String, Int>639 newNode.array[2] shouldBe "12"640 newNode.array[3] shouldBe 12641 newNode.datamap shouldBeExactly (n.datamap or bitpos)642 newNode.nodemap shouldBeExactly (n.nodemap xor bitpos)643 removedLeaf.value.shouldNotBeNull()644 }645 @Suppress("UNCHECKED_CAST")646 """when key exists and and more than 1 pair left in newSubNode647 after removal, it should update the array using newSubNode648 """ {649 val shift = 0650 val edit = Edit(Any())651 val leafFlag = Box(null)652 val removedLeaf = Box(null)653 var n = BitMapIndexedNode<String, Int>()654 val key = "96"655 val keyHash = hasheq(key)656 var i = 0657 while (i < 100) {658 val k = "$i"659 n = n.assoc(660 edit, shift, hasheq(k), k, i, leafFlag661 ) as BitMapIndexedNode<String, Int>662 i += 2663 }664 val subNode = n.array[35] as BitMapIndexedNode<String, Int>665 val newNode = n.without(666 edit, shift, keyHash, key, removedLeaf667 ) as BitMapIndexedNode<String, Int>668 val newSubNode = newNode.array[35]669 as BitMapIndexedNode<String, Int>670 newNode shouldBeSameInstanceAs n671 newNode.datamap shouldBeExactly newNode.datamap672 newNode.nodemap shouldBeExactly newNode.nodemap673 newSubNode.array.size shouldBeExactly subNode.array.size - 2674 }675 @Suppress("UNCHECKED_CAST")676 """when key exists and there is only 1 node in the array and677 1 pair left in subNode after removal, return the subNode""" {678 val shift = 0679 val edit = Edit(Any())680 val leafFlag = Box(null)681 val removedLeaf = Box(null)682 var n = BitMapIndexedNode<String, Int>()683 val key = "1958"684 val keyHash = hasheq(key)685 var i = 0686 while (i < 2000) {687 val k = "$i"688 n = n.assoc(689 edit, shift, hasheq(k), k, i, leafFlag690 ) as BitMapIndexedNode<String, Int>691 i += 2692 }693 val newNode = n.without(694 edit, shift, keyHash, key, removedLeaf695 ) as BitMapIndexedNode<String, Int>696 val newSubNode = newNode.array[10]697 as BitMapIndexedNode<String, Int>698 newSubNode.array[2] shouldBe "642"699 newSubNode.array[3] shouldBe 642700 newNode.nodemap shouldBeExactly -1701 newNode.datamap shouldBeExactly 0702 }703 "when key doesn't exist, return this" {704 val shift = 0705 val edit = Edit(Any())706 val leafFlag = Box(null)707 val removedLeaf = Box(null)708 var n = BitMapIndexedNode<String, Int>()709 val key = "4000"710 val keyHash = hasheq(key)711 var i = 0712 while (i < 2000) {713 val k = "$i"714 n = n.assoc(715 edit, shift, hasheq(k), k, i, leafFlag716 ) as BitMapIndexedNode<String, Int>717 i += 2718 }719 val newNode = n.without(720 edit, shift, keyHash, key, removedLeaf721 ) as BitMapIndexedNode<String, Int>722 newNode shouldBeSameInstanceAs n723 }724 }725 }726 "find(...key, default) should return value" - {727 "when key doesn't exist return default" {728 val shift = 0729 val edit = Edit(Any())730 val leafFlag = Box(null)731 var n = BitMapIndexedNode<String, Int>()732 var i = 0733 while (i < 20) {734 val k = "$i"735 n = n.assoc(736 edit, shift, hasheq(k), k, i, leafFlag737 ) as BitMapIndexedNode<String, Int>738 i += 2739 }740 val default = -1741 n.find(shift, hasheq("80"), "80", default) shouldBe default742 n.find(shift, hasheq("28"), "28", default) shouldBe default743 }744 "when exists, it should return the associated value" {745 val shift = 0746 val edit = Edit(Any())747 val leafFlag = Box(null)748 var n = BitMapIndexedNode<String, Int>()749 var i = 0750 while (i < 20) {751 val k = "$i"752 n = n.assoc(753 edit, shift, hasheq(k), k, i, leafFlag754 ) as BitMapIndexedNode<String, Int>755 i += 2756 }757 n.find(shift, hasheq("6"), "6", -1) shouldBe 6758 n.find(shift, hasheq("18"), "18", -1) shouldBe 18759 }760 "compare keys with equiv()" {761 val shift = 0762 val edit = Edit(Any())763 val leafFlag = Box(null)764 val k = 1L765 val n = BitMapIndexedNode<Any, String>().assoc(766 edit, shift, hasheq(k), k, "1L", leafFlag767 ) as BitMapIndexedNode<Any, String>768 n.find(shift, hasheq(1), 1, "notFound") shouldBe "1L"769 }770 }771 "find(...key) should return IMapEntry" - {772 "when key doesn't exist return null" {773 val shift = 0774 val edit = Edit(Any())775 val leafFlag = Box(null)776 var n = BitMapIndexedNode<String, Int>()777 var i = 0778 while (i < 20) {779 val k = "$i"780 n = n.assoc(781 edit, shift, hasheq(k), k, i, leafFlag782 ) as BitMapIndexedNode<String, Int>783 i += 2784 }785 n.find(shift, hasheq("80"), "80").shouldBeNull()786 n.find(shift, hasheq("28"), "28").shouldBeNull()787 }788 "when exists, it should return IMapEntry of key/value" {789 val shift = 0790 val edit = Edit(Any())791 val leafFlag = Box(null)792 var n = BitMapIndexedNode<String, Int>()793 var i = 0794 while (i < 20) {795 val k = "$i"796 n = n.assoc(797 edit, shift, hasheq(k), k, i, leafFlag798 ) as BitMapIndexedNode<String, Int>799 i += 2800 }801 n.find(shift, hasheq("6"), "6") shouldBe802 MapEntry("6", 6)803 n.find(shift, hasheq("18"), "18") shouldBe804 MapEntry("18", 18)805 }806 }807 "nodeSeq()" - {808 "when datamap > 0" {809 val shift = 0810 val edit = Edit(Any())811 val leafFlag = Box(null)812 var n = BitMapIndexedNode<String, Int>()813 var i = 0814 while (i < 20) {815 val k = "$i"816 n = n.assoc(817 edit, shift, hasheq(k), k, i, leafFlag818 ) as BitMapIndexedNode<String, Int>819 i += 2820 }821 val nodeSeq = n.nodeSeq() as NodeSeq<String, Int>822 nodeSeq.array shouldBeSameInstanceAs n.array823 nodeSeq.lvl shouldBeExactly 0824 nodeSeq.nodes.size shouldBeExactly 7825 nodeSeq.nodes[0] shouldBeSameInstanceAs n826 nodeSeq.cursorLengths.size shouldBeExactly 7827 nodeSeq.cursorLengths[0] shouldBeExactly n.nodeArity()828 nodeSeq.dataIndex shouldBeExactly 0829 nodeSeq.dataLength shouldBeExactly n.dataArity() - 1830 nodeSeq.first() shouldBe MapEntry("14", 14)831 }832 "when datamap == 0" - {833 "when node is empty, it should return an empty seq" {834 val node = BitMapIndexedNode<String, Int>()835 val nodeSeq = node.nodeSeq()836 nodeSeq shouldBeSameInstanceAs PersistentList.Empty837 nodeSeq.rest() shouldBeSameInstanceAs PersistentList.Empty838 nodeSeq.next().shouldBeNull()839 }840 "it should return a seq of map entries" {841 val shift = 0842 val edit = Edit(Any())843 val hash = hasheq("672")844 val leafFlag = Box(null)845 val removedLeaf = Box(null)846 var indexedNode = BitMapIndexedNode<String, Int>()847 var i = 0848 while (i < 1000) {849 val k = "$i"850 indexedNode = indexedNode.assoc(851 edit, shift, hasheq(k), k, i, leafFlag852 ) as BitMapIndexedNode<String, Int>853 i += 2854 }855 val nodeSeq = indexedNode.nodeSeq() as NodeSeq<String, Int>856 val next = nodeSeq.next() as NodeSeq<String, Int>857 nodeSeq.count shouldBeExactly 500858 nodeSeq[0] shouldBe MapEntry("672", 672)859 nodeSeq[499] shouldBe MapEntry("784", 784)860 next.count shouldBe 499861 next.first() shouldBe MapEntry("52", 52)862 next[498] shouldBe MapEntry("784", 784)863 }864 }865 }866})...

Full Screen

Full Screen

IterableTest.kt

Source:IterableTest.kt Github

copy

Full Screen

...324 .zip(j) { (a, b, c, d, e, f, g, h, i), j -> Tuple10(a, b, c, d, e, f, g, h, i, j) }325 result shouldBe expected326 }327 }328 "can align lists with different lengths" {329 checkAll(Arb.list(Arb.boolean()), Arb.list(Arb.boolean())) { a, b ->330 a.align(b).size shouldBe max(a.size, b.size)331 }332 checkAll(Arb.list(Arb.boolean()), Arb.list(Arb.boolean())) { a, b ->333 a.align(b).take(min(a.size, b.size)).forEach {334 it.isBoth shouldBe true335 }336 }337 checkAll(Arb.list(Arb.boolean()), Arb.list(Arb.boolean())) { a, b ->338 a.align(b).drop(min(a.size, b.size)).forEach {339 if (a.size < b.size) {340 it.isRight shouldBe true341 } else {342 it.isLeft shouldBe true...

Full Screen

Full Screen

NonEmptyListTest.kt

Source:NonEmptyListTest.kt Github

copy

Full Screen

...103 ints.map { if (it % 2 == 0) Valid(it) else Invalid(it) }.sequenceValidated(Semigroup.int()) shouldBe104 ints.traverseValidated(Semigroup.int()) { if (it % 2 == 0) Valid(it) else Invalid(it) }105 }106 }107 "can align lists with different lengths" {108 checkAll(Arb.nonEmptyList(Arb.boolean()), Arb.nonEmptyList(Arb.boolean())) { a, b ->109 a.align(b).size shouldBe max(a.size, b.size)110 }111 checkAll(Arb.nonEmptyList(Arb.boolean()), Arb.nonEmptyList(Arb.boolean())) { a, b ->112 a.align(b).all.take(min(a.size, b.size)).forEach {113 it.isBoth shouldBe true114 }115 }116 }117 "zip2" {118 checkAll(Arb.nonEmptyList(Arb.int()), Arb.nonEmptyList(Arb.int())) { a, b ->119 val result = a.zip(b)120 val expected = a.all.zip(b.all).let(NonEmptyList.Companion::fromListUnsafe)121 result shouldBe expected...

Full Screen

Full Screen

MaximumProductOfWordLengthsTest.kt

Source:MaximumProductOfWordLengthsTest.kt Github

copy

Full Screen

1package leetcode.codingchallenge2021.may2import io.kotest.core.spec.style.StringSpec3import io.kotest.data.blocking.forAll4import io.kotest.data.row5import io.kotest.matchers.shouldBe6class MaximumProductOfWordLengthsTest : StringSpec({7 "Given a string array, return the maximum product value of two words which don't share common letters." {8 forAll(9 row(arrayOf("abcw", "baz", "foo", "bar", "xtfn", "abcdef"), 16),10 row(arrayOf("a", "ab", "abc", "d", "cd", "bcd", "abcd"), 4),11 row(arrayOf("a", "aa", "aaa", "aaaa"), 0),12 row(13 arrayOf(14 "edadc", "ebbfe", "aacdde", "dfe", "cb", "fddddff", "fabca", "adccac", "ece", "ccaf", "feba", "bcb",15 "edadc", "aea", "bacb", "acefa", "fcebffd", "dfeebca", "bedcbaa", "deaccc", "abedc", "dadff", "eef",16 "ddebbb", "abecab", "cd", "abdeee", "eedce", "deef", "dceaddd", "ced", "fbbf", "ba", "eefeda", "fb",17 "cddc", "adafbf", "dded", "aadbf", "caefbaf", "ccebf", "dbb", "ee", "dadcecc", "ddbcabb", "afeaa",18 "ec", "aad", "efde", "cbcda", "cdbdafd", "cddc", "ecaaa", "ae", "cfc", "bccac", "cdcc", "abbbf",19 "fcdface", "ddbcdc", "bfebb", "daed", "bc", "dc", "ecdfc", "eeb", "bb", "dad", "caecb", "fbe",20 "bbbc", "cacea", "dbc", "fbe", "bcfffbd", "aeda", "cff", "ddfc", "ea", "bdfd", "ccb", "cb", "ae",21 "ceabefa", "dcea", "cbaed", "bfedf", "fa", "ccd", "fece", "bceef", "acabca", "dafa", "fdeec", "dac",22 "cae", "adeeadb", "ecacc", "acfe", "de"23 ),24 4225 )26 ) { input, output ->27 MaximumProductOfWordLengths.maxProduct(input) shouldBe output28 }29 }30})...

Full Screen

Full Screen

MainTest.kt

Source:MainTest.kt Github

copy

Full Screen

1package hm.binkley.kunits2import com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemErrAndOutNormalized3import io.kotest.matchers.shouldBe4import org.junit.jupiter.api.Test5internal class MainTest {6 @Test7 fun `should run`() {8 tapSystemErrAndOutNormalized { main() } shouldBeAfterTrimming9 """10== ENGLISH LENGTHS11120 lines12-120 lines13120 lines1430 Bc15240 lines16240 lines170 hh18360 lines1930 Bc2040 lines215 sticks225⁄2 hh23== MEDIEVAL TIMES2412345⁄4 sec25-12345⁄4 sec2638681⁄2 atoms27823⁄960 hr2812345⁄2 sec2912585⁄4 sec300 quadrants3112345 sec32823⁄16 min3312345⁄16 sec34823⁄345600 quinzièmes3512345⁄4 sec36== AVOIRDUPOIS WEIGHTS37300 dr38-300 dr39300 dr4075⁄4 oz41600 dr42316 dr430 lb441500 dr4575⁄4 oz4660 dr4775⁄896 st48300 dr49== USD DENOMINATIONS50$4.33 MAKES CHANGE IN 9 COINS AS:51- 4 100¢ ($4.00)52- 0 50¢ ($0.00)53- 1 25¢ ($0.25)54- 0 10¢ ($0.00)55- 1 5¢ ($0.05)56- 3 1¢ ($0.03)57WHICH SUMS TO $4.3358AND IS THE SAME AS [4 100¢, 0 50¢, 1 25¢, 0 10¢, 1 5¢, 3 1¢] (true)59== CONVERSIONS601 fur IN Furlong-Firkin-Fortnight IS 220 yd IN English61220 yd IN English IS 1 fur IN Furlong-Firkin-Fortnight621 sm IN MIT IS 67" IN English6367" IS [5', 7"]64== EXAMPLE: CLOCK ARITHMETIC65377⁄4 min (94¼) IS [15 sec, 34 min, 1 hr] (377⁄240 hr)66 """67 }68}69private infix fun String.shouldBeAfterTrimming(expected: String) =70 trimIndent().trim() shouldBe expected.trimIndent().trim()...

Full Screen

Full Screen

LengthTest.kt

Source:LengthTest.kt Github

copy

Full Screen

1package com.example2import io.kotest.core.spec.style.StringSpec3import io.kotest.matchers.shouldBe4class LengthTest : StringSpec({5 "should add two lengths in both meters" {6 Addition(5.0, Unit.Metre).add(7 Addition(5.0,Unit.Metre)8 ) shouldBe Addition(10.0,Unit.Metre)9 }10 "should add two lengths one in meter and another one in centimeter" {11 Addition(7.0, Unit.Metre).add(12 Addition(5.0, Unit.Centimetre)13 ) shouldBe Addition(7.05, Unit.Metre)14 }15 "should add two lengths one in centimeter and another one in meter" {16 Addition(7.0, Unit.Centimetre).add(17 Addition(5.0, Unit.Metre)18 ) shouldBe Addition(507.0, Unit.Centimetre)19 }20 "should add two lengths in both centimeters" {21 Addition(7.0, Unit.Centimetre).add(22 Addition(5.0, Unit.Centimetre)23 ) shouldBe Addition(12.0, Unit.Centimetre)24 }25 "should add two lengths one in millimeter and another one in meter" {26 Addition(7.0, Unit.Millimetre).add(27 Addition(5.0, Unit.Metre)28 ) shouldBe Addition(5007.0, Unit.Millimetre)29 }30})...

Full Screen

Full Screen

AnagramCheckerTest.kt

Source:AnagramCheckerTest.kt Github

copy

Full Screen

2import io.kotest.matchers.booleans.shouldBeFalse3import io.kotest.matchers.booleans.shouldBeTrue4class AnagramCheckerTest : StringSpec() {5 init {6 "is 'b' an anagram of 'bac', check for not equal lengths"{7 AnagramChecker().match("b","bac").shouldBeFalse()8 }9 "is 'a' an anagram of 'a', check for equal length string & both string in small-case" {10 AnagramChecker().match("a", "a").shouldBeTrue()11 }12 "is 'DoG' an anagram of 'dog', check for uppercase and lowercase equality"{13 AnagramChecker().match("DoG","dog").shouldBeTrue()14 }15 "is 'A' an anagram of 'A', check for equal length string & both string in capital-case"{16 AnagramChecker().match("A","A").shouldBeTrue()17 }18 "is 'A' an anagram of 'aA', check for the same character occurrence but when count is not equal"{19 AnagramChecker().match("A","aA").shouldBeFalse()20 }...

Full Screen

Full Screen

mergeTwoLinkedListsTest.kt

Source:mergeTwoLinkedListsTest.kt Github

copy

Full Screen

...4class mergeTwoLinkedListsTest: StringSpec({5 "same length" {6 mergeTwoLinkedLists(makeListNode(arrayOf(1, 2, 3)), makeListNode(arrayOf(4,5,6))) shouldBe makeListNode(arrayOf(1, 2, 3, 4, 5 ,6))7 }8 "different lengths" {9 mergeTwoLinkedLists(makeListNode(arrayOf(1, 1, 2, 4)), makeListNode(arrayOf(0, 3, 5))) shouldBe makeListNode(arrayOf(0, 1, 1, 2, 3, 4, 5))10 }11})...

Full Screen

Full Screen

lengths

Using AI Code Generation

copy

Full Screen

1+import io.kotest.matchers.string.*2+class StringMatchersTest : FunSpec() {3+ init {4+ test("startsWith") {5+ "hello" should startWith("he")6+ "hello" should startWith("hello")7+ "hello" shouldNot startWith("ello")8+ }9+ test("endsWith") {10+ "hello" should endWith("lo")11+ "hello" should endWith("hello")12+ "hello" shouldNot endWith("hell")13+ }14+ test("contain") {15+ "hello" should contain("ell")16+ "hello" should contain("hello")17+ "hello" shouldNot contain("ello")18+ }19+ test("haveLength") {20+ "hello" should haveLength(5)21+ "hello" shouldNot haveLength(4)22+ }23+ test("haveMaxLength") {24+ "hello" should haveMaxLength(5)25+ "hello" should haveMaxLength(6)26+ "hello" shouldNot haveMaxLength(4)27+ }28+ test("haveMinLength") {29+ "hello" should haveMinLength(5)30+ "hello" should haveMinLength(4)31+ "hello" shouldNot haveMinLength(6)32+ }33+ test("beEmpty") {34+ "" should beEmpty()35+ "hello" shouldNot beEmpty()36+ }37+ test("beBlank") {38+ "" should beBlank()39+ " " should beBlank()40+ "hello" shouldNot beBlank()41+ }42+ test("beLowerCase") {43+ "hello" should beLowerCase()44+ "Hello" shouldNot beLowerCase()45+ }46+ test("beUpperCase") {47+ "HELLO" should beUpperCase()48+ "Hello" shouldNot beUpperCase()49+ }50+ test("beDigit") {51+ "123" should beDigit()52+ "abc" shouldNot beDigit()53+ }54+ test("beAlphanumeric") {55+ "abc123" should beAlphanumeric()56+ "abc" should beAlphanumeric()57+ "123" should beAlphanumeric()

Full Screen

Full Screen

lengths

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.string.shouldHaveLength2 class StringLengthTest : StringSpec({3 "string length should be correct" {4 "hello".shouldHaveLength(5)5 }6 })7 "hello".isEmpty() shouldBe false8 "hello".isEmpty() shouldBe false9 "hello".isEmpty() shouldBe false10 "hello".isEmpty() shouldNotBe true11 "hello".isEmpty() shouldNotBe true12 "hello".isEmpty() shouldNotBe false13 listOf(1, 2, 3) shouldContain 214 listOf(1, 2, 3) shouldNotContain 415 listOf(1, 2, 3) shouldContainAll listOf(2, 3)16 listOf(1, 2, 3) shouldContainExactly listOf(1, 2, 3)17 listOf(1, 2, 3) shouldContainExactlyInAnyOrder listOf(2, 1, 3)

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