Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide test coverage for NonEmptyList #3135

Merged
merged 9 commits into from
Oct 19, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import io.kotest.matchers.booleans.shouldBeTrue
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
import io.kotest.property.Arb
import io.kotest.property.arbitrary.boolean
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.negativeInt
import io.kotest.property.arbitrary.pair
import io.kotest.property.arbitrary.*
import io.kotest.property.checkAll
import kotlin.math.max
import kotlin.math.min
Expand Down Expand Up @@ -445,4 +442,56 @@ class NonEmptyListTest : StringSpec({
}
}
}

"lastOrNull" {
checkAll(
Arb.nonEmptyList(Arb.int())
) { a ->
val result = a.lastOrNull()
val expected = a.last()
result shouldBe expected
}
}

"extract" {
checkAll(
Arb.nonEmptyList(Arb.int())
) { a ->
val result = a.extract()
val expected = a.head
result shouldBe expected
}
}

"plus" {
checkAll(
Arb.nonEmptyList(Arb.int()),
Arb.int()
) { a, b ->
val result = a + b
val expected = a.all + b
result shouldBe expected
}
}

"coflatMap should retain the same length as the original list" {
checkAll(
Arb.nonEmptyList(Arb.int())
) { a ->
val result = a.coflatMap { it.all }
val expected = a.all
result.size shouldBe expected.size
}
}

"foldLeft should sum up correctly for addition" {
checkAll(
Arb.nonEmptyList(Arb.int()),
Arb.int()
) { list, initial ->
val result = list.foldLeft(initial) { acc, i -> acc + i }
val expected = initial + list.all.sum()
result shouldBe expected
}
}
})