How to use Sequence.shouldHaveElementAt method of io.kotest.matchers.sequences.matchers class

Best Kotest code snippet using io.kotest.matchers.sequences.matchers.Sequence.shouldHaveElementAt

SequenceMatchersTest.kt

Source:SequenceMatchersTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.matchers.collections2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.assertions.throwables.shouldThrowAny4import io.kotest.core.spec.style.WordSpec5import io.kotest.core.spec.style.scopes.WordSpecTerminalScope6import io.kotest.core.spec.style.scopes.WordSpecShouldContainerScope7import io.kotest.matchers.sequences.shouldBeLargerThan8import io.kotest.matchers.sequences.shouldBeSameCountAs9import io.kotest.matchers.sequences.shouldBeSmallerThan10import io.kotest.matchers.sequences.shouldBeSorted11import io.kotest.matchers.sequences.shouldBeSortedWith12import io.kotest.matchers.sequences.shouldBeUnique13import io.kotest.matchers.sequences.shouldContain14import io.kotest.matchers.sequences.shouldContainAll15import io.kotest.matchers.sequences.shouldContainAllInAnyOrder16import io.kotest.matchers.sequences.shouldContainDuplicates17import io.kotest.matchers.sequences.shouldContainExactly18import io.kotest.matchers.sequences.shouldContainInOrder19import io.kotest.matchers.sequences.shouldContainNoNulls20import io.kotest.matchers.sequences.shouldContainNull21import io.kotest.matchers.sequences.shouldContainOnlyNulls22import io.kotest.matchers.sequences.shouldExist23import io.kotest.matchers.sequences.shouldHaveAtLeastCount24import io.kotest.matchers.sequences.shouldHaveAtMostCount25import io.kotest.matchers.sequences.shouldHaveCount26import io.kotest.matchers.sequences.shouldHaveElementAt27import io.kotest.matchers.sequences.shouldHaveLowerBound28import io.kotest.matchers.sequences.shouldHaveSingleElement29import io.kotest.matchers.sequences.shouldHaveUpperBound30import io.kotest.matchers.sequences.shouldNotBeSorted31import io.kotest.matchers.sequences.shouldNotBeSortedWith32import io.kotest.matchers.sequences.shouldNotBeUnique33import io.kotest.matchers.sequences.shouldNotContain34import io.kotest.matchers.sequences.shouldNotContainAllInAnyOrder35import io.kotest.matchers.sequences.shouldNotContainExactly36import io.kotest.matchers.sequences.shouldNotContainNoNulls37import io.kotest.matchers.sequences.shouldNotContainNull38import io.kotest.matchers.sequences.shouldNotContainOnlyNulls39import io.kotest.matchers.sequences.shouldNotHaveCount40import io.kotest.matchers.sequences.shouldNotHaveElementAt41class SequenceMatchersTest : WordSpec() {42 /* PassFail */43 private suspend fun WordSpecShouldContainerScope.pass(name: String, test: suspend WordSpecTerminalScope.() -> Unit) {44 ("succeed $name")(test)45 }46 private suspend fun WordSpecShouldContainerScope.succeed(name: String, test: suspend WordSpecTerminalScope.() -> Unit) = pass(name, test)47 fun WordSpecShouldContainerScope.fail(msg: String): Nothing = io.kotest.assertions.fail(msg)48 suspend fun WordSpecShouldContainerScope.fail(name: String, test: () -> Any?) {49 ("fail $name") { shouldThrowAny(test) }50 }51 suspend inline fun <reified E : Throwable> WordSpecShouldContainerScope.abort(name: String, crossinline test: () -> Any?) {52 ("abort $name") { shouldThrow<E>(test) }53 }54 suspend inline fun <reified E : Throwable> WordSpecShouldContainerScope.`throw`(name: String, crossinline test: () -> Any?) = abort<E>(55 name,56 test)57 /* sample data */58 val empty = emptySequence<Int>()59 val single = sequenceOf(0)60 val nulls = sequenceOf<Int?>(null, null, null, null)61 val sparse = sequenceOf(null, null, null, 3)62 val countup = (0..10).asSequence()63 val countdown = (10 downTo 0).asSequence()64 val unique = sequenceOf(3, 2, 1)65 val repeating = sequenceOf(1, 2, 3, 1, 2, 3)66 val asc = { a: Int, b: Int -> a - b }67 val desc = { a: Int, b: Int -> b - a }68 /* tests */69 init {70 /* count */71 "have count" should {72 succeed("for empty when 0") {73 empty.shouldHaveCount(0)74 }75 fail("for empty when non-zero") {76 empty.shouldHaveCount(1)77 }78 succeed("for single when 1") {79 single.shouldHaveCount(1)80 }81 fail("for single when 0") {82 single.shouldHaveCount(0)83 }84 "match count() for multiple" {85 sparse.shouldHaveCount(sparse.count())86 }87 fail("to mis-match count() for multiple") {88 sparse.shouldHaveCount(sparse.count() - 1)89 }90 }91 "not have count" should {92 fail("for empty when non-zero") {93 empty.shouldNotHaveCount(0)94 }95 succeed("for empty when non-zero") {96 empty.shouldNotHaveCount(1)97 }98 fail("for single when 1") {99 single.shouldNotHaveCount(1)100 }101 succeed("for single when 0") {102 single.shouldNotHaveCount(0)103 }104 fail("to match count() for multiple") {105 sparse.shouldNotHaveCount(sparse.count())106 }107 "mis-match count() for multiple" {108 sparse.shouldNotHaveCount(sparse.count() - 1)109 }110 }111 "larger than" should {112 fail("for empty") {113 empty.shouldBeLargerThan(single)114 }115 succeed("with empty") {116 single.shouldBeLargerThan(empty)117 }118 fail("for smaller") {119 nulls.shouldBeLargerThan(countup)120 }121 fail("for same count") {122 countup.shouldBeLargerThan(countdown)123 }124 succeed("for larger") {125 countup.shouldBeLargerThan(nulls)126 }127 }128 "smaller than" should {129 succeed("for empty") {130 empty.shouldBeSmallerThan(single)131 }132 fail("with empty") {133 single.shouldBeSmallerThan(empty)134 }135 succeed("for smaller") {136 nulls.shouldBeSmallerThan(countup)137 }138 fail("for same count") {139 countup.shouldBeSmallerThan(countdown)140 }141 fail("for larger") {142 countup.shouldBeSmallerThan(nulls)143 }144 }145 "same count" should {146 fail("for empty with any") {147 empty.shouldBeSameCountAs(single)148 }149 fail("for any with empty") {150 nulls.shouldBeSameCountAs(empty)151 }152 fail("for smaller") {153 nulls.shouldBeSameCountAs(countup)154 }155 succeed("with same count") {156 countup.shouldBeSameCountAs(countdown)157 }158 fail("for larger") {159 countup.shouldBeSmallerThan(nulls)160 }161 }162 "at least count" should {163 succeed("for empty with -1") {164 empty.shouldHaveAtLeastCount(-1)165 }166 succeed("for any with -1") {167 countup.shouldHaveAtLeastCount(-1)168 }169 succeed("for empty with 0") {170 empty.shouldHaveAtLeastCount(0)171 }172 fail("for empty with 1") {173 empty.shouldHaveAtLeastCount(1)174 }175 succeed("for smaller count") {176 single.shouldHaveAtLeastCount(0)177 }178 succeed("for same count") {179 nulls.shouldHaveAtLeastCount(nulls.count())180 }181 fail("for larger count") {182 countup.shouldHaveAtLeastCount(countup.count() + 1)183 }184 }185 "at most count" should {186 fail("for empty with -1") {187 empty.shouldHaveAtMostCount(-1)188 }189 succeed("for empty with 0") {190 empty.shouldHaveAtMostCount(0)191 }192 succeed("for empty with 1") {193 empty.shouldHaveAtMostCount(1)194 }195 fail("for smaller count") {196 countup.shouldHaveAtMostCount(countup.count() - 1)197 }198 succeed("for same count") {199 countup.shouldHaveAtMostCount(countup.count())200 }201 succeed("for larger count") {202 countup.shouldHaveAtMostCount(countup.count() + 1)203 }204 }205 /* contain */206 /** null */207 "contain only nulls" should {208 succeed("for empty") {209 empty.shouldContainOnlyNulls()210 }211 fail("for single") {212 single.shouldContainOnlyNulls()213 }214 succeed("for nulls") {215 nulls.shouldContainOnlyNulls()216 }217 fail("for sparse") {218 sparse.shouldContainOnlyNulls()219 }220 }221 "not contain only nulls" should {222 fail("for empty") {223 empty.shouldNotContainOnlyNulls()224 }225 "fail for single" {226 single.shouldNotContainOnlyNulls()227 }228 fail("for nulls") {229 nulls.shouldNotContainOnlyNulls()230 }231 succeed("for sparse") {232 sparse.shouldNotContainOnlyNulls()233 }234 }235 "contain a null" should {236 fail("for empty") {237 empty.shouldContainNull()238 }239 fail("for non-nulls") {240 single.shouldContainNull()241 }242 succeed("for nulls") {243 nulls.shouldContainNull()244 }245 succeed("for sparse") {246 sparse.shouldContainNull()247 }248 }249 "not contain a null" should {250 succeed("for empty") {251 empty.shouldNotContainNull()252 }253 succeed("for non-nulls") {254 single.shouldNotContainNull()255 }256 fail("for nulls") {257 nulls.shouldNotContainNull()258 }259 fail("for sparse") {260 sparse.shouldNotContainNull()261 }262 }263 "contain no nulls" should {264 succeed("for empty") {265 empty.shouldContainNoNulls()266 }267 succeed("for non-nulls") {268 single.shouldContainNoNulls()269 }270 fail("for nulls") {271 nulls.shouldContainNoNulls()272 }273 fail("for sparse") {274 sparse.shouldContainNoNulls()275 }276 }277 "not contain no nulls" should {278 fail("for empty") {279 empty.shouldNotContainNoNulls()280 }281 fail("for non-nulls") {282 single.shouldNotContainNoNulls()283 }284 succeed("for nulls") {285 nulls.shouldNotContainNoNulls()286 }287 succeed("for sparse") {288 sparse.shouldNotContainNoNulls()289 }290 }291 /** single-value */292 "single element" should {293 fail("for empty") {294 empty.shouldHaveSingleElement(null)295 }296 succeed("for single") {297 single.shouldHaveSingleElement(single.first())298 }299 fail("for multiple") {300 nulls.shouldHaveSingleElement(null)301 }302 }303 "have element at" should {304 abort<IndexOutOfBoundsException>("for empty") {305 empty.shouldHaveElementAt(empty.count(), 0)306 }307 abort<IndexOutOfBoundsException>("when an element after the end is requested") {308 nulls.shouldHaveElementAt(nulls.count(), 0)309 }310 succeed("when the sequence has the element") {311 countup.shouldHaveElementAt(10, 10)312 }313 fail("when the sequence doesn't have the element") {314 countdown.shouldHaveElementAt(10, 10)315 }316 }317 "not have element at" should {318 abort<IndexOutOfBoundsException>("for empty") {319 empty.shouldNotHaveElementAt(empty.count(), 0)320 }321 abort<IndexOutOfBoundsException>("when an element after the end is requested") {322 nulls.shouldNotHaveElementAt(nulls.count(), 0)323 }324 fail("when the sequence has the element") {325 countup.shouldNotHaveElementAt(10, 10)326 }327 succeed("when the sequence doesn't have the element") {328 countdown.shouldNotHaveElementAt(10, 10)329 }330 }331 "contain" should {332 fail("for empty") {333 empty.shouldContain(0)334 }335 succeed("when the sequence contains the value") {336 countup.shouldContain(2)337 }338 fail("when the sequence doesn't contain the value") {339 sparse.shouldContain(2)340 }341 }342 "not contain" should {343 succeed("for empty") {344 empty.shouldNotContain(0)345 }346 fail("when the sequence contains the value") {347 countup.shouldNotContain(2)348 }349 succeed("when the sequence doesn't contain the value") {350 sparse.shouldNotContain(2)351 }352 }353 "exist" should {354 fail("for empty") {355 empty.shouldExist { true }356 }357 succeed("when always true") {358 single.shouldExist { true }359 }360 fail("when always false") {361 countup.shouldExist { false }362 }363 succeed("when matches at least one") {364 countdown.shouldExist { it % 5 == 4 }365 }366 fail("when matches none") {367 countdown.shouldExist { it > 20 }368 }369 }370 /** multiple-value */371 "contain all" should {372 succeed("for empty with empty") {373 empty.shouldContainAll(empty)374 }375 succeed("for empty with empty (variadic)") {376 empty.shouldContainAll()377 }378 fail("for empty with any other") {379 empty.shouldContainAll(single)380 }381 succeed("for any with empty") {382 single.shouldContainAll(empty)383 }384 succeed("for any with empty (variadic)") {385 single.shouldContainAll()386 }387 succeed("for subset of nulls") {388 sparse.shouldContainAll(nulls)389 }390 succeed("for subset of nulls (variadic)") {391 sparse.shouldContainAll(null, null)392 }393 succeed("for subset in order (variadic)") {394 countdown.shouldContainAll(2, 3, 5, 7)395 }396 succeed("for subset not in order (variadic)") {397 countdown.shouldContainAll(2, 5, 3, 7)398 }399 succeed("for same elements") {400 repeating.shouldContainAll(unique)401 }402 succeed("for same elements (variadic)") {403 repeating.shouldContainAll(2, 3, 1)404 }405 succeed("for same elements, repeated") {406 unique.shouldContainAll(repeating)407 }408 succeed("for same elements, repeated (variadic)") {409 unique.shouldContainAll(1, 2, 3, 1, 2, 3)410 }411 }412 "contain exactly empty" should {413 succeed("for empty") {414 empty.shouldContainExactly(sequenceOf<Int>())415 }416 succeed("for empty (variadic)") {417 empty.shouldContainExactly()418 }419 fail("for single") {420 single.shouldContainExactly(empty)421 }422 "fail for single (variadic)" {423 shouldThrowAny {424 single.shouldContainExactly()425 }426 }427 fail("for multiple") {428 nulls.shouldContainExactly(empty)429 }430 fail("for multiple (variadic)") {431 nulls.shouldContainExactly()432 }433 }434 "contain exactly non-empty" should {435 val nonempty = sparse;436 fail("for empty") {437 empty.shouldContainExactly(nonempty)438 }439 fail("for empty (variadic)") {440 empty.shouldContainExactly(*nonempty.toList().toTypedArray())441 }442 succeed("for same") {443 sparse.shouldContainExactly(nonempty)444 }445 succeed("for same (variadic)") {446 sparse.shouldContainExactly(*sparse.toList().toTypedArray())447 }448 fail("for another of different size") {449 countup.shouldContainExactly(nonempty)450 }451 fail("for another of different size (variadic)") {452 countup.shouldContainExactly(*nonempty.toList().toTypedArray())453 }454 fail("for another of same size") {455 nulls.shouldContainExactly(nonempty)456 }457 fail("for another of same size (variadic)") {458 nulls.shouldContainExactly(*nonempty.toList().toTypedArray())459 }460 fail("for same elements but different order") {461 repeating.shouldContainExactly(unique + unique)462 }463 fail("for same elements but different order (variadic)") {464 repeating.shouldContainExactly(1, 1, 2, 2, 3, 3)465 }466 }467 "not contain exactly empty" should {468 fail("for empty") {469 empty.shouldNotContainExactly(sequenceOf<Int>())470 }471 succeed("for single") {472 single.shouldNotContainExactly(empty)473 }474 succeed("for multiple") {475 nulls.shouldNotContainExactly(empty)476 }477 }478 "not contain exactly non-empty" should {479 val nonempty = sparse;480 succeed("for empty") {481 empty.shouldNotContainExactly(nonempty)482 }483 fail("for same") {484 sparse.shouldNotContainExactly(nonempty)485 }486 succeed("for another of different size") {487 countup.shouldNotContainExactly(nonempty)488 }489 succeed("for another of same size") {490 nulls.shouldNotContainExactly(nonempty)491 }492 succeed("for same elements but different order") {493 repeating.shouldNotContainExactly(unique + unique)494 }495 succeed("for same elements but different order (variadic)") {496 repeating.shouldNotContainExactly(1, 1, 2, 2, 3, 3)497 }498 succeed("for single traversable equal sequence") {499 var count1 = 0500 var count2 = 0501 val seq1 = generateSequence { if(count1 < 5) count1++ else null }502 val seq2 = generateSequence { if(count2 < 5) count2++ else null }503 seq1.shouldContainExactly(seq2)504 }505 fail("for single traversable unequal sequence") {506 var count1 = 0507 var count2 = 0508 val seq1 = generateSequence { if(count1 < 5) count1++ else null }509 val seq2 = generateSequence { if(count2 < 6) count2++ else null }510 seq1.shouldContainExactly(seq2)511 }512 }513 "contain in any order" should {514 succeed("for empty with empty") {515 empty.shouldContainAllInAnyOrder(empty)516 }517 fail("for empty with any other") {518 empty.shouldContainAllInAnyOrder(nulls)519 }520 succeed("when elements are same") {521 countdown.shouldContainAllInAnyOrder(countup)522 }523 fail("for overlapping sequence") {524 countup.shouldContainAllInAnyOrder((5..15).asSequence())525 }526 succeed("for subset, same count with nulls") {527 sparse.shouldContainAllInAnyOrder(nulls)528 }529 succeed("for subset, same count") {530 repeating.shouldContainAllInAnyOrder(unique + unique)531 }532 succeed("for subset, same count (variadic)") {533 repeating.shouldContainAllInAnyOrder(1, 1, 2, 2, 3, 3)534 }535 fail("for subset, different count with nulls") {536 sparse.shouldContainAllInAnyOrder(sparse.toSet().asSequence())537 }538 fail("for same, different count") {539 repeating.shouldContainAllInAnyOrder(unique)540 }541 }542 "not contain in any order" should {543 fail("for empty with empty") {544 empty.shouldNotContainAllInAnyOrder(empty)545 }546 succeed("for empty with any other") {547 empty.shouldNotContainAllInAnyOrder(nulls)548 }549 fail("when elements are same") {550 countdown.shouldNotContainAllInAnyOrder(countup)551 }552 succeed("for overlapping sequence") {553 countup.shouldNotContainAllInAnyOrder((5..15).asSequence())554 }555 fail("for subset, same count with nulls") {556 sparse.shouldNotContainAllInAnyOrder(nulls)557 }558 fail("for subset, same count") {559 repeating.shouldNotContainAllInAnyOrder(unique + unique)560 }561 fail("for subset, same count (variadic)") {562 repeating.shouldNotContainAllInAnyOrder(1, 1, 2, 2, 3, 3)563 }564 succeed("for subset, different count with nulls") {565 sparse.shouldNotContainAllInAnyOrder(sparse.toSet().asSequence())566 }567 succeed("for same, different count") {568 repeating.shouldNotContainAllInAnyOrder(unique)569 }570 }571 "contain in order" should {572 "with empty" {573 shouldThrowAny {574 countup.shouldContainInOrder(empty)575 }576 }577 fail("with empty (variadic)") {578 countup.shouldContainInOrder()579 }580 fail("for overlapping sequence") {581 countup.shouldContainInOrder((5..15).asSequence())582 }583 fail("for overlapping sequence (variadic)") {584 countup.shouldContainInOrder(*(5..15).toList().toTypedArray())585 }586 succeed("for subset in order") {587 countup.shouldContainInOrder(sequenceOf(2, 3, 5, 7))588 }589 succeed("for subset in order (variadic)") {590 countup.shouldContainInOrder(2, 3, 5, 7)591 }592 succeed("for subset in order with repeats") {593 repeating.shouldContainInOrder(sequenceOf(1, 3, 1, 2))594 }595 succeed("for subset in order with repeats (variadic)") {596 repeating.shouldContainInOrder(1, 3, 1, 2)597 }598 fail("for subset in order with too many repeats") {599 repeating.shouldContainInOrder(sequenceOf(1, 3, 1, 2, 2))600 }601 fail("for subset in order with too many repeats (variadic)") {602 repeating.shouldContainInOrder(1, 3, 1, 2, 2)603 }604 fail("for subset not in order") {605 countup.shouldContainInOrder(sequenceOf(2, 5, 3, 7))606 }607 fail("for subset not in order (variadic)") {608 countup.shouldContainInOrder(2, 5, 3, 7)609 }610 }611 /** unique */612 "unique" should {613 succeed("for empty") {614 empty.shouldBeUnique()615 }616 succeed("for single") {617 single.shouldBeUnique()618 }619 fail("with repeated nulls") {620 sparse.shouldBeUnique()621 }622 fail("with repeats") {623 repeating.shouldBeUnique()624 }625 succeed("for multiple unique") {626 countup.shouldBeUnique()627 }628 }629 "not unique" should {630 fail("for empty") {631 empty.shouldNotBeUnique()632 }633 fail("for single") {634 single.shouldNotBeUnique()635 }636 succeed("with repeated nulls") {637 sparse.shouldNotBeUnique()638 }639 succeed("with repeats") {640 repeating.shouldNotBeUnique()641 }642 fail("for multiple unique") {643 countup.shouldNotBeUnique()644 }645 }646 "duplicates" should {647 fail("for empty") {648 empty.shouldContainDuplicates()649 }650 fail("for single") {651 single.shouldContainDuplicates()652 }653 succeed("with repeated nulls") {654 sparse.shouldContainDuplicates()655 }656 succeed("with repeats") {657 repeating.shouldNotBeUnique()658 }659 fail("for multiple unique") {660 countup.shouldContainDuplicates()661 }662 }663 /* comparable */664 /** bound */665 "have an upper bound" should {666 succeed("for empty") {667 empty.shouldHaveUpperBound(Int.MIN_VALUE)668 }669 succeed("for single") {670 single.shouldHaveUpperBound(0)671 }672 fail("for single with wrong bound") {673 single.shouldHaveUpperBound(-1)674 }675 succeed("for multiple") {676 countup.shouldHaveUpperBound(countup.maxOrNull() ?: Int.MAX_VALUE)677 }678 fail("for multiple with wrong bound") {679 countup.shouldHaveUpperBound((countup.maxOrNull() ?: Int.MAX_VALUE) - 1)680 }681 }682 "have a lower bound" should {683 succeed("for empty") {684 empty.shouldHaveLowerBound(Int.MAX_VALUE)685 }686 succeed("for single") {687 single.shouldHaveLowerBound(0)688 }689 fail("for single with wrong bound") {690 single.shouldHaveLowerBound(1)691 }692 succeed("for multiple") {693 countup.shouldHaveLowerBound(countup.minOrNull() ?: Int.MIN_VALUE)694 }695 fail("for multiple with wrong bound") {696 countup.shouldHaveLowerBound((countup.minOrNull() ?: Int.MIN_VALUE) + 1)697 }698 }699 /** sort */700 "sorted" should {701 succeed("for empty") {702 empty.shouldBeSorted()703 }704 succeed("for single") {705 single.shouldBeSorted()706 }707 fail("for repeating") {708 repeating.shouldBeSorted()709 }710 succeed("for count-up") {711 countup.shouldBeSorted()712 }713 fail("for count-down") {714 countdown.shouldBeSorted()715 }716 }717 "not sorted" should {718 fail("for empty") {719 empty.shouldNotBeSorted()720 }721 fail("for single") {722 single.shouldNotBeSorted()723 }724 succeed("for repeating") {725 repeating.shouldNotBeSorted()726 }727 fail("for count-up") {728 countup.shouldNotBeSorted()729 }730 succeed("for count-down") {731 countdown.shouldNotBeSorted()732 }733 }734 "sorted ascending" should {735 val dir = asc736 succeed("for empty") {737 empty.shouldBeSortedWith(dir)738 }739 succeed("for single") {740 single.shouldBeSortedWith(dir)741 }742 fail("for repeating") {743 repeating.shouldBeSortedWith(dir)744 }745 succeed("for count-up") {746 countup.shouldBeSortedWith(dir)747 }748 fail("for count-down") {749 countdown.shouldBeSortedWith(dir)750 }751 }752 "sorted descending" should {753 val dir = desc754 succeed("for empty") {755 empty.shouldBeSortedWith(dir)756 }757 succeed("for single") {758 single.shouldBeSortedWith(dir)759 }760 fail("for repeating") {761 repeating.shouldBeSortedWith(dir)762 }763 fail("for count-up") {764 countup.shouldBeSortedWith(dir)765 }766 succeed("for count-down") {767 countdown.shouldBeSortedWith(dir)768 }769 }770 "not sorted ascending" should {771 val dir = asc772 fail("for empty") {773 empty.shouldNotBeSortedWith(dir)774 }775 fail("for single") {776 single.shouldNotBeSortedWith(dir)777 }778 succeed("for repeating") {779 repeating.shouldNotBeSortedWith(dir)780 }781 fail("for count-up") {782 countup.shouldNotBeSortedWith(dir)783 }784 succeed("for count-down") {785 countdown.shouldNotBeSortedWith(dir)786 }787 }788 "not sorted descending" should {789 val dir = desc790 fail("for empty") {791 empty.shouldNotBeSortedWith(dir)792 }793 fail("for single") {794 single.shouldNotBeSortedWith(dir)795 }796 succeed("for repeating") {797 repeating.shouldNotBeSortedWith(dir)798 }799 succeed("for count-up") {800 countup.shouldNotBeSortedWith(dir)801 }802 fail("for count-down") {803 countdown.shouldNotBeSortedWith(dir)804 }805 }806 }807}...

