How to use sorted class of io.kotest.matchers.collections package

Best Kotest code snippet using io.kotest.matchers.collections.sorted

ReasonableDefaultElementsTest.kt

Source:ReasonableDefaultElementsTest.kt Github

copy

Full Screen

...92 }93 }94 }95 "All default elements" should {96 "be sorted" {97 allDefaultElements98 .keys99 .toList()100 .shouldBeSorted()101 Elements.allElements()102 .keys103 .toList()104 .shouldBeSorted()105 Elements.allCommandingElements()106 .keys107 .toList()108 .shouldBeSorted()109 }110 "have a name" {...

Full Screen

Full Screen

FailingKotestAsserts.kt

Source:FailingKotestAsserts.kt Github

copy

Full Screen

1package testing.failing2import arrow.core.*3import io.kotest.assertions.arrow.either.shouldBeLeft4import io.kotest.assertions.arrow.either.shouldBeRight5import io.kotest.assertions.arrow.nel.shouldContain6import io.kotest.assertions.arrow.nel.shouldContainNull7import io.kotest.assertions.arrow.option.shouldBeNone8import io.kotest.assertions.arrow.option.shouldBeSome9import io.kotest.assertions.arrow.validation.shouldBeInvalid10import io.kotest.assertions.arrow.validation.shouldBeValid11import io.kotest.assertions.asClue12import io.kotest.assertions.assertSoftly13import io.kotest.assertions.json.*14import io.kotest.assertions.throwables.shouldThrowAny15import io.kotest.assertions.throwables.shouldThrowExactly16import io.kotest.assertions.withClue17import io.kotest.matchers.Matcher18import io.kotest.matchers.MatcherResult19import io.kotest.matchers.booleans.shouldBeFalse20import io.kotest.matchers.booleans.shouldBeTrue21import io.kotest.matchers.collections.shouldBeEmpty22import io.kotest.matchers.collections.shouldBeOneOf23import io.kotest.matchers.collections.shouldBeSameSizeAs24import io.kotest.matchers.collections.shouldBeSorted25import io.kotest.matchers.collections.shouldContain26import io.kotest.matchers.date.shouldBeAfter27import io.kotest.matchers.ints.shouldBeEven28import io.kotest.matchers.ints.shouldBeGreaterThan29import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual30import io.kotest.matchers.ints.shouldBeLessThan31import io.kotest.matchers.ints.shouldBeLessThanOrEqual32import io.kotest.matchers.ints.shouldBeZero33import io.kotest.matchers.maps.shouldBeEmpty34import io.kotest.matchers.maps.shouldContain35import io.kotest.matchers.maps.shouldContainKey36import io.kotest.matchers.maps.shouldContainValue37import io.kotest.matchers.nulls.shouldBeNull38import io.kotest.matchers.should39import io.kotest.matchers.shouldBe40import io.kotest.matchers.shouldNot41import io.kotest.matchers.string.shouldBeBlank42import io.kotest.matchers.string.shouldBeEmpty43import io.kotest.matchers.string.shouldBeUpperCase44import io.kotest.matchers.string.shouldContain45import io.kotest.matchers.string.shouldNotBeBlank46import java.time.LocalDate47import org.junit.jupiter.api.Test48/**49 * Kotest assertions50 *51 * - [Kotest Assertions Documentation](https://kotest.io/assertions/)52 * - [Github](https://github.com/kotest/kotest/)53 */54class FailingKotestAsserts {55 @Test56 fun `General assertions`() {57 assertSoftly {58 "text" shouldBe "txet"59 "hi".shouldBeBlank()60 " ".shouldNotBeBlank()61 "hi".shouldBeEmpty()62 "hi".shouldBeUpperCase()63 "hello".shouldContain("hi")64 false.shouldBeTrue()65 true.shouldBeFalse()66 "not null".shouldBeNull()67 10 shouldBeLessThan 1068 10 shouldBeLessThanOrEqual 969 11 shouldBeGreaterThan 1170 11 shouldBeGreaterThanOrEqual 1271 9.shouldBeEven()72 1.shouldBeZero()73 }74 }75 @Test76 fun `Exception assertions`() {77 assertSoftly {78 shouldThrowExactly<IllegalArgumentException> {79 angryFunction()80 }81 shouldThrowAny {82 "I'm not throwing anything"83 }84 }85 }86 @Test87 fun `Collection assertions`() {88 assertSoftly {89 listOf(1, 2, 3).shouldBeEmpty()90 listOf(1, 2, 3) shouldContain 491 listOf(1, 3, 2).shouldBeSorted()92 listOf(1, 2, 3, 4) shouldBeSameSizeAs listOf(4, 5, 6)93 1 shouldBeOneOf listOf(2, 3)94 mapOf(1 to "one", 2 to "two", 3 to "three").shouldBeEmpty()95 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContainKey 496 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContainValue "five"97 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContain (6 to "six")98 }99 }100 @Test101 fun `Arrow assertions`() {102 assertSoftly {103 val optionNone = none<String>()104 val optionSome = Some("I am something").toOption()105 optionSome.shouldBeNone()106 optionNone.shouldBeSome()107 val rightEither = Either.Right(1)108 val leftEither = Either.Left("ERROR!!")109 leftEither.shouldBeRight()110 leftEither shouldBeRight 1111 rightEither.shouldBeLeft()112 rightEither shouldBeLeft "ERROR!!"113 val nonEmptyList = NonEmptyList.of(1, 2, 3, 4, 5)114 nonEmptyList shouldContain 6115 nonEmptyList.shouldContainNull()116 val valid = Validated.valid()117 val invalid = Validated.invalid()118 invalid.shouldBeValid()119 valid.shouldBeInvalid()120 }121 }122 @Test123 fun `Json assertions`() {124 val jsonString = "{\"test\": \"property\", \"isTest\": true }"125 assertSoftly {126 jsonString shouldMatchJson "{\"test\": \"otherProperty\"}"127 jsonString shouldContainJsonKey "$.anotherTest"128 jsonString shouldNotContainJsonKey "$.test"129 jsonString.shouldContainJsonKeyValue("$.isTest", false)130 }131 }132 @Test133 fun `Custom assertions`() {134 assertSoftly {135 val sentMail = Mail(136 dateCreated = LocalDate.of(2020, 10, 27),137 sent = true, message = "May you have an amazing day"138 )139 val unsentMail = Mail(140 dateCreated = LocalDate.of(2020, 10, 27),141 sent = false, message = "May you have an amazing day"142 )143 // This is possible144 unsentMail.sent should beSent()145 sentMail.sent shouldNot beSent()146 // This is recommended147 unsentMail.shouldBeSent()148 sentMail.shouldNotBeSent()149 }150 }151 @Test152 fun `withClue usage`() {153 val mail = Mail(154 dateCreated = LocalDate.of(2020, 10, 27),155 sent = false, message = "May you have an amazing day"156 )157 withClue("sent field should be true") {158 mail.sent shouldBe true159 }160 mail.asClue {161 it.dateCreated shouldBeAfter LocalDate.of(2020, 10, 26)162 it.sent shouldBe true163 }164 }165 @Test166 fun `asClue usage`() {167 val mail = Mail(168 dateCreated = LocalDate.of(2020, 10, 27),169 sent = false, message = "May you have an amazing day"170 )171 mail.asClue {172 it.dateCreated shouldBeAfter LocalDate.of(2020, 10, 26)173 it.sent shouldBe true174 }175 }176 fun beSent() = object : Matcher<Boolean> {177 override fun test(value: Boolean) = MatcherResult(value, "Mail.sent should be true", "Mail.sent should be false")178 }179 fun Mail.shouldBeSent() = this.sent should beSent()180 fun Mail.shouldNotBeSent() = this.sent shouldNot beSent()181}182data class Mail(val dateCreated: LocalDate, val sent: Boolean, val message: String)183fun angryFunction() {184 throw IllegalStateException("How dare you!")185}...

Full Screen

Full Screen

KotestAsserts.kt

Source:KotestAsserts.kt Github

copy

Full Screen

1package testing.asserts2import arrow.core.*3import io.kotest.assertions.arrow.either.shouldBeLeft4import io.kotest.assertions.arrow.either.shouldBeRight5import io.kotest.assertions.arrow.nel.shouldContain6import io.kotest.assertions.arrow.nel.shouldContainNull7import io.kotest.assertions.arrow.option.shouldBeNone8import io.kotest.assertions.arrow.option.shouldBeSome9import io.kotest.assertions.arrow.validation.shouldBeInvalid10import io.kotest.assertions.arrow.validation.shouldBeValid11import io.kotest.assertions.asClue12import io.kotest.assertions.json.*13import io.kotest.assertions.throwables.shouldThrowAny14import io.kotest.assertions.throwables.shouldThrowExactly15import io.kotest.assertions.withClue16import io.kotest.matchers.Matcher17import io.kotest.matchers.MatcherResult18import io.kotest.matchers.booleans.shouldBeFalse19import io.kotest.matchers.booleans.shouldBeTrue20import io.kotest.matchers.collections.shouldBeEmpty21import io.kotest.matchers.collections.shouldBeOneOf22import io.kotest.matchers.collections.shouldBeSameSizeAs23import io.kotest.matchers.collections.shouldBeSorted24import io.kotest.matchers.collections.shouldContain25import io.kotest.matchers.date.shouldBeAfter26import io.kotest.matchers.ints.shouldBeEven27import io.kotest.matchers.ints.shouldBeGreaterThan28import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual29import io.kotest.matchers.ints.shouldBeLessThan30import io.kotest.matchers.ints.shouldBeLessThanOrEqual31import io.kotest.matchers.ints.shouldBeZero32import io.kotest.matchers.maps.shouldBeEmpty33import io.kotest.matchers.maps.shouldContain34import io.kotest.matchers.maps.shouldContainKey35import io.kotest.matchers.maps.shouldContainValue36import io.kotest.matchers.nulls.shouldBeNull37import io.kotest.matchers.should38import io.kotest.matchers.shouldBe39import io.kotest.matchers.shouldNot40import io.kotest.matchers.string.shouldBeBlank41import io.kotest.matchers.string.shouldBeEmpty42import io.kotest.matchers.string.shouldBeUpperCase43import io.kotest.matchers.string.shouldContain44import io.kotest.matchers.string.shouldNotBeBlank45import java.time.LocalDate46import org.junit.jupiter.api.Test47/**48 * Kotest assertions49 *50 * - [Kotest Assertions Documentation](https://kotest.io/assertions/)51 * - [Github](https://github.com/kotest/kotest/)52 */53class KotestAsserts {54 @Test55 fun `General assertions`() {56 "text" shouldBe "text"57 " ".shouldBeBlank()58 "hi".shouldNotBeBlank()59 "".shouldBeEmpty()60 "HI".shouldBeUpperCase()61 "hello".shouldContain("ll")62 true.shouldBeTrue()63 false.shouldBeFalse()64 null.shouldBeNull()65 10 shouldBeLessThan 1166 10 shouldBeLessThanOrEqual 1067 11 shouldBeGreaterThan 1068 11 shouldBeGreaterThanOrEqual 1169 10.shouldBeEven()70 0.shouldBeZero()71 }72 @Test73 fun `Exception assertions`() {74 shouldThrowExactly<IllegalStateException> {75 angryFunction()76 }77 shouldThrowAny {78 angryFunction()79 }80 }81 @Test82 fun `Collection assertions`() {83 emptyList<Int>().shouldBeEmpty()84 listOf(1, 2, 3) shouldContain 385 listOf(1, 2, 3).shouldBeSorted()86 listOf(1, 2, 3) shouldBeSameSizeAs listOf(4, 5, 6)87 1 shouldBeOneOf listOf(1, 2, 3)88 emptyMap<Int, String>().shouldBeEmpty()89 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContainKey 190 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContainValue "two"91 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContain (3 to "three")92 }93 @Test94 fun `Arrow assertions`() {95 val optionNone = none<String>()96 val optionSome = Some("I am something").toOption()97 optionNone.shouldBeNone()98 optionSome.shouldBeSome()99 val rightEither = Either.Right(1)100 val leftEither = Either.Left("ERROR!!")101 rightEither.shouldBeRight()102 rightEither shouldBeRight 1103 leftEither.shouldBeLeft()104 leftEither shouldBeLeft "ERROR!!"105 val nonEmptyList = NonEmptyList.of(1, 2, 3, 4, 5, null)106 nonEmptyList shouldContain 1107 nonEmptyList.shouldContainNull()108 val valid = Validated.valid()109 val invalid = Validated.invalid()110 valid.shouldBeValid()111 invalid.shouldBeInvalid()112 }113 @Test114 fun `Json assertions`() {115 val jsonString = "{\"test\": \"property\", \"isTest\": true }"116 jsonString shouldMatchJson jsonString117 jsonString shouldContainJsonKey "$.test"118 jsonString shouldNotContainJsonKey "$.notTest"119 jsonString.shouldContainJsonKeyValue("$.isTest", true)120 }121 @Test122 fun `Custom assertions`() {123 val sentMail = Mail(124 dateCreated = LocalDate.of(2020, 10, 27),125 sent = true, message = "May you have an amazing day"126 )127 val unsentMail = Mail(128 dateCreated = LocalDate.of(2020, 10, 27),129 sent = false, message = "May you have an amazing day"130 )131 // This is possible132 sentMail.sent should beSent()133 unsentMail.sent shouldNot beSent()134 // This is recommended135 sentMail.shouldBeSent()136 unsentMail.shouldNotBeSent()137 }138 @Test139 fun `withClue usage`() {140 val mail = Mail(141 dateCreated = LocalDate.of(2020, 10, 27),142 sent = false, message = "May you have an amazing day"143 )144 withClue("sent field should be false") {145 mail.sent shouldBe false146 }147 mail.asClue {148 it.dateCreated shouldBeAfter LocalDate.of(2020, 10, 26)149 it.sent shouldBe false150 }151 }152 @Test153 fun `asClue usage`() {154 val mail = Mail(155 dateCreated = LocalDate.of(2020, 10, 27),156 sent = false, message = "May you have an amazing day"157 )158 mail.asClue {159 it.dateCreated shouldBeAfter LocalDate.of(2020, 10, 26)160 it.sent shouldBe false161 }162 }163 fun beSent() = object : Matcher<Boolean> {164 override fun test(value: Boolean) = MatcherResult(value, "Mail.sent should be true", "Mail.sent should be false")165 }166 fun Mail.shouldBeSent() = this.sent should beSent()167 fun Mail.shouldNotBeSent() = this.sent shouldNot beSent()168}169data class Mail(val dateCreated: LocalDate, val sent: Boolean, val message: String)170fun angryFunction() {171 throw IllegalStateException("How dare you!")172}...

Full Screen

Full Screen

KotlinTest.kt

Source:KotlinTest.kt Github

copy

Full Screen

1package com.example.sampletestcode2import io.kotest.core.spec.style.*3import io.kotest.matchers.collections.sorted4import io.kotest.matchers.should5import io.kotest.matchers.shouldBe6import io.kotest.matchers.string.*7import io.kotest.matchers.collections.beEmpty8import io.kotest.matchers.maps.contain9import io.kotest.matchers.maps.haveKey10import io.kotest.matchers.maps.haveValue11class StringSpecTest : StringSpec() {12 // StringSpec를 상속 받으며, 보통 init 블럭 내에서 테스트 코드를 작성한다.13 // init 블록 내부의 문자열은 테스트를 설명하는 부분이며, 블럭 내부의 코드가 실제 테스트가 진행되는 부분이다.14 init {15 "문자열.length가 문자열의 길이를 리턴해야 합니다." {16 "kotlin test".length shouldBe 1117 }18 }19}20class FunSpecTest : FunSpec({21 // FunSpec는 함수 형태로 테스트 코드를 작성할 수 있도록 돕는다.22 // 테스트 함수의 매개 변수는 단순 테스트 설명이며, 테스트 함수 내부의 코드가 실제 테스트가 진행되는 부분이다.23 test("문자열의 길이를 리턴해야 합니다.") {24 "kotlin".length shouldBe 625 "".length shouldBe 026 }27})28class ShouldSpecTest : ShouldSpec({29 // ShouldSpec는 FunSpec과 유사하다. 다만, test 대신 should 키워드를 사용한다는 차이점이 있다.30 // 아래 should 의 매개 변수는 단순 설명이고, 테스트는 역시 블럭 내부에서 동작한다.31 should("문자열의 길이를 리턴해야 합니다.") {32 "kotlin".length shouldBe 633 "".length shouldBe 034 }35})36class WordSpecTest : WordSpec({37 // String.length 부분은 context string이다. 어떠한 환경에서 테스트를 진행할 것인지를 말해 주는 것이다.38 // 아래 한글은 역시 설명 부분이며, 코드 블럭 내부에서 실제 테스트가 동작한다.39 "String.length" should {40 "문자열의 길이를 리턴해야 합니다." {41 "kotlin".length shouldBe 642 "".length shouldBe 043 }44 }45})46class BehaviorSpecTest : BehaviorSpec({47 // BehaviorSpec는 BDD (Behaviour Driven Development)48 given("젓가락") {49 `when`("잡는다.") {50 then("음식을 먹는다.") {51 println("젓가락을 잡고, 음식을 먹는다.")52 }53 }54 `when`("던진다.") {55 then("사람이 맞는다.") {56 println("젓가락을 던지면, 사람이 맞는다.")57 }58 }59 }60})61class AnnotationSpecTest : AnnotationSpec() {62 // AnnotationSpec는 JUnit 스타일(PersonTest 파일 참고)로 테스트 코드를 작성할 수 있다.63 @BeforeEach64 fun beforeTest() {65 println("Before Test, Setting")66 }67 @Test68 fun test1() {69 "test".length shouldBe 470 }71 @Test72 fun test2() {73 "test2".length shouldBe 574 }75}76class MatcherTest : StringSpec() {77 init {78 // shouldBe는 동일함을 체크하는 Matcher 이다.79 "hello World" shouldBe haveLength(11) // length가 매개변수에 전달된 값이어야 함을 체크한다.80 "hello" should include("ll") // 매개변수 값이 포함되어 있는지 확인한다.81 "hello" should endWith("lo") // 매개변수의 끝이 포함되는지 확인한다.82 "hello" should match("he...") // 매개변수가 매칭되는지 체크한다.83 "hello".shouldBeLowerCase() // 소문자로 작성된 것이 맞는지 체크한다.84 val list = emptyList<String>()85 val list2 = listOf("aaa", "bbb", "ccc")86 val map = mapOf<String, String>(Pair("aa", "11"))87 list should beEmpty() // 원소가 비었는지 확인한다.88 list2 shouldBe sorted<String>() // 해당 자료형이 정렬되어 있는지 확인한다.89 map should contain("aa", "11") // 해당 원소가 포함되어 있는지 확인한다.90 map should haveKey("aa") // 해당 키 값이 포함되어 있는지 확인한다.91 map should haveValue("11") // 해당 value 값이 포함되어 있는지 확인한다.92 }93}...

Full Screen

Full Screen

Nel.kt

Source:Nel.kt Github

copy

Full Screen

1package io.kotest.assertions.arrow.core2import arrow.core.NonEmptyList3import io.kotest.matchers.collections.shouldBeSorted4import io.kotest.matchers.collections.shouldNotBeSorted5import io.kotest.matchers.collections.shouldBeUnique6import io.kotest.matchers.collections.shouldContain7import io.kotest.matchers.collections.shouldContainAll8import io.kotest.matchers.collections.shouldContainDuplicates9import io.kotest.matchers.collections.shouldContainNoNulls10import io.kotest.matchers.collections.shouldContainNull11import io.kotest.matchers.collections.shouldContainOnlyNulls12import io.kotest.matchers.collections.shouldHaveElementAt13import io.kotest.matchers.collections.shouldHaveSingleElement14import io.kotest.matchers.collections.shouldHaveSize15import io.kotest.matchers.collections.shouldNotHaveSize16import io.kotest.matchers.collections.shouldNotBeUnique17import io.kotest.matchers.collections.shouldNotContain18import io.kotest.matchers.collections.shouldNotContainAll19import io.kotest.matchers.collections.shouldNotContainDuplicates20import io.kotest.matchers.collections.shouldNotContainNoNulls21import io.kotest.matchers.collections.shouldNotContainNull22import io.kotest.matchers.collections.shouldNotContainOnlyNulls23import io.kotest.matchers.collections.shouldNotHaveElementAt24import io.kotest.matchers.collections.shouldNotHaveSingleElement25public fun <A> NonEmptyList<A>.shouldContainOnlyNulls(): NonEmptyList<A> =26 apply { all.shouldContainOnlyNulls() }27public fun <A> NonEmptyList<A>.shouldNotContainOnlyNulls(): NonEmptyList<A> =28 apply { all.shouldNotContainOnlyNulls() }29public fun <A> NonEmptyList<A>.shouldContainNull(): NonEmptyList<A> =30 apply { all.shouldContainNull() }31public fun <A> NonEmptyList<A>.shouldNotContainNull(): NonEmptyList<A> =32 apply { all.shouldNotContainNull() }33public fun <A> NonEmptyList<A>.shouldHaveElementAt(index: Int, element: A): Unit =34 all.shouldHaveElementAt(index, element)35public fun <A> NonEmptyList<A>.shouldNotHaveElementAt(index: Int, element: A): Unit =36 all.shouldNotHaveElementAt(index, element)37public fun <A> NonEmptyList<A>.shouldContainNoNulls(): NonEmptyList<A> =38 apply { all.shouldContainNoNulls() }39public fun <A> NonEmptyList<A>.shouldNotContainNoNulls(): NonEmptyList<A> =40 apply { all.shouldNotContainNoNulls() }41public infix fun <A> NonEmptyList<A>.shouldContain(a: A): Unit {42 all.shouldContain(a)43}44public infix fun <A> NonEmptyList<A>.shouldNotContain(a: A): Unit {45 all.shouldNotContain(a)46}47public fun <A> NonEmptyList<A>.shouldBeUnique(): NonEmptyList<A> =48 apply { all.shouldBeUnique() }49public fun <A> NonEmptyList<A>.shouldNotBeUnique(): NonEmptyList<A> =50 apply { all.shouldNotBeUnique() }51public fun <A> NonEmptyList<A>.shouldContainDuplicates(): NonEmptyList<A> =52 apply { all.shouldContainDuplicates() }53public fun <A> NonEmptyList<A>.shouldNotContainDuplicates(): NonEmptyList<A> =54 apply { all.shouldNotContainDuplicates() }55public fun <A> NonEmptyList<A>.shouldContainAll(vararg ts: A): Unit =56 all.shouldContainAll(*ts)57public fun <A> NonEmptyList<A>.shouldNotContainAll(vararg ts: A): Unit =58 all.shouldNotContainAll(*ts)59public infix fun <A> NonEmptyList<A>.shouldContainAll(ts: List<A>): Unit =60 all.shouldContainAll(ts)61public infix fun <A> NonEmptyList<A>.shouldNotContainAll(ts: List<A>): Unit =62 all.shouldNotContainAll(ts)63public infix fun <A> NonEmptyList<A>.shouldHaveSize(size: Int): NonEmptyList<A> =64 apply { all.shouldHaveSize(size) }65public infix fun <A> NonEmptyList<A>.shouldNotHaveSize(size: Int): NonEmptyList<A> =66 apply { all.shouldNotHaveSize(size) }67public infix fun <A> NonEmptyList<A>.shouldHaveSingleElement(a: A): Unit =68 all.shouldHaveSingleElement(a)69public infix fun <A> NonEmptyList<A>.shouldNotHaveSingleElement(a: A): Unit =70 all.shouldNotHaveSingleElement(a)71public fun <A : Comparable<A>> NonEmptyList<A>.shouldBeSorted(): NonEmptyList<A> =72 apply { all.shouldBeSorted() }73public fun <A : Comparable<A>> NonEmptyList<A>.shouldNotBeSorted(): NonEmptyList<A> =74 apply { all.shouldNotBeSorted() }...

Full Screen

Full Screen

04_PropertyBasedStrategies.kt

Source:04_PropertyBasedStrategies.kt Github

copy

Full Screen

...12class PropertyBasedStrategies : ShouldSpec({13 context("different paths, same destination") {14 xshould("negate and sort list") {15 checkAll(Arb.list(Arb.int(-10_000, 10_000))) { a ->16 a.map(Int::unaryMinus).sorted() shouldBe a.sorted().map(Int::unaryMinus).reversed()17 }18 }19 xshould("append then reverse is same like reverse then prepend") {20 checkAll(Arb.int(), Arb.list(Arb.int(-10_000, 10_000))) { additionalItem, list ->21 val appendThenReverse = list.appended(additionalItem).asReversed()22 val reversedThenPrepended = list.asReversed().prepended(additionalItem)23 appendThenReverse shouldBe reversedThenPrepended24 }25 }26 }27 context("there and back again") {28 xshould("insert - contains") {29 checkAll<Int, String> { a, b ->30 val myMap = mapOf(a to b)31 myMap shouldContain (a to b)32 }33 }34 xshould("serialization - deserialization") {35 checkAll(Arb.person()) { person ->36 JsonSerializer.fromString(JsonSerializer.toString(person)) shouldBe person37 }38 }39 }40 context("some things never change") {41 xshould("size of sorted list") {42 checkAll<List<Int>> { a ->43 a.sorted() shouldHaveSize a.size44 }45 }46 xshould("contain exactly same elements") {47 checkAll<List<Int>> { a ->48 a.sorted() shouldContainExactlyInAnyOrder a49 }50 }51 }52 context("The more things change, the more they stay the same") {53 xshould("filtering twice is same as filtering once") {54 checkAll<List<Int>> { a ->55 a.filter(::isEven).filter(::isEven) shouldContainExactlyInAnyOrder a.filter(::isEven)56 }57 }58 xshould("trim a string multiple times is same as trim it once") {59 checkAll<String> { a ->60 a.trim().trim().trim() shouldBe a.trim()61 }62 }...

Full Screen

Full Screen

MatcherTest.kt

Source:MatcherTest.kt Github

copy

Full Screen

1package com.psg.kotest_example2import io.kotest.core.spec.style.StringSpec3import io.kotest.matchers.collections.sorted4import io.kotest.matchers.maps.contain5import io.kotest.matchers.maps.haveKey6import io.kotest.matchers.maps.haveValue7import io.kotest.matchers.should8import io.kotest.matchers.shouldBe9import io.kotest.matchers.string.*10class MatcherTest : StringSpec() {11 init {12 // 'shouldBe' 동일함을 체크하는 Matcher 입니다.13 "hello world" shouldBe haveLength(11) // length가 11이어야 함을 체크 합니다.14 "hello" should include("ll") // 파라미터가 포함되어 있는지 체크 합니다.15 "hello" should endWith("lo") // 파라미터가 끝의 포함되는지 체크 합니다.16 "hello" should match("he...") // 파라미터가 매칭되는지 체크 합니다.17 "hello".shouldBeLowerCase() // 소문자로 작성되었는지 체크 합니다.18 val list = emptyList<String>()19 val list2 = listOf("aaa", "bbb", "ccc")20 val map = mapOf<String, String>(Pair("aa", "11"))21 list should beEmpty() // 원소가 비었는지 체크 합니다.22 list2 shouldBe sorted<String>() // 해당 자료형이 정렬 되었는지 체크 합니다.23 map should contain("aa", "11") // 해당 원소가 포함되었는지 체크 합니다.24 map should haveKey("aa") // 해당 key가 포함되었는지 체크 합니다.25 map should haveValue("11") // 해당 value가 포함되었는지 체크 합니다.26 }27}...

Full Screen

Full Screen

ExampleUnitTest.kt

Source:ExampleUnitTest.kt Github

copy

Full Screen

1package pl.gdg.myapplication2import io.kotest.matchers.collections.shouldBeSortedWith3import io.kotest.matchers.collections.shouldNotContain4import io.kotest.matchers.ints.shouldBeExactly5import org.junit.Assert.assertEquals6import org.junit.Test7/**8 * Example local unit test, which will execute on the development machine (host).9 *10 * See [testing documentation](http://d.android.com/tools/testing).11 */12class ExampleUnitTest {13 @Test14 fun addition_isCorrect() {15 assertEquals(4, 2 + 2)16 }17 @Test18 fun `addition is correct`() {19 2 + 2 shouldBeExactly 420 }21 @Test22 fun `list contains odd numbers`() {23 listOf(1, 3, 5) shouldNotContain 724 listOf(1, 3, 5) shouldBeSortedWith Int::compareTo25 }26}...

Full Screen

Full Screen

sorted

Using AI Code Generation

copy

Full Screen

1val expected = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)2val actual = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).shuffled()3actual should sorted()4val expected = listOf(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)5val actual = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).shuffled()6actual should sorted(reverseOrder())7val expected = listOf("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")8val actual = listOf("a", "b", "c", "d", "e", "f", "g", "h", "i", "j").shuffled()9actual should sorted()10val expected = listOf("j", "i", "h", "g", "f", "e", "d", "c", "b", "a")11val actual = listOf("a", "b", "c", "d", "e", "f", "g", "h", "i", "j").shuffled()12actual should sorted(reverseOrder())13val expected = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)14val actual = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).shuffled()15actual should sortedWith(compareBy { it })16val expected = listOf(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)

Full Screen

Full Screen

sorted

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.collections.*2val list = listOf(1, 2, 3, 4, 5)3list shouldContainAll listOf(1, 2, 3)4list shouldContainInOrder listOf(1, 2, 3)5list shouldContainExactlyInOrder listOf(1, 2, 3)6list shouldContainAllInOrder listOf(1, 2, 3)7list shouldContainExactlyAllInOrder listOf(1, 2, 3)8list shouldContainNone listOf(6, 7, 8)9list shouldContainExactly listOf(1, 2, 3, 4, 5)10list shouldContainSame listOf(5, 4, 3, 2, 1)11list shouldContainExactlyInAnyOrder listOf(5, 4, 3, 2, 1)12list shouldContainSameInAnyOrder listOf(5, 4, 3, 2, 1)13list shouldContainExactlyInAnyOrder listOf(5, 4, 3, 2, 1)14list shouldContainSameInAnyOrder listOf(5, 4, 3, 2, 1)15list shouldContainExactlyInAnyOrder listOf(5, 4, 3, 2, 1)16list shouldContainSameInAnyOrder listOf(5, 4, 3, 2, 1)17list shouldContainExactlyInAnyOrder listOf(5, 4, 3, 2, 1)18list shouldContainSameInAnyOrder listOf(5, 4, 3, 2, 1)19list shouldContainExactlyInAnyOrder listOf(5, 4, 3, 2, 1)20list shouldContainSameInAnyOrder listOf(5, 4, 3, 2, 1)21list shouldContainExactlyInAnyOrder listOf(5, 4, 3, 2, 1)22list shouldContainSameInAnyOrder listOf(5, 4, 3, 2, 1)23list shouldContainExactlyInAnyOrder listOf(5, 4, 3, 2, 1)24list shouldContainSameInAnyOrder listOf(5, 4, 3, 2, 1)25list shouldContainExactlyInAnyOrder listOf(5

Full Screen

Full Screen

sorted

Using AI Code Generation

copy

Full Screen

1val list = listOf(1, 2, 3, 4, 5, 6)2list should beSorted()3list should beSorted(reverseOrder())4list should beSortedBy { it % 3 }5list should beSortedBy(reverseOrder()) { it % 3 }6list should beSortedBy { it % 3 }.using(reverseOrder())7list should beSortedBy(reverseOrder()) { it % 3 }.using(reverseOrder())8list should beSortedBy { it % 3 }.using(reverseOrder())9list should beSortedBy(reverseOrder()) { it % 3 }.using(reverseOrder())10list should beSortedBy { it % 3 }11list should beSortedBy(reverseOrder()) { it % 3 }12list should beSortedBy { it % 3 }.using(reverseOrder())13list should beSortedBy(reverseOrder()) { it % 3 }.using(reverseOrder())14list should beSortedBy { it % 3 }15list should beSortedBy(reverseOrder()) { it % 3 }16list should beSortedBy { it % 3 }.using(reverseOrder())17list should beSortedBy(reverseOrder()) { it % 3 }.using(reverseOrder())18list should beSortedBy { it % 3 }19list should beSortedBy(reverseOrder()) { it % 3 }20list should beSortedBy { it % 3 }.using(reverseOrder())21list should beSortedBy(reverseOrder()) { it % 3 }.using(reverseOrder())22list should beSortedBy { it % 3 }23list should beSortedBy(reverseOrder()) { it % 3 }24list should beSortedBy { it % 3 }.using(reverseOrder())25list should beSortedBy(reverseOrder()) { it % 3 }.using(reverseOrder())26list should beSortedBy { it % 3 }27list should beSortedBy(reverseOrder()) { it % 3 }28list should beSortedBy { it % 3 }.using(reverseOrder())29list should beSortedBy(reverseOrder()) { it % 3 }.using(reverseOrder())30list should beSortedBy { it % 3 }31list should beSortedBy(reverseOrder()) { it % 3 }32list should beSortedBy { it % 3 }.using(reverseOrder())33list should beSortedBy(reverseOrder()) { it % 3 }.using(reverseOrder())34list should beSortedBy { it % 3 }35list should beSortedBy(reverseOrder()) { it % 3 }

Full Screen

Full Screen

sorted

Using AI Code Generation

copy

Full Screen

1+data class Person(val name: String, val age: Int)2+fun main() {3+ val people = listOf(Person("Alice", 29), Person("Bob", 31))4+ people should sorted(Person::age)5+ people should sorted(Person::age, reverseOrder())6+ people should sorted(Person::name)7+}8+data class Person(val name: String, val age: Int)9+fun main() {10+ val people = listOf(Person("Alice", 29), Person("Bob", 31))11+ people should sorted(Person::age)12+ people should sorted(Person::age, reverseOrder())13+ people should sorted(Person::name)14+}15+data class Person(val name: String, val age: Int)16+fun main() {17+ val people = listOf(Person("Alice", 29), Person("Bob", 31))18+ people should sorted(Person::age)19+ people should sorted(Person::age, reverseOrder())20+ people should sorted(Person::name)21+}22+data class Person(val name: String, val age: Int)23+fun main() {24+ val people = listOf(Person("Alice",

Full Screen

Full Screen

sorted

Using AI Code Generation

copy

Full Screen

1 test("sorting") {2 val list = listOf(3, 2, 1)3 list should beSorted()4 }5 test("sorting") {6 val list = listOf(3, 2, 1)7 list should beSorted()8 }9 test("sorting") {10 val list = listOf(3, 2, 1)11 list should beSorted()12 }13 test("sorting") {14 val list = listOf(3, 2, 1)15 list should beSorted()16 }17 test("sorting") {18 val list = listOf(3, 2, 1)19 list should beSorted()20 }21 test("sorting") {22 val list = listOf(3, 2, 1)23 list should beSorted()24 }25 test("sorting") {26 val list = listOf(3, 2, 1)27 list should beSorted()28 }29 test("sorting") {30 val list = listOf(3, 2, 1)31 list should beSorted()32 }33 test("sorting") {34 val list = listOf(3, 2, 1)35 list should beSorted()36 }37 test("sorting") {38 val list = listOf(3, 2, 1)39 list should beSorted()40 }41 test("sorting") {42 val list = listOf(3, 2, 1)43 list should beSorted()44 }

Full Screen

Full Screen

sorted

Using AI Code Generation

copy

Full Screen

1val list = listOf(1, 2, 3, 4, 5)2list.shouldBeSorted()3list.shouldBeSorted(reverseOrder())4list.shouldBeSortedDescending()5val collection = listOf(1, 2, 3, 4, 5)6collection.shouldBeSorted()7collection.shouldBeSorted(reverseOrder())8collection.shouldBeSortedDescending()9val array = arrayOf(1, 2, 3, 4, 5)10array.shouldBeSorted()11array.shouldBeSorted(reverseOrder())12array.shouldBeSortedDescending()13val sequence = listOf(1, 2, 3, 4, 5).asSequence()14sequence.shouldBeSorted()15sequence.shouldBeSorted(reverseOrder())16sequence.shouldBeSortedDescending()17val map = mapOf(1 to "one", 2 to "two", 3 to "three")18map.shouldBeSorted()19map.shouldBeSortedBy { it.key }20map.shouldBeSortedBy { it.value }21map.shouldBeSortedBy { it.value.length }22map.shouldBeSortedBy { it.value.length }.reversed()23map.shouldBeSortedBy { it.value.length }.withReverseOrder()24map.shouldBeSortedBy { it.value.length }.withReverseOrder().reversed()25map.shouldBeSortedBy { it.value.length }.withReverseOrder().reversed().reversed()26map.shouldBeSortedBy { it.value.length }.withReverseOrder().reversed().reversed().withReverseOrder()27map.shouldBeSortedBy { it.value.length }.withReverseOrder().reversed().reversed().withReverseOrder().reversed()28val map = mapOf(1 to "one", 2 to "two", 3 to "three")29map.shouldBeSorted()30map.shouldBeSortedBy { it.key }

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.

Most used methods in sorted

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful