How to use Array.forExactly method of io.kotest.inspectors.Inspectors class

Best Kotest code snippet using io.kotest.inspectors.Inspectors.Array.forExactly

CollectionInspectorsTest.kt

Source:CollectionInspectorsTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.inspectors2import io.kotest.assertions.assertSoftly3import io.kotest.assertions.shouldFail4import io.kotest.assertions.throwables.shouldThrow5import io.kotest.assertions.throwables.shouldThrowAny6import io.kotest.core.spec.style.WordSpec7import io.kotest.inspectors.forAll8import io.kotest.inspectors.forAny9import io.kotest.inspectors.forAtLeastOne10import io.kotest.inspectors.forAtMostOne11import io.kotest.inspectors.forExactly12import io.kotest.inspectors.forNone13import io.kotest.inspectors.forOne14import io.kotest.inspectors.forSingle15import io.kotest.inspectors.forSome16import io.kotest.matchers.comparables.beGreaterThan17import io.kotest.matchers.comparables.beLessThan18import io.kotest.matchers.ints.shouldBeGreaterThan19import io.kotest.matchers.ints.shouldBeLessThan20import io.kotest.matchers.should21import io.kotest.matchers.shouldBe22@Suppress("ConstantConditionIf")23class CollectionInspectorsTest : WordSpec() {24 private val list = listOf(1, 2, 3, 4, 5)25 private val array = arrayOf(1, 2, 3, 4, 5)26 data class DummyEntry(27 val id: Int,28 val name: String,29 )30 init {31 "forAll" should {32 "pass if all elements of an array pass" {33 array.forAll {34 it.shouldBeGreaterThan(0)35 }36 }37 "pass if all elements of a collection pass" {38 list.forAll {39 it.shouldBeGreaterThan(0)40 }41 }42 "return itself" {43 array.forAll {44 it.shouldBeGreaterThan(0)45 }.forAll {46 it.shouldBeGreaterThan(0)47 }48 list.forAll {49 it.shouldBeGreaterThan(0)50 }.forAll {51 it.shouldBeGreaterThan(0)52 }53 }54 "fail when an exception is thrown inside an array" {55 shouldThrowAny {56 array.forAll {57 if (true) throw NullPointerException()58 }59 }.message shouldBe "0 elements passed but expected 5\n" +60 "\n" +61 "The following elements passed:\n" +62 "--none--\n" +63 "\n" +64 "The following elements failed:\n" +65 "1 => java.lang.NullPointerException\n" +66 "2 => java.lang.NullPointerException\n" +67 "3 => java.lang.NullPointerException\n" +68 "4 => java.lang.NullPointerException\n" +69 "5 => java.lang.NullPointerException"70 }71 "fail when an exception is thrown inside a list" {72 shouldThrowAny {73 list.forAll {74 if (true) throw NullPointerException()75 }76 }.message shouldBe "0 elements passed but expected 5\n" +77 "\n" +78 "The following elements passed:\n" +79 "--none--\n" +80 "\n" +81 "The following elements failed:\n" +82 "1 => java.lang.NullPointerException\n" +83 "2 => java.lang.NullPointerException\n" +84 "3 => java.lang.NullPointerException\n" +85 "4 => java.lang.NullPointerException\n" +86 "5 => java.lang.NullPointerException"87 }88 }89 "forNone" should {90 "pass if no elements pass fn test for a list" {91 list.forNone {92 it shouldBe 1093 }94 }95 "pass if no elements pass fn test for an array" {96 array.forNone {97 it shouldBe 1098 }99 }100 "pass if an element throws an exception" {101 val items = listOf(1, 2, 3)102 items.forNone {103 if (true) throw NullPointerException()104 }105 }106 "return itself" {107 list.forNone {108 it shouldBe 10109 }.forNone {110 it shouldBe 10111 }112 array.forNone {113 it shouldBe 10114 }.forNone {115 it shouldBe 10116 }117 }118 "fail if one elements passes fn test" {119 shouldThrow<AssertionError> {120 list.forNone {121 it shouldBe 4122 }123 }.message shouldBe """1 elements passed but expected 0124The following elements passed:1254126The following elements failed:1271 => expected:<4> but was:<1>1282 => expected:<4> but was:<2>1293 => expected:<4> but was:<3>1305 => expected:<4> but was:<5>"""131 }132 "fail if all elements pass fn test" {133 shouldThrow<AssertionError> {134 list.forNone {135 it should beGreaterThan(0)136 }137 }.message shouldBe """5 elements passed but expected 0138The following elements passed:13911402141314241435144The following elements failed:145--none--"""146 }147 "work inside assertSoftly block" {148 val dummyEntries = listOf(149 DummyEntry(id = 1, name = "first"),150 DummyEntry(id = 2, name = "second"),151 )152 assertSoftly(dummyEntries) {153 forNone {154 it.id shouldBe 3155 it.name shouldBe "third"156 }157 }158 }159 }160 "forSome" should {161 "pass if one elements pass test" {162 list.forSome {163 it shouldBe 3164 }165 }166 "pass if size-1 elements pass test" {167 list.forSome {168 it should beGreaterThan(1)169 }170 }171 "return itself" {172 list.forSome {173 it shouldBe 3174 }.forSome {175 it shouldBe 3176 }177 array.forSome {178 it shouldBe 3179 }.forSome {180 it shouldBe 3181 }182 }183 "fail if no elements pass test" {184 shouldThrow<AssertionError> {185 array.forSome {186 it should beLessThan(0)187 }188 }.message shouldBe """No elements passed but expected at least one189The following elements passed:190--none--191The following elements failed:1921 => 1 should be < 01932 => 2 should be < 01943 => 3 should be < 01954 => 4 should be < 01965 => 5 should be < 0"""197 }198 "fail if all elements pass test" {199 shouldThrow<AssertionError> {200 list.forSome {201 it should beGreaterThan(0)202 }203 }.message shouldBe """All elements passed but expected < 5204The following elements passed:20512062207320842095210The following elements failed:211--none--"""212 }213 "work inside assertSoftly block" {214 val dummyEntries = listOf(215 DummyEntry(id = 1, name = "first"),216 DummyEntry(id = 1, name = "first"),217 DummyEntry(id = 2, name = "second"),218 )219 assertSoftly(dummyEntries) {220 forSome {221 it.id shouldBe 1222 it.name shouldBe "first"223 }224 }225 }226 }227 "forOne" should {228 "pass if one elements pass test" {229 list.forOne {230 it shouldBe 3231 }232 }233 "return itself" {234 list.forOne {235 it shouldBe 3236 }.forOne {237 it shouldBe 3238 }239 array.forOne {240 it shouldBe 3241 }.forOne {242 it shouldBe 3243 }244 }245 "fail if > 1 elements pass test" {246 shouldThrow<AssertionError> {247 list.forOne {248 it should beGreaterThan(2)249 }250 }.message shouldBe """3 elements passed but expected 1251The following elements passed:252325342545255The following elements failed:2561 => 1 should be > 22572 => 2 should be > 2"""258 }259 "fail if no elements pass test" {260 shouldThrow<AssertionError> {261 array.forOne {262 it shouldBe 22263 }264 }.message shouldBe """0 elements passed but expected 1265The following elements passed:266--none--267The following elements failed:2681 => expected:<22> but was:<1>2692 => expected:<22> but was:<2>2703 => expected:<22> but was:<3>2714 => expected:<22> but was:<4>2725 => expected:<22> but was:<5>"""273 }274 "work inside assertSoftly block" {275 val dummyEntries = listOf(276 DummyEntry(id = 1, name = "first"),277 DummyEntry(id = 2, name = "second"),278 )279 assertSoftly(dummyEntries) {280 forOne {281 it.id shouldBe 1282 it.name shouldBe "first"283 }284 }285 }286 }287 "forAny" should {288 "pass if one elements pass test" {289 list.forAny {290 it shouldBe 3291 }292 }293 "pass if at least elements pass test" {294 list.forAny {295 it should beGreaterThan(2)296 }297 }298 "return itself" {299 list.forAny {300 it shouldBe 3301 }.forAny {302 it shouldBe 3303 }304 array.forAny {305 it shouldBe 3306 }.forAny {307 it shouldBe 3308 }309 }310 "fail if no elements pass test" {311 shouldThrow<AssertionError> {312 array.forAny {313 it shouldBe 6314 }315 }.message shouldBe """0 elements passed but expected at least 1316The following elements passed:317--none--318The following elements failed:3191 => expected:<6> but was:<1>3202 => expected:<6> but was:<2>3213 => expected:<6> but was:<3>3224 => expected:<6> but was:<4>3235 => expected:<6> but was:<5>"""324 }325 "work inside assertSoftly block" {326 val dummyEntries = listOf(327 DummyEntry(id = 1, name = "first"),328 DummyEntry(id = 2, name = "second"),329 )330 assertSoftly(dummyEntries) {331 forAny {332 it.id shouldBe 1333 it.name shouldBe "first"334 }335 }336 }337 }338 "forExactly" should {339 "pass if exactly k elements pass" {340 list.forExactly(2) {341 it should beLessThan(3)342 }343 }344 "fail if more elements pass test" {345 shouldThrow<AssertionError> {346 list.forExactly(2) {347 it should beGreaterThan(2)348 }349 }.message shouldBe """3 elements passed but expected 2350The following elements passed:351335243535354The following elements failed:3551 => 1 should be > 23562 => 2 should be > 2"""357 }358 "fail if less elements pass test" {359 shouldThrow<AssertionError> {360 array.forExactly(2) {361 it should beLessThan(2)362 }363 }.message shouldBe """1 elements passed but expected 2364The following elements passed:3651366The following elements failed:3672 => 2 should be < 23683 => 3 should be < 23694 => 4 should be < 23705 => 5 should be < 2"""371 }372 "fail if no elements pass test" {373 shouldThrow<AssertionError> {374 array.forExactly(2) {375 it shouldBe 33376 }377 }.message shouldBe """0 elements passed but expected 2378The following elements passed:379--none--380The following elements failed:3811 => expected:<33> but was:<1>3822 => expected:<33> but was:<2>3833 => expected:<33> but was:<3>3844 => expected:<33> but was:<4>3855 => expected:<33> but was:<5>"""386 }387 }388 "forAtMostOne" should {389 "pass if one elements pass test" {390 list.forAtMostOne {391 it shouldBe 3392 }393 }394 "fail if 2 elements pass test" {395 shouldThrow<AssertionError> {396 array.forAtMostOne {397 it should beGreaterThan(3)398 }399 }.message shouldBe """2 elements passed but expected at most 1400The following elements passed:40144025403The following elements failed:4041 => 1 should be > 34052 => 2 should be > 34063 => 3 should be > 3"""407 }408 "work inside assertSoftly block" {409 val dummyEntries = listOf(410 DummyEntry(id = 1, name = "first"),411 DummyEntry(id = 2, name = "second"),412 )413 assertSoftly(dummyEntries) {414 forAtMostOne {415 it.id shouldBe 1416 it.name shouldBe "first"417 }418 }419 }420 }421 "forAtLeastOne" should {422 "pass if one elements pass test" {423 list.forAtLeastOne {424 it shouldBe 3425 }426 }427 "fail if no elements pass test" {428 shouldThrow<AssertionError> {429 array.forAtLeastOne {430 it shouldBe 22431 }432 }.message shouldBe """0 elements passed but expected at least 1433The following elements passed:434--none--435The following elements failed:4361 => expected:<22> but was:<1>4372 => expected:<22> but was:<2>4383 => expected:<22> but was:<3>4394 => expected:<22> but was:<4>4405 => expected:<22> but was:<5>"""441 }442 "work inside assertSoftly block" {443 val dummyEntries = listOf(444 DummyEntry(id = 1, name = "first"),445 DummyEntry(id = 2, name = "second"),446 )447 assertSoftly(dummyEntries) {448 forAtLeastOne {449 it.id shouldBe 1450 it.name shouldBe "first"451 }452 }453 }454 }455 "forSingle" should {456 "pass list is singular, and the single element pass" {457 listOf(1).forSingle {458 it shouldBeLessThan 3459 }460 }461 "return the single element on success" {462 listOf(1).forSingle { it shouldBeLessThan 3 } shouldBe 1463 }464 "fail if collection consists of multiple elements" {465 shouldFail {466 listOf(467 DummyEntry(id = 1, name = "first"),468 DummyEntry(id = 2, name = "second"),469 ).forSingle {470 it.id shouldBe 1471 }472 }.message shouldBe """473 Expected a single element in the collection, but found 2.474 The following elements passed:475 DummyEntry(id=1, name=first)476 The following elements failed:477 DummyEntry(id=2, name=second) => expected:<1> but was:<2>478 """.trimIndent()479 }480 "fail for empty collection" {481 shouldFail {482 arrayOf<Int>().forSingle {483 it shouldBe 3484 }485 }.message shouldBe """486 Expected a single element in the collection, but it was empty.487 """.trimIndent()488 }489 "fail if single element doesn't match" {490 shouldFail {491 arrayOf(2).forSingle {492 it shouldBe 3493 }494 }.message shouldBe """495 Expected a single element to pass, but it failed.496 The following elements passed:497 --none--498 The following elements failed:499 2 => expected:<3> but was:<2>500 """.trimIndent()501 }502 "work inside assertSoftly block" {503 val dummyEntries = listOf(504 DummyEntry(id = 1, name = "first"),505 )506 assertSoftly(dummyEntries) {507 forSingle {508 it.id shouldBe 1509 it.name shouldBe "first"510 }511 }512 }513 }514 }515}...

Full Screen

Full Screen

GooglePlayTest.kt

Source:GooglePlayTest.kt Github

copy

Full Screen

1package io.appvox.googleplay2import io.appvox.core.exception.AppVoxException3import io.appvox.googleplay.app.GooglePlayRepository4import io.appvox.googleplay.review.GooglePlayReviewRepository.Companion.REQUEST_URL_DOMAIN5import io.appvox.googleplay.review.GooglePlayReviewRepository.Companion.REQUEST_URL_PATH6import io.appvox.googleplay.review.constant.GooglePlayLanguage7import io.appvox.googleplay.review.constant.GooglePlaySortType8import io.appvox.googleplay.review.domain.GooglePlayReview9import io.kotest.assertions.assertSoftly10import io.kotest.assertions.throwables.shouldThrowExactly11import io.kotest.inspectors.forExactly12import io.kotest.matchers.ints.shouldBeBetween13import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual14import io.kotest.matchers.nulls.shouldNotBeNull15import io.kotest.matchers.string.shouldContain16import io.kotest.matchers.string.shouldNotBeEmpty17import io.kotest.matchers.string.shouldStartWith18import kotlinx.coroutines.ExperimentalCoroutinesApi19import kotlinx.coroutines.flow.collect20import kotlinx.coroutines.flow.take21import kotlinx.coroutines.test.runBlockingTest22import org.junit.jupiter.params.ParameterizedTest23import org.junit.jupiter.params.provider.CsvSource24import kotlin.contracts.ExperimentalContracts25class GooglePlayTest : BaseGooglePlayMockTest() {26 @ExperimentalContracts27 @ExperimentalCoroutinesApi28 @ParameterizedTest29 @CsvSource(30 "com.twitter.android, 50"31 )32 fun `Get reviews using default parameters`(33 appId: String,34 expectedReviewCount: Int35 ) = runBlockingTest {36 GooglePlayRepository.APP_HP_URL_DOMAIN = httpMockServerDomain37 val scriptParamsMockData = javaClass.getResource(38 "/app/com.twitter.android" +39 "/app_googleplay_com.twitter.android_homepage.html"40 ).readText()41 stubHttpUrl(GooglePlayRepository.APP_HP_URL_PATH, scriptParamsMockData)42 REQUEST_URL_DOMAIN = httpMockServerDomain43 val mockData =44 javaClass.getResource(45 "/review/com.twitter.android/relevant" +46 "/review_google_play_com.twitter.android_relevant_1.json"47 ).readText()48 stubHttpUrl(REQUEST_URL_PATH, mockData)49 val reviews = ArrayList<GooglePlayReview>()50 GooglePlay()51 .reviews { this.appId = appId }52 .take(expectedReviewCount)53 .collect { review ->54 reviews.add(review)55 }56 reviews.forExactly(expectedReviewCount) { result ->57 assertSoftly(result) {58 id shouldStartWith "gp:"59 language.shouldNotBeNull()60 url shouldContain id61 userTypes.shouldNotBeNull()62 latestComment.shouldNotBeNull()63 }64 assertSoftly(result.latestUserComment) {65 name.shouldNotBeEmpty()66 avatar shouldStartWith "https://play-lh.googleusercontent.com/"67 rating.shouldBeBetween(1, 5)68 text.shouldNotBeEmpty()69 lastUpdateTime.shouldNotBeNull()70 likeCount.shouldBeGreaterThanOrEqual(0)71 types.shouldNotBeNull()72 }73 assertSoftly(result.latestDeveloperComment) {74 text?.let { it.shouldNotBeEmpty() }75 }76 }77 }78 @ExperimentalContracts79 @ExperimentalCoroutinesApi80 @ParameterizedTest81 @CsvSource(82 "com.twitter.android, en-US, 1, 50"83 )84 fun `Get most relevant reviews from the US with a delay of 3s between each request`(85 appId: String,86 language: String,87 sortType: Int,88 expectedReviewCount: Int89 ) = runBlockingTest {90 GooglePlayRepository.APP_HP_URL_DOMAIN = httpMockServerDomain91 val scriptParamsMockData = javaClass.getResource(92 "/app/com.twitter.android" +93 "/app_googleplay_com.twitter.android_homepage.html"94 ).readText()95 stubHttpUrl(GooglePlayRepository.APP_HP_URL_PATH, scriptParamsMockData)96 REQUEST_URL_DOMAIN = httpMockServerDomain97 val mockResponse =98 javaClass.getResource(99 "/review/com.twitter.android/relevant" +100 "/review_google_play_com.twitter.android_relevant_1.json"101 ).readText()102 stubHttpUrl(REQUEST_URL_PATH, mockResponse)103 val reviews = ArrayList<GooglePlayReview>()104 val googlePlay = GooglePlay()105 googlePlay106 .reviews {107 this.appId = appId108 this.language = GooglePlayLanguage.fromValue(language)109 this.sortType = GooglePlaySortType.fromValue(sortType)110 }111 .take(expectedReviewCount)112 .collect { review ->113 reviews.add(review)114 }115 reviews.forExactly(expectedReviewCount) { result ->116 assertSoftly(result) {117 id shouldStartWith "gp:"118 language.shouldNotBeNull()119 url shouldContain id120 userTypes.shouldNotBeNull()121 latestComment.shouldNotBeNull()122 }123 assertSoftly(result.latestUserComment) {124 name.shouldNotBeEmpty()125 avatar shouldStartWith "https://play-lh.googleusercontent.com/"126 rating.shouldBeBetween(1, 5)127 text.shouldNotBeEmpty()128 lastUpdateTime.shouldNotBeNull()129 likeCount.shouldBeGreaterThanOrEqual(0)130 types.shouldNotBeNull()131 }132 assertSoftly(result.latestDeveloperComment) {133 text?.let { it.shouldNotBeEmpty() }134 }135 }136 }137 @ExperimentalContracts138 @ExperimentalCoroutinesApi139 @ParameterizedTest140 @CsvSource(141 "com.twitter.android, 50"142 )143 fun `Get reviews using default parameters and get timeout`(144 appId: String,145 expectedReviewCount: Int146 ) = runBlockingTest {147 GooglePlayRepository.APP_HP_URL_DOMAIN = httpMockServerDomain148 val scriptParamsMockData = javaClass.getResource(149 "/app/com.twitter.android" +150 "/app_googleplay_com.twitter.android_homepage.html"151 ).readText()152 stubHttpUrl(GooglePlayRepository.APP_HP_URL_PATH, scriptParamsMockData)153 REQUEST_URL_DOMAIN = httpMockServerDomain154 val mockData =155 javaClass.getResource(156 "/review/com.twitter.android/relevant" +157 "/review_google_play_com.twitter.android_relevant_1.json"158 ).readText()159 stubHttpUrlWithStatus(REQUEST_URL_PATH, mockData, 408)160 shouldThrowExactly<AppVoxException> {161 val reviews = ArrayList<GooglePlayReview>()162 GooglePlay()163 .reviews { this.appId = appId }164 .take(expectedReviewCount)165 .collect { review ->166 reviews.add(review)167 }168 }169 }170 @ExperimentalContracts171 @ExperimentalCoroutinesApi172 @ParameterizedTest173 @CsvSource(174 "com.twitter.android, 50"175 )176 fun `Get reviews using default parameters and get not exist`(177 appId: String,178 expectedReviewCount: Int179 ) = runBlockingTest {180 GooglePlayRepository.APP_HP_URL_DOMAIN = httpMockServerDomain181 val scriptParamsMockData = javaClass.getResource(182 "/app/com.twitter.android" +183 "/app_googleplay_com.twitter.android_homepage.html"184 ).readText()185 stubHttpUrl(GooglePlayRepository.APP_HP_URL_PATH, scriptParamsMockData)186 REQUEST_URL_DOMAIN = httpMockServerDomain187 val mockData =188 javaClass.getResource(189 "/review/com.twitter.android/relevant" +190 "/review_google_play_com.twitter.android_relevant_1.json"191 ).readText()192 stubHttpUrlWithStatus(REQUEST_URL_PATH, mockData, 404)193 shouldThrowExactly<AppVoxException> {194 val reviews = ArrayList<GooglePlayReview>()195 GooglePlay()196 .reviews { this.appId = appId }197 .take(expectedReviewCount)198 .collect { review ->199 reviews.add(review)200 }201 }202 }203}...

Full Screen

Full Screen

InspectorAliasTest.kt

Source:InspectorAliasTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest2import io.kotest.assertions.throwables.shouldThrowAny3import io.kotest.core.spec.style.FunSpec4import io.kotest.inspectors.shouldForAll5import io.kotest.inspectors.shouldForAny6import io.kotest.inspectors.shouldForAtLeast7import io.kotest.inspectors.shouldForAtLeastOne8import io.kotest.inspectors.shouldForAtMost9import io.kotest.inspectors.shouldForAtMostOne10import io.kotest.inspectors.shouldForExactly11import io.kotest.inspectors.shouldForNone12import io.kotest.inspectors.shouldForOne13import io.kotest.inspectors.shouldForSome14import io.kotest.matchers.comparables.shouldBeGreaterThan15import io.kotest.matchers.ints.shouldBeLessThan16import io.kotest.matchers.shouldBe17class InspectorAliasTest : FunSpec({18 val array = arrayOf(1, 2, 3)19 val list = listOf(1, 2, 3)20 val sequence = sequenceOf(1, 2, 3)21 context("forAll") {22 fun block(x: Int) = x shouldBeGreaterThan 023 test("array") {24 array.shouldForAll {25 it shouldBeLessThan 426 }27 shouldThrowAny {28 array.shouldForAll {29 it shouldBeLessThan 330 }31 }32 }33 test("list") {34 list.shouldForAll(::block)35 shouldThrowAny {36 list.shouldForAll {37 it shouldBeLessThan 338 }39 }40 }41 test("sequence") {42 sequence.shouldForAll(::block)43 shouldThrowAny {44 sequence.shouldForAll {45 it shouldBeLessThan 346 }47 }48 }49 }50 context("forOne") {51 fun block(x: Int) = x shouldBe 252 test("array") {53 array.shouldForOne(::block)54 shouldThrowAny {55 array.shouldForOne {56 it shouldBeLessThan 157 }58 }59 }60 test("list") {61 list.shouldForOne(::block)62 shouldThrowAny {63 list.shouldForOne {64 it shouldBeLessThan 165 }66 }67 }68 test("sequence") {69 sequence.shouldForOne(::block)70 shouldThrowAny {71 sequence.shouldForOne {72 it shouldBeLessThan 173 }74 }75 }76 }77 context("forExactly") {78 fun block(x: Int) = x shouldBeGreaterThan 179 val n = 280 test("array") {81 array.shouldForExactly(n, ::block)82 shouldThrowAny {83 array.shouldForExactly(n) {84 it shouldBeLessThan 185 }86 }87 }88 test("list") {89 list.shouldForExactly(n, ::block)90 shouldThrowAny {91 list.shouldForExactly(n) {92 it shouldBeLessThan 193 }94 }95 }96 test("sequence") {97 sequence.shouldForExactly(n, ::block)98 shouldThrowAny {99 sequence.shouldForExactly(n) {100 it shouldBeLessThan 1101 }102 }103 }104 }105 context("forSome") {106 fun block(x: Int) = x shouldBeGreaterThan 2107 test("array") {108 array.shouldForSome(::block)109 shouldThrowAny {110 array.shouldForSome {111 it shouldBeLessThan 1112 }113 }114 }115 test("list") {116 list.shouldForSome(::block)117 shouldThrowAny {118 list.shouldForSome {119 it shouldBeLessThan 1120 }121 }122 }123 test("sequence") {124 sequence.shouldForSome(::block)125 shouldThrowAny {126 sequence.shouldForSome {127 it shouldBeLessThan 1128 }129 }130 }131 }132 context("forAny") {133 fun block(x: Int) = x shouldBeGreaterThan 0134 test("array") {135 array.shouldForAny(::block)136 shouldThrowAny {137 array.shouldForAny {138 it shouldBeLessThan 1139 }140 }141 }142 test("list") {143 list.shouldForAny(::block)144 shouldThrowAny {145 list.shouldForAny {146 it shouldBeLessThan 1147 }148 }149 }150 test("sequence") {151 sequence.shouldForAny(::block)152 shouldThrowAny {153 sequence.shouldForAny {154 it shouldBeLessThan 1155 }156 }157 }158 }159 context("forAtLeast") {160 fun block(x: Int) = x shouldBeGreaterThan 0161 val n = 3162 test("array") {163 array.shouldForAtLeast(n, ::block)164 shouldThrowAny {165 array.shouldForAtLeast(n) {166 it shouldBeLessThan 3167 }168 }169 }170 test("list") {171 list.shouldForAtLeast(n, ::block)172 shouldThrowAny {173 list.shouldForAtLeast(n) {174 it shouldBeLessThan 3175 }176 }177 }178 test("sequence") {179 sequence.shouldForAtLeast(n, ::block)180 shouldThrowAny {181 sequence.shouldForAtLeast(n) {182 it shouldBeLessThan 3183 }184 }185 }186 }187 context("forAtLeastOne") {188 fun block(x: Int) = x shouldBeGreaterThan 0189 test("array") {190 array.shouldForAtLeastOne(::block)191 shouldThrowAny {192 array.shouldForAtLeastOne {193 it shouldBeLessThan 1194 }195 }196 }197 test("list") {198 list.shouldForAtLeastOne(::block)199 shouldThrowAny {200 list.shouldForAtLeastOne {201 it shouldBeLessThan 1202 }203 }204 }205 test("sequence") {206 sequence.shouldForAtLeastOne(::block)207 shouldThrowAny {208 sequence.shouldForAtLeastOne {209 it shouldBeLessThan 1210 }211 }212 }213 }214 context("forAtMost") {215 fun block(x: Int) = x shouldBeGreaterThan 0216 test("array") {217 val arr = arrayOf(0, 0, 1)218 arr.shouldForAtMost(1, ::block)219 shouldThrowAny {220 arr.shouldForAtMost(1) {221 it shouldBeLessThan 3222 }223 }224 }225 test("list") {226 val l = listOf(0, 1, 1)227 l.shouldForAtMost(2, ::block)228 shouldThrowAny {229 l.shouldForAtMost(2) {230 it shouldBeLessThan 3231 }232 }233 }234 test("sequence") {235 sequence.shouldForAtMost(3, ::block)236 shouldThrowAny {237 sequence.shouldForAtMost(2) {238 it shouldBeLessThan 4239 }240 }241 }242 }243 context("forNone") {244 fun block(x: Int) = x shouldBeLessThan 1245 test("array") {246 array.shouldForNone(::block)247 shouldThrowAny {248 array.shouldForNone {249 it shouldBeLessThan 4250 }251 }252 }253 test("list") {254 list.shouldForNone(::block)255 shouldThrowAny {256 list.shouldForNone {257 it shouldBeLessThan 4258 }259 }260 }261 test("sequence") {262 sequence.shouldForNone(::block)263 shouldThrowAny {264 sequence.shouldForNone {265 it shouldBeLessThan 4266 }267 }268 }269 }270 context("forAtMostOne") {271 fun block(x: Int) = x shouldBe 1272 test("array") {273 array.shouldForAtMostOne(::block)274 }275 test("list") {276 list.shouldForAtMostOne(::block)277 }278 test("sequence") {279 sequence.shouldForAtMostOne(::block)280 }281 }282})...

Full Screen

Full Screen

InspectorsTest.kt

Source:InspectorsTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.core.spec.style.WordSpec4import io.kotest.inspectors.forAny5import io.kotest.inspectors.forExactly6import io.kotest.inspectors.forNone7import io.kotest.inspectors.forOne8import io.kotest.inspectors.forSome9import io.kotest.matchers.comparables.beGreaterThan10import io.kotest.matchers.comparables.beLessThan11import io.kotest.matchers.should12import io.kotest.matchers.shouldBe13import io.kotest.matchers.shouldNotBe14class InspectorsTest : WordSpec() {15 private val list = listOf(1, 2, 3, 4, 5)16 private val array = arrayOf(1, 2, 3, 4, 5)17 private val charSequence = "charSequence"18 init {19 "forNone" should {20 "pass if no elements pass fn test for a list" {21 list.forNone {22 it shouldBe 1023 }24 }25 "pass if no elements pass fn test for a char sequence" {26 charSequence.forNone {27 it shouldBe 'x'28 }29 }30 "pass if no elements pass fn test for an array" {31 array.forNone {32 it shouldBe 1033 }34 }35 "fail if one elements passes fn test" {36 shouldThrow<AssertionError> {37 list.forNone {38 it shouldBe 439 }40 }.message shouldBe """1 elements passed but expected 041The following elements passed:42443The following elements failed:441 => expected:<4> but was:<1>452 => expected:<4> but was:<2>463 => expected:<4> but was:<3>475 => expected:<4> but was:<5>"""48 }49 "fail if all elements pass fn test" {50 shouldThrow<AssertionError> {51 list.forNone {52 it should beGreaterThan(0)53 }54 }.message shouldBe """5 elements passed but expected 055The following elements passed:56157258359460561The following elements failed:62--none--"""63 }64 }65 "forSome" should {66 "pass if one elements pass test" {67 list.forSome {68 it shouldBe 369 }70 }71 "pass if size-1 elements pass test" {72 list.forSome {73 it should beGreaterThan(1)74 }75 }76 "pass if two elements pass test for a char sequence" {77 charSequence.forSome {78 it shouldBe 'c'79 }80 }81 "fail if no elements pass test" {82 shouldThrow<AssertionError> {83 array.forSome {84 it should beLessThan(0)85 }86 }.message shouldBe """No elements passed but expected at least one87The following elements passed:88--none--89The following elements failed:901 => 1 should be < 0912 => 2 should be < 0923 => 3 should be < 0934 => 4 should be < 0945 => 5 should be < 0"""95 }96 "fail if all elements pass test" {97 shouldThrow<AssertionError> {98 list.forSome {99 it should beGreaterThan(0)100 }101 }.message shouldBe """All elements passed but expected < 5102The following elements passed:10311042105310641075108The following elements failed:109--none--"""110 }111 }112 "forOne" should {113 "pass if one elements pass test" {114 list.forOne {115 it shouldBe 3116 }117 }118 "fail if all elements pass test for a char sequence" {119 shouldThrow<AssertionError> {120 charSequence.forOne { t ->121 t shouldNotBe 'X'122 }123 }.message shouldBe """12 elements passed but expected 1124The following elements passed:125c126h127a128r129S130e131q132u133e134n135... and 2 more passed elements136The following elements failed:137--none--"""138 }139 "fail if > 1 elements pass test" {140 shouldThrow<AssertionError> {141 list.forOne { t ->142 t should beGreaterThan(2)143 }144 }.message shouldBe """3 elements passed but expected 1145The following elements passed:146314741485149The following elements failed:1501 => 1 should be > 21512 => 2 should be > 2"""152 }153 "fail if no elements pass test" {154 shouldThrow<AssertionError> {155 array.forOne { t ->156 t shouldBe 22157 }158 }.message shouldBe """0 elements passed but expected 1159The following elements passed:160--none--161The following elements failed:1621 => expected:<22> but was:<1>1632 => expected:<22> but was:<2>1643 => expected:<22> but was:<3>1654 => expected:<22> but was:<4>1665 => expected:<22> but was:<5>"""167 }168 }169 "forAny" should {170 "pass if one elements pass test" {171 list.forAny { t ->172 t shouldBe 3173 }174 }175 "pass if at least elements pass test" {176 list.forAny { t ->177 t should beGreaterThan(2)178 }179 }180 "pass if all elements pass test for a char sequence" {181 charSequence.forAny {182 it shouldNotBe 'X'183 }184 }185 "fail if no elements pass test" {186 shouldThrow<AssertionError> {187 array.forAny { t ->188 t shouldBe 6189 }190 }.message shouldBe """0 elements passed but expected at least 1191The following elements passed:192--none--193The following elements failed:1941 => expected:<6> but was:<1>1952 => expected:<6> but was:<2>1963 => expected:<6> but was:<3>1974 => expected:<6> but was:<4>1985 => expected:<6> but was:<5>"""199 }200 }201 "forExactly" should {202 "pass if exactly k elements pass" {203 list.forExactly(2) { t ->204 t should beLessThan(3)205 }206 }207 "pass if exactly k elements pass for a char sequence" {208 charSequence.forExactly(1) {209 it shouldBe 'h'210 }211 }212 "fail if more elements pass test" {213 shouldThrow<AssertionError> {214 list.forExactly(2) { t ->215 t should beGreaterThan(2)216 }217 }.message shouldBe """3 elements passed but expected 2218The following elements passed:219322042215222The following elements failed:2231 => 1 should be > 22242 => 2 should be > 2"""225 }226 "fail if less elements pass test" {227 shouldThrow<AssertionError> {228 array.forExactly(2) { t ->229 t should beLessThan(2)230 }231 }.message shouldBe """1 elements passed but expected 2232The following elements passed:2331234The following elements failed:2352 => 2 should be < 22363 => 3 should be < 22374 => 4 should be < 22385 => 5 should be < 2"""239 }240 "fail if no elements pass test" {241 shouldThrow<AssertionError> {242 list.forExactly(2) { t ->243 t shouldBe 33244 }245 }.message shouldBe """0 elements passed but expected 2246The following elements passed:247--none--248The following elements failed:2491 => expected:<33> but was:<1>2502 => expected:<33> but was:<2>2513 => expected:<33> but was:<3>2524 => expected:<33> but was:<4>2535 => expected:<33> but was:<5>"""254 }255 }256 }257}...