Full Screen

Full Screen

matchers.kt

Source:matchers.kt Github

copy

Full Screen

1package io.kotest.matchers.sequences2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.neverNullMatcher5import io.kotest.matchers.should6import io.kotest.matchers.shouldHave7import io.kotest.matchers.shouldNot8private fun <T> Sequence<T>.toString(limit: Int = 10) = this.joinToString(", ", limit = limit)9/*10How should infinite sequences be detected, and how should they be dealt with?11Sequence<T>.count() may run through the whole sequence (sequences from `generateSequence()` do so), so isn't always a safe way to detect infinite sequences.12For now, the documentation should mention that infinite sequences will cause these matchers never to halt.13*/14fun <T> Sequence<T>.shouldContainOnlyNulls() = this should containOnlyNulls()15fun <T> Sequence<T>.shouldNotContainOnlyNulls() = this shouldNot containOnlyNulls()16fun <T> containOnlyNulls() = object : Matcher<Sequence<T>> {17 override fun test(value: Sequence<T>) =18 MatcherResult(19 value.all { it == null },20 "Sequence should contain only nulls",21 "Sequence should not contain only nulls"22 )23}24fun <T> Sequence<T>.shouldContainNull() = this should containNull()25fun <T> Sequence<T>.shouldNotContainNull() = this shouldNot containNull()26fun <T> containNull() = object : Matcher<Sequence<T>> {27 override fun test(value: Sequence<T>) =28 MatcherResult(29 value.any { it == null },30 "Sequence should contain at least one null",31 "Sequence should not contain any nulls"32 )33}34fun <T> Sequence<T>.shouldHaveElementAt(index: Int, element: T) = this should haveElementAt(index, element)35fun <T> Sequence<T>.shouldNotHaveElementAt(index: Int, element: T) = this shouldNot haveElementAt(index, element)36fun <T, S : Sequence<T>> haveElementAt(index: Int, element: T) = object : Matcher<S> {37 override fun test(value: S) =38 MatcherResult(39 value.elementAt(index) == element,40 { "Sequence should contain $element at index $index" },41 { "Sequence should not contain $element at index $index" }42 )43}44fun <T> Sequence<T>.shouldContainNoNulls() = this should containNoNulls()45fun <T> Sequence<T>.shouldNotContainNoNulls() = this shouldNot containNoNulls()46fun <T> containNoNulls() = object : Matcher<Sequence<T>> {47 override fun test(value: Sequence<T>) =48 MatcherResult(49 value.all { it != null },50 { "Sequence should not contain nulls" },51 { "Sequence should have at least one null" }52 )53}54infix fun <T, C : Sequence<T>> C.shouldContain(t: T) = this should contain(t)55infix fun <T, C : Sequence<T>> C.shouldNotContain(t: T) = this shouldNot contain(t)56fun <T, C : Sequence<T>> contain(t: T) = object : Matcher<C> {57 override fun test(value: C) = MatcherResult(58 value.contains(t),59 { "Sequence should contain element $t" },60 { "Sequence should not contain element $t" }61 )62}63infix fun <T, C : Sequence<T>> C?.shouldNotContainExactly(expected: C) = this shouldNot containExactly(expected)64fun <T, C : Sequence<T>> C?.shouldNotContainExactly(vararg expected: T) = this shouldNot containExactly(*expected)65infix fun <T, C : Sequence<T>> C?.shouldContainExactly(expected: C) = this should containExactly(expected)66fun <T, C : Sequence<T>> C?.shouldContainExactly(vararg expected: T) = this should containExactly(*expected)67fun <T> containExactly(vararg expected: T): Matcher<Sequence<T>?> = containExactly(expected.asSequence())68/** Assert that a sequence contains exactly the given values and nothing else, in order. */69fun <T, C : Sequence<T>> containExactly(expected: C): Matcher<C?> = neverNullMatcher { value ->70 var passed: Boolean = value.count() == expected.count()71 var failMessage = "Sequence should contain exactly $expected but was $value"72 if (passed) {73 val diff = value.zip(expected) { a, b -> Triple(a, b, a == b) }.withIndex().find { !it.value.third }74 if (diff != null) {75 passed = false76 failMessage += " (expected ${diff.value.second} at ${diff.index} but found ${diff.value.first})"77 }78 } else {79 failMessage += " (expected ${expected.count()} elements but found ${value.count()})"80 }81 MatcherResult(82 passed,83 failMessage,84 "Sequence should not be exactly $expected"85 )86}87@Deprecated("use shouldNotContainAllInAnyOrder", ReplaceWith("shouldNotContainAllInAnyOrder"))88infix fun <T, C : Sequence<T>> C?.shouldNotContainExactlyInAnyOrder(expected: C) =89 this shouldNot containAllInAnyOrder(expected)90@Deprecated("use shouldNotContainAllInAnyOrder", ReplaceWith("shouldNotContainAllInAnyOrder"))91fun <T, C : Sequence<T>> C?.shouldNotContainExactlyInAnyOrder(vararg expected: T) =92 this shouldNot containAllInAnyOrder(*expected)93@Deprecated("use shouldContainAllInAnyOrder", ReplaceWith("shouldContainAllInAnyOrder"))94infix fun <T, C : Sequence<T>> C?.shouldContainExactlyInAnyOrder(expected: C) =95 this should containAllInAnyOrder(expected)96@Deprecated("use shouldContainAllInAnyOrder", ReplaceWith("shouldContainAllInAnyOrder"))97fun <T, C : Sequence<T>> C?.shouldContainExactlyInAnyOrder(vararg expected: T) =98 this should containAllInAnyOrder(*expected)99@Deprecated("use containAllInAnyOrder", ReplaceWith("containAllInAnyOrder"))100fun <T> containExactlyInAnyOrder(vararg expected: T): Matcher<Sequence<T>?> =101 containAllInAnyOrder(expected.asSequence())102@Deprecated("use containAllInAnyOrder", ReplaceWith("containAllInAnyOrder"))103/** Assert that a sequence contains the given values and nothing else, in any order. */104fun <T, C : Sequence<T>> containExactlyInAnyOrder(expected: C): Matcher<C?> = containAllInAnyOrder(expected)105infix fun <T, C : Sequence<T>> C?.shouldNotContainAllInAnyOrder(expected: C) =106 this shouldNot containAllInAnyOrder(expected)107fun <T, C : Sequence<T>> C?.shouldNotContainAllInAnyOrder(vararg expected: T) =108 this shouldNot containAllInAnyOrder(*expected)109infix fun <T, C : Sequence<T>> C?.shouldContainAllInAnyOrder(expected: C) =110 this should containAllInAnyOrder(expected)111fun <T, C : Sequence<T>> C?.shouldContainAllInAnyOrder(vararg expected: T) =112 this should containAllInAnyOrder(*expected)113fun <T> containAllInAnyOrder(vararg expected: T): Matcher<Sequence<T>?> =114 containAllInAnyOrder(expected.asSequence())115/** Assert that a sequence contains all the given values and nothing else, in any order. */116fun <T, C : Sequence<T>> containAllInAnyOrder(expected: C): Matcher<C?> = neverNullMatcher { value ->117 val passed = value.count() == expected.count() && expected.all { value.contains(it) }118 MatcherResult(119 passed,120 { "Sequence should contain the values of $expected in any order, but was $value" },121 { "Sequence should not contain the values of $expected in any order" }122 )123}124infix fun <T : Comparable<T>, C : Sequence<T>> C.shouldHaveUpperBound(t: T) = this should haveUpperBound(t)125fun <T : Comparable<T>, C : Sequence<T>> haveUpperBound(t: T) = object : Matcher<C> {126 override fun test(value: C) = MatcherResult(127 (value.maxOrNull() ?: t) <= t,128 { "Sequence should have upper bound $t" },129 { "Sequence should not have upper bound $t" }130 )131}132infix fun <T : Comparable<T>, C : Sequence<T>> C.shouldHaveLowerBound(t: T) = this should haveLowerBound(t)133fun <T : Comparable<T>, C : Sequence<T>> haveLowerBound(t: T) = object : Matcher<C> {134 override fun test(value: C) = MatcherResult(135 (value.minOrNull() ?: t) >= t,136 { "Sequence should have lower bound $t" },137 { "Sequence should not have lower bound $t" }138 )139}140fun <T> Sequence<T>.shouldBeUnique() = this should beUnique()141fun <T> Sequence<T>.shouldNotBeUnique() = this shouldNot beUnique()142fun <T> beUnique() = object : Matcher<Sequence<T>> {143 override fun test(value: Sequence<T>) = MatcherResult(144 value.toSet().size == value.count(),145 { "Sequence should be Unique" },146 { "Sequence should contain at least one duplicate element" }147 )148}149fun <T> Sequence<T>.shouldContainDuplicates() = this should containDuplicates()150fun <T> Sequence<T>.shouldNotContainDuplicates() = this shouldNot containDuplicates()151fun <T> containDuplicates() = object : Matcher<Sequence<T>> {152 override fun test(value: Sequence<T>) = MatcherResult(153 value.toSet().size < value.count(),154 { "Sequence should contain duplicates" },155 { "Sequence should not contain duplicates" }156 )157}158fun <T : Comparable<T>> Sequence<T>.shouldBeSorted() = this should beSorted()159fun <T : Comparable<T>> Sequence<T>.shouldNotBeSorted() = this shouldNot beSorted()160fun <T : Comparable<T>> beSorted(): Matcher<Sequence<T>> = sorted()161fun <T : Comparable<T>> sorted(): Matcher<Sequence<T>> = object : Matcher<Sequence<T>> {162 override fun test(value: Sequence<T>): MatcherResult {163 @Suppress("UNUSED_DESTRUCTURED_PARAMETER_ENTRY")164 val failure = value.zipWithNext().withIndex().firstOrNull { (i, it) -> it.first > it.second }165 val snippet = value.joinToString(",", limit = 10)166 val elementMessage = when (failure) {167 null -> ""168 else -> ". Element ${failure.value.first} at index ${failure.index} was greater than element ${failure.value.second}"169 }170 return MatcherResult(171 failure == null,172 { "Sequence $snippet should be sorted$elementMessage" },173 { "Sequence $snippet should not be sorted" }174 )175 }176}177infix fun <T> Sequence<T>.shouldBeSortedWith(comparator: Comparator<in T>) = this should beSortedWith(comparator)178infix fun <T> Sequence<T>.shouldBeSortedWith(cmp: (T, T) -> Int) = this should beSortedWith(cmp)179fun <T> beSortedWith(comparator: Comparator<in T>): Matcher<Sequence<T>> = sortedWith(comparator)180fun <T> beSortedWith(cmp: (T, T) -> Int): Matcher<Sequence<T>> = sortedWith(cmp)181fun <T> sortedWith(comparator: Comparator<in T>): Matcher<Sequence<T>> = sortedWith { a, b ->182 comparator.compare(a, b)183}184fun <T> sortedWith(cmp: (T, T) -> Int): Matcher<Sequence<T>> = object : Matcher<Sequence<T>> {185 override fun test(value: Sequence<T>): MatcherResult {186 @Suppress("UNUSED_DESTRUCTURED_PARAMETER_ENTRY")187 val failure = value.zipWithNext().withIndex().firstOrNull { (i, it) -> cmp(it.first, it.second) > 0 }188 val snippet = value.joinToString(",", limit = 10)189 val elementMessage = when (failure) {190 null -> ""191 else -> ". Element ${failure.value.first} at index ${failure.index} shouldn't precede element ${failure.value.second}"192 }193 return MatcherResult(194 failure == null,195 { "Sequence $snippet should be sorted$elementMessage" },196 { "Sequence $snippet should not be sorted" }197 )198 }199}200infix fun <T> Sequence<T>.shouldNotBeSortedWith(comparator: Comparator<in T>) = this shouldNot beSortedWith(comparator)201infix fun <T> Sequence<T>.shouldNotBeSortedWith(cmp: (T, T) -> Int) = this shouldNot beSortedWith(cmp)202infix fun <T> Sequence<T>.shouldHaveSingleElement(t: T) = this should singleElement(t)203infix fun <T> Sequence<T>.shouldNotHaveSingleElement(t: T) = this shouldNot singleElement(t)204fun <T> singleElement(t: T) = object : Matcher<Sequence<T>> {205 override fun test(value: Sequence<T>) = MatcherResult(206 value.count() == 1 && value.first() == t,207 { "Sequence should be a single element of $t but has ${value.count()} elements" },208 { "Sequence should not be a single element of $t" }209 )210}211infix fun <T> Sequence<T>.shouldHaveCount(count: Int) = this should haveCount(count)212infix fun <T> Sequence<T>.shouldNotHaveCount(count: Int) = this shouldNot haveCount(213 count)214infix fun <T> Sequence<T>.shouldHaveSize(size: Int) = this should haveCount(size)215infix fun <T> Sequence<T>.shouldNotHaveSize(size: Int) = this shouldNot haveCount(size)216//fun <T> haveSize(size: Int) = haveCount(size)217fun <T> haveSize(size: Int): Matcher<Sequence<T>> = haveCount(size)218fun <T> haveCount(count: Int): Matcher<Sequence<T>> = object : Matcher<Sequence<T>> {219 override fun test(value: Sequence<T>) =220 MatcherResult(221 value.count() == count,222 { "Sequence should have count $count but has count ${value.count()}" },223 { "Sequence should not have count $count" }224 )225}226infix fun <T, U> Sequence<T>.shouldBeLargerThan(other: Sequence<U>) = this should beLargerThan(other)227fun <T, U> beLargerThan(other: Sequence<U>) = object : Matcher<Sequence<T>> {228 override fun test(value: Sequence<T>) = MatcherResult(229 value.count() > other.count(),230 { "Sequence of count ${value.count()} should be larger than sequence of count ${other.count()}" },231 { "Sequence of count ${value.count()} should not be larger than sequence of count ${other.count()}" }232 )233}234infix fun <T, U> Sequence<T>.shouldBeSmallerThan(other: Sequence<U>) = this should beSmallerThan(other)235fun <T, U> beSmallerThan(other: Sequence<U>) = object : Matcher<Sequence<T>> {236 override fun test(value: Sequence<T>) = MatcherResult(237 value.count() < other.count(),238 { "Sequence of count ${value.count()} should be smaller than sequence of count ${other.count()}" },239 { "Sequence of count ${value.count()} should not be smaller than sequence of count ${other.count()}" }240 )241}242infix fun <T, U> Sequence<T>.shouldBeSameCountAs(other: Sequence<U>) = this should beSameCountAs(243 other)244fun <T, U> beSameCountAs(other: Sequence<U>) = object : Matcher<Sequence<T>> {245 override fun test(value: Sequence<T>) = MatcherResult(246 value.count() == other.count(),247 { "Sequence of count ${value.count()} should be the same count as sequence of count ${other.count()}" },248 { "Sequence of count ${value.count()} should not be the same count as sequence of count ${other.count()}" }249 )250}251infix fun <T, U> Sequence<T>.shouldBeSameSizeAs(other: Sequence<U>) = this.shouldBeSameCountAs(other)252infix fun <T> Sequence<T>.shouldHaveAtLeastCount(n: Int) = this shouldHave atLeastCount(n)253fun <T> atLeastCount(n: Int) = object : Matcher<Sequence<T>> {254 override fun test(value: Sequence<T>) = MatcherResult(255 value.count() >= n,256 { "Sequence should contain at least $n elements" },257 { "Sequence should contain less than $n elements" }258 )259}260infix fun <T> Sequence<T>.shouldHaveAtLeastSize(n: Int) = this.shouldHaveAtLeastCount(n)261infix fun <T> Sequence<T>.shouldHaveAtMostCount(n: Int) = this shouldHave atMostCount(n)262fun <T> atMostCount(n: Int) = object : Matcher<Sequence<T>> {263 override fun test(value: Sequence<T>) = MatcherResult(264 value.count() <= n,265 { "Sequence should contain at most $n elements" },266 { "Sequence should contain more than $n elements" }267 )268}269infix fun <T> Sequence<T>.shouldHaveAtMostSize(n: Int) = this shouldHave atMostCount(n)270infix fun <T> Sequence<T>.shouldExist(p: (T) -> Boolean) = this should exist(p)271fun <T> exist(p: (T) -> Boolean) = object : Matcher<Sequence<T>> {272 override fun test(value: Sequence<T>) = MatcherResult(273 value.any { p(it) },274 { "Sequence should contain an element that matches the predicate $p" },275 { "Sequence should not contain an element that matches the predicate $p" }276 )277}278fun <T : Comparable<T>> Sequence<T>.shouldContainInOrder(vararg ts: T) =279 this should containsInOrder(ts.asSequence())280infix fun <T : Comparable<T>> Sequence<T>.shouldContainInOrder(expected: Sequence<T>) =281 this should containsInOrder(expected)282fun <T : Comparable<T>> Sequence<T>.shouldNotContainInOrder(expected: Sequence<T>) =283 this shouldNot containsInOrder(expected)284/** Assert that a sequence contains a given subsequence, possibly with values in between. */285fun <T> containsInOrder(subsequence: Sequence<T>): Matcher<Sequence<T>?> = neverNullMatcher { actual ->286 val subsequenceCount = subsequence.count()287 require(subsequenceCount > 0) { "expected values must not be empty" }288 var subsequenceIndex = 0289 val actualIterator = actual.iterator()290 while (actualIterator.hasNext() && subsequenceIndex < subsequenceCount) {291 if (actualIterator.next() == subsequence.elementAt(subsequenceIndex)) subsequenceIndex += 1292 }293 MatcherResult(294 subsequenceIndex == subsequence.count(),295 { "[$actual] did not contain the elements [$subsequence] in order" },296 { "[$actual] should not contain the elements [$subsequence] in order" }297 )298}299fun <T> Sequence<T>.shouldBeEmpty() = this should beEmpty()300fun <T> Sequence<T>.shouldNotBeEmpty() = this shouldNot beEmpty()301fun <T> beEmpty(): Matcher<Sequence<T>> = object : Matcher<Sequence<T>> {302 override fun test(value: Sequence<T>): MatcherResult = MatcherResult(303 value.count() == 0,304 { "Sequence should be empty" },305 { "Sequence should not be empty" }306 )307}308fun <T> Sequence<T>.shouldContainAll(vararg ts: T) = this should containAll(ts.asSequence())309infix fun <T> Sequence<T>.shouldContainAll(ts: Collection<T>) = this should containAll(ts.asSequence())310infix fun <T> Sequence<T>.shouldContainAll(ts: Sequence<T>) = this should containAll(ts)311fun <T> Sequence<T>.shouldNotContainAll(vararg ts: T) = this shouldNot containAll(ts.asSequence())312infix fun <T> Sequence<T>.shouldNotContainAll(ts: Collection<T>) = this shouldNot containAll(ts.asSequence())313infix fun <T> Sequence<T>.shouldNotContainAll(ts: Sequence<T>) = this shouldNot containAll(ts)314fun <T, C : Sequence<T>> containAll(ts: C): Matcher<Sequence<T>> = object : Matcher<Sequence<T>> {315 override fun test(value: Sequence<T>): MatcherResult = MatcherResult(316 ts.all { value.contains(it) },317 { "Sequence should contain all of ${value.joinToString(",", limit = 10)}" },318 { "Sequence should not contain all of ${value.joinToString(",", limit = 10)}" }319 )320}...

