Skip to content

Commit

Permalink
add some Iterable tests (arrow-kt#2894)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoizo committed Apr 11, 2023
1 parent b1ad7f7 commit 1eb3119
Showing 1 changed file with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String> ->
val result: Iterable<CharSequence> = orig.widen()
result shouldContainExactly orig
}
}

"widen(List)" {
checkAll(Arb.list(Arb.string())) { orig: List<String> ->
val result: List<CharSequence> = orig.widen()
result shouldContainExactly orig
}
}

"unzip is the inverse of zip" {
checkAll(Arb.list(Arb.int())) { xs ->

Expand Down Expand Up @@ -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
}

})

0 comments on commit 1eb3119

Please sign in to comment.