Full Screen

Full Screen

ItunesRssTest.kt

Source:ItunesRssTest.kt Github

copy

Full Screen

1package io.appvox.appstore2import io.appvox.appstore.review.ItunesRssReviewRepository.Companion.REQUEST_URL_DOMAIN3import io.appvox.appstore.review.ItunesRssReviewRepository.Companion.REQUEST_URL_PATH4import io.appvox.appstore.review.constant.AppStoreRegion.Companion.fromValue5import io.appvox.appstore.review.constant.ItunesRssSortType6import io.appvox.appstore.review.domain.ItunesRssReview7import io.appvox.core.configuration.RequestConfiguration8import io.kotest.assertions.assertSoftly9import io.kotest.inspectors.forExactly10import io.kotest.matchers.collections.shouldBeEmpty11import io.kotest.matchers.ints.shouldBeBetween12import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual13import io.kotest.matchers.nulls.shouldNotBeNull14import io.kotest.matchers.string.shouldNotBeEmpty15import kotlinx.coroutines.ExperimentalCoroutinesApi16import kotlinx.coroutines.flow.take17import kotlinx.coroutines.flow.collect18import kotlinx.coroutines.test.runBlockingTest19import org.junit.jupiter.params.ParameterizedTest20import org.junit.jupiter.params.provider.CsvSource21class ItunesRssTest : BaseAppStoreMockTest() {22 @ExperimentalCoroutinesApi23 @ParameterizedTest24 @CsvSource(25 "333903271, US, 1, 50"26 )27 fun `Get reviews using default parameters`(28 appId: String,29 region: String,30 pageNo: Int,31 expectedReviewCount: Int32 ) = runBlockingTest {33 REQUEST_URL_DOMAIN = httpMockServerDomain34 val mockData = javaClass.getResource("/review/itunesrss/itunes_rss_reviews_mock_data.xml").readText()35 stubHttpUrl(REQUEST_URL_PATH.format(region, pageNo, appId), mockData)36 val reviews = ArrayList<ItunesRssReview>()37 ItunesRss()38 .reviews { this.appId = appId }39 .take(expectedReviewCount)40 .collect { review ->41 reviews.add(review)42 }43 reviews.forExactly(expectedReviewCount) { result ->44 assertSoftly(result) {45 id.shouldNotBeEmpty()46 region.shouldNotBeNull()47 url.shouldNotBeEmpty()48 latestComment.shouldNotBeNull()49 }50 assertSoftly(result.latestUserComment) {51 userName.shouldNotBeEmpty()52 rating.shouldBeBetween(1, 5)53 appVersion.shouldNotBeEmpty()54 title.shouldNotBeEmpty()55 text.shouldNotBeEmpty()56 time.shouldNotBeNull()57 likeCount.shouldBeGreaterThanOrEqual(0)58 commentTypes.shouldNotBeNull()59 userTypes.shouldNotBeNull()60 }61 }62 }63 @ExperimentalCoroutinesApi64 @ParameterizedTest65 @CsvSource(66 "333903271, US, 1, 50"67 )68 fun `get most recent reviews with a delay of 3s between each request`(69 appId: String,70 region: String,71 pageNo: Int,72 expectedReviewCount: Int73 ) = runBlockingTest {74 REQUEST_URL_DOMAIN = httpMockServerDomain75 val mockData = javaClass.getResource("/review/itunesrss/itunes_rss_reviews_mock_data.xml").readText()76 stubHttpUrl(REQUEST_URL_PATH.format(region, pageNo, appId), mockData)77 val reviews = arrayListOf<ItunesRssReview>()78 val itunesRss = ItunesRss(RequestConfiguration(delay = 3000))79 itunesRss.reviews {80 this.appId = appId81 this.region = fromValue(region)82 this.sortType = ItunesRssSortType.RECENT83 }84 .take(expectedReviewCount)85 .collect { review ->86 reviews.add(review)87 }88 reviews.forExactly(expectedReviewCount) { result ->89 assertSoftly(result) {90 id.shouldNotBeEmpty()91 region.shouldNotBeNull()92 url.shouldNotBeEmpty()93 latestComment.shouldNotBeNull()94 }95 assertSoftly(result.latestUserComment) {96 userName.shouldNotBeEmpty()97 rating.shouldBeBetween(1, 5)98 appVersion.shouldNotBeEmpty()99 title.shouldNotBeEmpty()100 text.shouldNotBeEmpty()101 time.shouldNotBeNull()102 likeCount.shouldBeGreaterThanOrEqual(0)103 commentTypes.shouldNotBeNull()104 userTypes.shouldNotBeNull()105 }106 }107 }108 @ExperimentalCoroutinesApi109 @ParameterizedTest110 @CsvSource(111 "1208224953, ZW, 1"112 )113 fun `Get reviews with an empty response`(114 appId: String,115 region: String,116 pageNo: Int117 ) = runBlockingTest {118 REQUEST_URL_DOMAIN = httpMockServerDomain119 val mockData = javaClass.getResource("/review/itunesrss/itunes_rss_reviews_empty_mock_data.xml").readText()120 stubHttpUrl(REQUEST_URL_PATH.format(region, pageNo, appId), mockData)121 val reviews = ArrayList<ItunesRssReview>()122 ItunesRss()123 .reviews {124 this.appId = appId125 this.region = fromValue(region)126 this.sortType = ItunesRssSortType.RECENT127 }128 .collect { review ->129 reviews.add(review)130 }131 reviews.shouldBeEmpty()132 }133}...

Full Screen

Full Screen

AppStoreTest.kt

Source:AppStoreTest.kt Github

copy

Full Screen

1package io.appvox.appstore2import io.appvox.appstore.app.AppStoreRepository.Companion.APP_HP_URL_DOMAIN3import io.appvox.appstore.app.AppStoreRepository.Companion.APP_HP_URL_PATH4import io.appvox.appstore.review.AppStoreReviewRepository5import io.appvox.appstore.review.AppStoreReviewRepository.Companion.REQUEST_URL_DOMAIN6import io.appvox.appstore.review.AppStoreReviewRepository.Companion.REQUEST_URL_PATH7import io.appvox.appstore.review.constant.AppStoreRegion.Companion.fromValue8import io.appvox.appstore.review.domain.AppStoreReview9import io.appvox.core.configuration.RequestConfiguration10import io.kotest.assertions.assertSoftly11import io.kotest.inspectors.forExactly12import io.kotest.matchers.ints.shouldBeBetween13import io.kotest.matchers.nulls.shouldNotBeNull14import io.kotest.matchers.string.shouldNotBeEmpty15import kotlinx.coroutines.ExperimentalCoroutinesApi16import kotlinx.coroutines.flow.collect17import kotlinx.coroutines.flow.take18import kotlinx.coroutines.test.runBlockingTest19import org.junit.jupiter.params.ParameterizedTest20import org.junit.jupiter.params.provider.CsvSource21class AppStoreTest : BaseAppStoreMockTest() {22 @ExperimentalCoroutinesApi23 @ParameterizedTest24 @CsvSource(25 "333903271, us, 10"26 )27 fun `Get reviews using default parameters`(28 appId: String,29 regionCode: String,30 expectedReviewCount: Int31 ) = runBlockingTest {32 REQUEST_URL_DOMAIN = httpMockServerDomain33 APP_HP_URL_DOMAIN = httpMockServerDomain34 val region = fromValue(regionCode)35 val bearerTokenRequestUrlPath = APP_HP_URL_PATH.format(region.code, appId)36 stubHttpUrl(bearerTokenRequestUrlPath, "mock-bearer-token")37 val mockData = javaClass.getResource("/review/appstore/appstore_reviews_mock_data.json").readText()38 stubHttpUrl(REQUEST_URL_PATH.format(region.code, appId, AppStoreReviewRepository.REQUEST_REVIEW_SIZE), mockData)39 val reviews = ArrayList<AppStoreReview>()40 AppStore().reviews{ this.appId = appId }41 .take(expectedReviewCount)42 .collect { review ->43 reviews.add(review)44 }45 reviews.forExactly(expectedReviewCount) { result ->46 assertSoftly(result) {47 id.shouldNotBeEmpty()48 region.shouldNotBeNull()49 userName.shouldNotBeEmpty()50 rating.shouldBeBetween(1, 5)51 title.shouldNotBeEmpty()52 comment.shouldNotBeEmpty()53 commentTime.shouldNotBeNull()54 replyComment?.let { it.shouldNotBeEmpty() }55 replyTime?.let { it.shouldNotBeNull() }56 commentTypes.shouldNotBeNull()57 userTypes.shouldNotBeNull()58 }59 }60 }61 @ExperimentalCoroutinesApi62 @ParameterizedTest63 @CsvSource(64 "333903271, us, 10"65 )66 fun `get most recent reviews with a delay of 3s between each request`(67 appId: String,68 regionCode: String,69 expectedReviewCount: Int70 ) = runBlockingTest {71 REQUEST_URL_DOMAIN = httpMockServerDomain72 APP_HP_URL_DOMAIN = httpMockServerDomain73 val region = fromValue(regionCode)74 val bearerTokenRequestUrlPath = APP_HP_URL_PATH.format(region.code, appId)75 stubHttpUrl(bearerTokenRequestUrlPath, "mock-bearer-token")76 val mockData = javaClass.getResource("/review/appstore/appstore_reviews_mock_data.json").readText()77 stubHttpUrl(REQUEST_URL_PATH.format(region.code, appId, AppStoreReviewRepository.REQUEST_REVIEW_SIZE), mockData)78 val reviews = arrayListOf<AppStoreReview>()79 val appStore = AppStore(RequestConfiguration(delay = 3000))80 appStore.reviews {81 this.appId = appId82 this.region = region83 }84 .take(expectedReviewCount)85 .collect { review ->86 reviews.add(review)87 }88 reviews.forExactly(expectedReviewCount) { result ->89 assertSoftly(result) {90 id.shouldNotBeEmpty()91 region.shouldNotBeNull()92 userName.shouldNotBeEmpty()93 rating.shouldBeBetween(1, 5)94 title.shouldNotBeEmpty()95 comment.shouldNotBeEmpty()96 commentTime.shouldNotBeNull()97 replyComment?.let { it.shouldNotBeEmpty() }98 replyTime?.let { it.shouldNotBeNull() }99 commentTypes.shouldNotBeNull()100 userTypes.shouldNotBeNull()101 }102 }103 }104}...

Full Screen

Full Screen

Inspectors.kt

Source:Inspectors.kt Github

copy

Full Screen

1package com.github.shwaka.kotest.inspectors2import io.kotest.inspectors.ElementPass3import io.kotest.inspectors.runTests4fun <T> Sequence<T>.forAll(fn: (T) -> Unit) = toList().forAll(fn)5fun <T> Array<T>.forAll(fn: (T) -> Unit) = asList().forAll(fn)6fun <T> Collection<T>.forAll(fn: (T) -> Unit) {7 val results = runTests(this, fn)8 val passed = results.filterIsInstance<ElementPass<T>>()9 if (passed.size < this.size) {10 val msg = "${passed.size} elements passed but expected ${this.size}"11 buildAssertionError(msg, results)12 }13}14fun <T> Sequence<T>.forOne(fn: (T) -> Unit) = toList().forOne(fn)15fun <T> Array<T>.forOne(fn: (T) -> Unit) = asList().forOne(fn)16fun <T> Collection<T>.forOne(fn: (T) -> Unit) = forExactly(1, fn)17fun <T> Sequence<T>.forExactly(k: Int, fn: (T) -> Unit) = toList().forExactly(k, fn)18fun <T> Array<T>.forExactly(k: Int, fn: (T) -> Unit) = toList().forExactly(k, fn)19fun <T> Collection<T>.forExactly(k: Int, fn: (T) -> Unit) {20 val results = runTests(this, fn)21 val passed = results.filterIsInstance<ElementPass<T>>()22 if (passed.size != k) {23 val msg = "${passed.size} elements passed but expected $k"24 buildAssertionError(msg, results)25 }26}27fun <T> Sequence<T>.forSome(fn: (T) -> Unit) = toList().forSome(fn)28fun <T> Array<T>.forSome(fn: (T) -> Unit) = toList().forSome(fn)29fun <T> Collection<T>.forSome(fn: (T) -> Unit) {30 val results = runTests(this, fn)31 val passed = results.filterIsInstance<ElementPass<T>>()32 if (passed.isEmpty()) {33 buildAssertionError("No elements passed but expected at least one", results)34 } else if (passed.size == size) {35 buildAssertionError("All elements passed but expected < $size", results)36 }37}38fun <T> Sequence<T>.forAny(fn: (T) -> Unit) = toList().forAny(fn)39fun <T> Array<T>.forAny(fn: (T) -> Unit) = toList().forAny(fn)40fun <T> Collection<T>.forAny(fn: (T) -> Unit) = forAtLeastOne(fn)41fun <T> Sequence<T>.forAtLeastOne(fn: (T) -> Unit) = toList().forAtLeastOne(fn)42fun <T> Array<T>.forAtLeastOne(fn: (T) -> Unit) = toList().forAtLeastOne(fn)43fun <T> Collection<T>.forAtLeastOne(f: (T) -> Unit) = forAtLeast(1, f)44fun <T> Sequence<T>.forAtLeast(k: Int, fn: (T) -> Unit) = toList().forAtLeast(k, fn)45fun <T> Array<T>.forAtLeast(k: Int, fn: (T) -> Unit) = toList().forAtLeast(k, fn)46fun <T> Collection<T>.forAtLeast(k: Int, fn: (T) -> Unit) {47 val results = runTests(this, fn)48 val passed = results.filterIsInstance<ElementPass<T>>()49 if (passed.size < k) {50 val msg = "${passed.size} elements passed but expected at least $k"51 buildAssertionError(msg, results)52 }53}54fun <T> Sequence<T>.forAtMostOne(fn: (T) -> Unit) = toList().forAtMostOne(fn)55fun <T> Array<T>.forAtMostOne(fn: (T) -> Unit) = toList().forAtMostOne(fn)56fun <T> Collection<T>.forAtMostOne(fn: (T) -> Unit) = forAtMost(1, fn)57fun <T> Sequence<T>.forAtMost(k: Int, fn: (T) -> Unit) = toList().forAtMost(k, fn)58fun <T> Array<T>.forAtMost(k: Int, fn: (T) -> Unit) = toList().forAtMost(k, fn)59fun <T> Collection<T>.forAtMost(k: Int, fn: (T) -> Unit) {60 val results = runTests(this, fn)61 val passed = results.filterIsInstance<ElementPass<T>>()62 if (passed.size > k) {63 val msg = "${passed.size} elements passed but expected at most $k"64 buildAssertionError(msg, results)65 }66}67fun <T> Sequence<T>.forNone(fn: (T) -> Unit) = toList().forNone(fn)68fun <T> Array<T>.forNone(fn: (T) -> Unit) = toList().forNone(fn)69fun <T> Collection<T>.forNone(f: (T) -> Unit) {70 val results = runTests(this, f)71 val passed = results.filterIsInstance<ElementPass<T>>()72 if (passed.isNotEmpty()) {73 val msg = "${passed.size} elements passed but expected ${0}"74 buildAssertionError(msg, results)75 }76}...

Full Screen

Full Screen

NumbersTestWithInspectors.kt

Source:NumbersTestWithInspectors.kt Github

copy

Full Screen

1import io.kotest.core.spec.style.StringSpec2import io.kotest.inspectors.*3import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual4import io.kotest.matchers.shouldBe5class NumbersTestWithInspectors : StringSpec({6 val numbers = Array(10) { it + 1 }7 "all are non-negative" {8 numbers.forAll { it shouldBeGreaterThanOrEqual 0 }9 }10 "none is zero" { numbers.forNone { it shouldBe 0 } }11 "a single 10" { numbers.forOne { it shouldBe 10 } }12 "at most one 0" { numbers.forAtMostOne { it shouldBe 0 } }13 "at least one odd number" {14 numbers.forAtLeastOne { it % 2 shouldBe 1 }15 }16 "at most five odd numbers" {17 numbers.forAtMost(5) { it % 2 shouldBe 1 }18 }19 "at least three even numbers" {20 numbers.forAtLeast(3) { it % 2 shouldBe 0 }21 }22 "some numbers are odd" { numbers.forAny { it % 2 shouldBe 1 } }23 "some but not all numbers are even" {24 numbers.forSome { it % 2 shouldBe 0 }25 }26 "exactly five numbers are even" {27 numbers.forExactly(5) { it % 2 shouldBe 0 }28 }29})...

Full Screen

Full Screen

Array.forExactly

Using AI Code Generation

copy

Full Screen

1val list = listOf("a", "b", "c")2forExactly(2, list) { it should startWith("a") }3val list = listOf("a", "b", "c")4forNone(list) { it should startWith("d") }5val list = listOf("a", "b", "c")6forOne(list) { it should startWith("a") }7val list = listOf("a", "b", "c")8forSome(list) { it should startWith("a") }9val list = listOf("a", "b", "c")10forExactly(2, list) { it should startWith("a") }11val list = listOf("a", "b", "c")12forNone(list) { it should startWith("d") }13val list = listOf("a", "b", "c")14forOne(list) { it should startWith("a") }15val list = listOf("a", "b", "c")16forSome(list) { it should startWith("a") }17val list = listOf("a", "b", "c")18forExactly(2, list) { it should startWith("a") }19val list = listOf("a", "b", "c")20forNone(list) { it should startWith("d") }21val list = listOf("a", "b", "c")22forOne(list) { it should startWith("a") }

Full Screen

Full Screen

Array.forExactly

Using AI Code Generation

copy

Full Screen

1val numbers = intArrayOf(1, 2, 3, 4, 5)2val numbers = intArrayOf(1, 2, 3, 4, 5)3val numbers = intArrayOf(1, 2, 3, 4, 5)4val numbers = intArrayOf(1, 2, 3, 4, 5)5val numbers = intArrayOf(1, 2, 3, 4, 5)6val numbers = intArrayOf(1, 2, 3, 4, 5)7forAll(numbers) { n

Full Screen

Full Screen

Array.forExactly

Using AI Code Generation

copy

Full Screen

1@DisplayName("Test forExactly")2fun testForExactly() {3val list = listOf(1, 2, 3, 4, 5, 6)4forExactly(2, list) {5it.shouldBeLessThan(3)6}7}8@DisplayName("Test forAtLeast")9fun testForAtLeast() {10val list = listOf(1, 2, 3, 4, 5, 6)11forAtLeast(2, list) {12it.shouldBeLessThan(3)13}14}15@DisplayName("Test forAtMost")16fun testForAtMost() {17val list = listOf(1, 2, 3, 4, 5, 6)18forAtMost(2, list) {19it.shouldBeLessThan(3)20}21}22@DisplayName("Test forNone")23fun testForNone() {24val list = listOf(1, 2, 3, 4, 5, 6)25forNone(list) {26it.shouldBeGreaterThan(10)27}28}29@DisplayName("Test forOne")30fun testForOne() {31val list = listOf(1, 2, 3, 4, 5, 6)32forOne(list) {33it.shouldBeLessThan(3)34}35}36@DisplayName("Test forNone")37fun testForNone() {38val list = listOf(1, 2, 3, 4, 5, 6)39forNone(list) {40it.shouldBeGreaterThan(10)41}42}43@DisplayName("Test forExactly")44fun testForExactly() {45val list = listOf(1, 2, 3, 4, 5, 6)46forExactly(2, list) {47it.shouldBeLessThan(

Full Screen

Full Screen

Array.forExactly

Using AI Code Generation

copy

Full Screen

1@DisplayName ( "Testing the Array.forExactly method" ) @Test fun testArrayForExactly () { val array = arrayOf ( 1 , 2 , 3 , 4 , 5 ) array . forExactly ( 3 ) { it should beGreaterThan ( 0 ) } }2@DisplayName ( "Testing the Array.forAtLeast method" ) @Test fun testArrayForAtLeast () { val array = arrayOf ( 1 , 2 , 3 , 4 , 5 ) array . forAtLeast ( 3 ) { it should beGreaterThan ( 0 ) } }3@DisplayName ( "Testing the Array.forAtMost method" ) @Test fun testArrayForAtMost () { val array = arrayOf ( 1 , 2 , 3 , 4 , 5 ) array . forAtMost ( 3 ) { it should beGreaterThan ( 0 ) } }4@DisplayName ( "Testing the Array.forNone method" ) @Test fun testArrayForNone () { val array = arrayOf ( 1 , 2 , 3 , 4 , 5 ) array . forNone { it should beGreaterThan ( 6 ) } }5@DisplayName ( "Testing the Array.forOne method" ) @Test fun testArrayForOne () { val array = arrayOf ( 1 , 2 , 3 , 4 , 5 ) array . forOne { it should beGreaterThan ( 3 ) } }6@DisplayName ( "Testing the Array.forExactlyOne method" ) @Test fun testArrayForExactlyOne () { val array = arrayOf ( 1 , 2 , 3 , 4 , 5 ) array . forExactlyOne { it should beGreaterThan ( 3 ) } }7@DisplayName ( "Testing the Array.forAny method" ) @Test fun testArrayFor

Full Screen

Full Screen

Array.forExactly

Using AI Code Generation

copy

Full Screen

1@kotlin.test.Test fun test() {2val arr = arrayOf(1, 2, 3, 4, 5)3arr.forExactly(3) { it should beGreaterThan(2) }4}5@kotlin.test.Test fun test() {6val arr = arrayOf(1, 2, 3, 4, 5)7forExactly(arr, 3) { it should beGreaterThan(2) }8}9@kotlin.test.Test fun test() {10val arr = arrayOf(1, 2, 3, 4, 5)11forExactly(3, arr) { it should beGreaterThan(2) }12}13@kotlin.test.Test fun test() {14val arr = arrayOf(1, 2, 3, 4, 5)15forExactly(3, arr) { it should beGreaterThan(2) }16}17@kotlin.test.Test fun test() {18val arr = arrayOf(1, 2, 3, 4, 5)19forExactly(3, arr) { it should beGreaterThan(2) }20}21@kotlin.test.Test fun test() {22val arr = arrayOf(1, 2, 3, 4, 5)23forExactly(3, arr) { it should beGreaterThan(2) }24}25@kotlin.test.Test fun test() {26val arr = arrayOf(1, 2, 3, 4, 5)27forExactly(3, arr) { it should beGreaterThan(2) }28}29@kotlin.test.Test fun test() {30val arr = arrayOf(1, 2, 3, 4, 5)

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