Full Screen

Full Screen

Sequence.shouldHaveElementAt

Using AI Code Generation

copy

Full Screen

1val seq = sequenceOf(1, 2, 3)2seq.shouldHaveElementAt(0, 1)3seq.shouldHaveElementAt(1, 2)4seq.shouldHaveElementAt(2, 3)5seq.shouldHaveElementAt(3, null)6seq.shouldHaveElementAt(-1, null)7seq.shouldHaveElementAt(4, null)8val seq = sequenceOf(1, 2, 3)9seq.shouldHaveElements(1, 2, 3)10val seq = sequenceOf(1, 2, 3)11seq.shouldHaveFirst(1)12val seq = sequenceOf(1, 2, 3)13seq.shouldHaveLast(3)14val seq = sequenceOf(1)15seq.shouldHaveSingleElement(1)16val seq = sequenceOf(1, 2, 3)17seq.shouldHaveSingleElement(null)18val seq = sequenceOf(1, 2, 3)19seq.shouldHaveSize(3)20val seq = sequenceOf(1, 2, 3)21seq.shouldHaveUniqueElements()22val seq = sequenceOf(1, 2, 2)23seq.shouldHaveUniqueElements(null)24val seq = sequenceOf()25seq.shouldHaveZeroElements()26val seq = sequenceOf(1)27seq.shouldHaveZeroElements(null)28val seq = sequenceOf(1)29seq.shouldNotBeEmpty()30val seq = sequenceOf(1, 2

Full Screen

Full Screen

Sequence.shouldHaveElementAt

Using AI Code Generation

copy

Full Screen

1val seq = sequenceOf(1, 2, 3, 4, 5)2seq.shouldHaveElementAt(0, 1)3seq.shouldHaveElementAt(1, 2)4seq.shouldHaveElementAt(2, 3)5seq.shouldHaveElementAt(3, 4)6seq.shouldHaveElementAt(4, 5)7val seq = sequenceOf(1, 2, 3, 4, 5)8seq.shouldHaveElementAt(0, 1)9seq.shouldHaveElementAt(1, 2)10seq.shouldHaveElementAt(2, 3)11seq.shouldHaveElementAt(3, 4)12seq.shouldHaveElementAt(4, 5)13val seq = sequenceOf(1, 2, 3, 4, 5)14seq.shouldHaveElementAt(0, 1)15seq.shouldHaveElementAt(1, 2)16seq.shouldHaveElementAt(2, 3)17seq.shouldHaveElementAt(3, 4)18seq.shouldHaveElementAt(4, 5)19val seq = sequenceOf(1, 2, 3, 4, 5)20seq.shouldHaveElementAt(0, 1)21seq.shouldHaveElementAt(1, 2)22seq.shouldHaveElementAt(2, 3)23seq.shouldHaveElementAt(3, 4)24seq.shouldHaveElementAt(4, 5)

Full Screen

Full Screen

Sequence.shouldHaveElementAt

Using AI Code Generation

copy

Full Screen

1Sequence.shouldHaveElementAt(0, 1)2Sequence.shouldHaveElementAt(1, 2)3Sequence.shouldHaveElementAt(2, 3)4Sequence.shouldHaveElementAt(3, 4)5Sequence.shouldHaveElementAt(4, 5)6Sequence.shouldHaveElementAt(5, 6)7Sequence.shouldHaveElementAt(6, 7)8Sequence.shouldHaveElementAt(7, 8)9Sequence.shouldHaveElementAt(8, 9)10Sequence.shouldHaveElementAt(9, 10)11Sequence.shouldHaveElementAt(10, 11)12Sequence.shouldHaveElementAt(11, 12)13Sequence.shouldHaveElementAt(12, 13)14Sequence.shouldHaveElementAt(13, 14)15Sequence.shouldHaveElementAt(14, 15)16Sequence.shouldHaveElementAt(15, 16)17Sequence.shouldHaveElementAt(16, 17)18Sequence.shouldHaveElementAt(17, 18)19Sequence.shouldHaveElementAt(18, 19)20Sequence.shouldHaveElementAt(19, 20)21Sequence.shouldHaveElementAt(20, 21)22Sequence.shouldHaveElementAt(21, 22)23Sequence.shouldHaveElementAt(22, 23)24Sequence.shouldHaveElementAt(23, 24)25Sequence.shouldHaveElementAt(24, 25)26Sequence.shouldHaveElementAt(25, 26)27Sequence.shouldHaveElementAt(26, 27)28Sequence.shouldHaveElementAt(27, 28)29Sequence.shouldHaveElementAt(28, 29)30Sequence.shouldHaveElementAt(29, 30)31Sequence.shouldHaveElementAt(30, 31)32Sequence.shouldHaveElementAt(31, 32)33Sequence.shouldHaveElementAt(32, 33)34Sequence.shouldHaveElementAt(33, 34)35Sequence.shouldHaveElementAt(34, 35)36Sequence.shouldHaveElementAt(35, 36)37Sequence.shouldHaveElementAt(36, 37)38Sequence.shouldHaveElementAt(37, 38)39Sequence.shouldHaveElementAt(38, 39)40Sequence.shouldHaveElementAt(39, 40)41Sequence.shouldHaveElementAt(40, 41)42Sequence.shouldHaveElementAt(41, 42)43Sequence.shouldHaveElementAt(42, 43)44Sequence.shouldHaveElementAt(43, 44)45Sequence.shouldHaveElementAt(44, 45)

Full Screen

Full Screen

Sequence.shouldHaveElementAt

Using AI Code Generation

copy

Full Screen

1Sequence.shouldHaveElementAt(1, "b")2Sequence.shouldHaveLast("c")3Sequence.shouldHaveSingleElement("a")4Sequence.shouldNotBeEmpty()5Sequence.shouldNotBeInfinite()6Sequence.shouldNotContain("a")7Sequence.shouldNotContainAll("a", "b", "c")8Sequence.shouldNotContainAny("a", "b", "c")9Sequence.shouldNotContainDuplicates()10Sequence.shouldNotHaveElementAt(1, "b")11Sequence.shouldNotHaveLast("c")12Sequence.shouldNotHaveSingleElement("a")13Sequence.shouldNotStartWith("a")14Sequence.shouldStartWith("a")15Sequence.shouldStartWithInOrder("a")16Sequence.shouldStartWithInOrderIgnoringCase("a")

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful