From 1eb31194fece025c88defcc53cb3ffa581cc9d1e Mon Sep 17 00:00:00 2001 From: Jun Sekine Date: Tue, 11 Apr 2023 23:22:22 +0900 Subject: [PATCH] add some Iterable tests (#2894) --- .../kotlin/arrow/core/IterableTest.kt | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt index 7a1fe712366..7cafb6c9648 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt @@ -7,16 +7,12 @@ import arrow.core.test.option import arrow.typeclasses.Semigroup import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.collections.shouldContainExactly +import io.kotest.matchers.collections.shouldHaveUpperBound import io.kotest.matchers.nulls.shouldBeNull import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.property.Arb import io.kotest.matchers.shouldBe -import io.kotest.property.arbitrary.boolean -import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.list -import io.kotest.property.arbitrary.orNull -import io.kotest.property.arbitrary.pair -import io.kotest.property.arbitrary.string +import io.kotest.property.arbitrary.* import io.kotest.property.checkAll import kotlin.math.max import kotlin.math.min @@ -553,6 +549,26 @@ class IterableTest : StringSpec({ } } + "flatten" { + checkAll(Arb.pair(Arb.list(Arb.int()), Arb.list(Arb.int()))) { (a, b) -> + listOf(a, b).flatten() shouldBe a + b + } + } + + "widen(Iterable)" { + checkAll(Arb.list(Arb.string())) { orig: Iterable -> + val result: Iterable = orig.widen() + result shouldContainExactly orig + } + } + + "widen(List)" { + checkAll(Arb.list(Arb.string())) { orig: List -> + val result: List = orig.widen() + result shouldContainExactly orig + } + } + "unzip is the inverse of zip" { checkAll(Arb.list(Arb.int())) { xs -> @@ -628,4 +644,19 @@ class IterableTest : StringSpec({ } } } + + "compareTo returns 0 if other has same elements" { + checkAll(Arb.list(Arb.int())) { ints -> + ints.compareTo(ints) shouldBe 0 + } + } + + "compareTo returns -1 if other have greater element at the same position"{ + listOf(1,2,3).compareTo(listOf(1,4,3)) shouldBe -1 + } + + "compareTo returns 1 if other have smaller element at the same position"{ + listOf(1,2,3).compareTo(listOf(1,1,3)) shouldBe 1 + } + })