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

Update ComparisonKtTest.kt #3274

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package arrow.core

import io.kotest.assertions.assertSoftly
import io.kotest.core.spec.style.StringSpec
import io.kotest.property.Arb
import io.kotest.property.checkAll
import io.kotest.matchers.shouldBe
Expand All @@ -12,6 +11,8 @@ import io.kotest.property.arbitrary.list
import io.kotest.property.arbitrary.long
import io.kotest.property.arbitrary.short
import io.kotest.property.arbitrary.string
import kotlinx.coroutines.test.runTest
import kotlin.test.Test

data class Person(val age: Int, val name: String) : Comparable<Person> {
companion object {
Expand All @@ -29,8 +30,8 @@ data class Person(val age: Int, val name: String) : Comparable<Person> {
fun Arb.Companion.person(): Arb<Person> =
Arb.bind(Arb.int(), Arb.string(), ::Person)

class ComparisonKtTest : StringSpec({
"Arberic - sort2" {
class ComparisonKtTest {
@Test fun arbericSort2() = runTest {
checkAll(Arb.person(), Arb.person()) { a, b ->
val (first, second) = sort(a, b)
val (aa, bb) = listOf(a, b).sorted()
Expand All @@ -42,7 +43,7 @@ class ComparisonKtTest : StringSpec({
}
}

"Arberic - sort3" {
@Test fun arbericSort3() = runTest {
checkAll(Arb.person(), Arb.person(), Arb.person()) { a, b, c ->
val (first, second, third) = sort(a, b, c)
val (aa, bb, cc) = listOf(a, b, c).sorted()
Expand All @@ -55,7 +56,7 @@ class ComparisonKtTest : StringSpec({
}
}

"Arberic - sortAll" {
@Test fun arbericSortAll() = runTest {
checkAll(Arb.person(), Arb.list(Arb.person(), 0..50)) { a, lst ->
val aas = lst.toTypedArray()
val res = sort(a, *aas)
Expand All @@ -65,7 +66,7 @@ class ComparisonKtTest : StringSpec({
}
}

"Arberic - comparator - sort2" {
@Test fun arbericComparatorSort2() = runTest {
checkAll(Arb.person(), Arb.person()) { a, b ->
val (first, second) = sort(a, b, Person.comparator)
val (aa, bb) = listOf(a, b).sorted()
Expand All @@ -77,7 +78,7 @@ class ComparisonKtTest : StringSpec({
}
}

"Arberic - comparator - sort3" {
@Test fun arbericComparatorSort3() = runTest {
checkAll(Arb.person(), Arb.person(), Arb.person()) { a, b, c ->
val (first, second, third) = sort(a, b, c, Person.comparator)
val (aa, bb, cc) = listOf(a, b, c).sorted()
Expand All @@ -90,7 +91,7 @@ class ComparisonKtTest : StringSpec({
}
}

"Byte - sort2" {
@Test fun byteSort2() = runTest {
checkAll(Arb.byte(), Arb.byte()) { a, b ->
val (first, second) = sort(a, b)
val (aa, bb) = listOf(a, b).sorted()
Expand All @@ -102,7 +103,7 @@ class ComparisonKtTest : StringSpec({
}
}

"Byte - sort3" {
@Test fun byteSort3() = runTest {
checkAll(Arb.byte(), Arb.byte(), Arb.byte()) { a, b, c ->
val (first, second, third) = sort(a, b, c)
val (aa, bb, cc) = listOf(a, b, c).sorted()
Expand All @@ -115,7 +116,7 @@ class ComparisonKtTest : StringSpec({
}
}

"Byte - sortAll" {
@Test fun byteSortAll() = runTest {
checkAll(Arb.byte(), Arb.byte(), Arb.byte(), Arb.byte()) { a, b, c, d ->
val res = sort(a, b, c, d)
val expected = listOf(a, b, c, d).sorted()
Expand All @@ -124,7 +125,7 @@ class ComparisonKtTest : StringSpec({
}
}

"Short - sort2" {
@Test fun shortSort2() = runTest {
checkAll(Arb.short(), Arb.short()) { a, b ->
val (first, second) = sort(a, b)
val (aa, bb) = listOf(a, b).sorted()
Expand All @@ -136,7 +137,7 @@ class ComparisonKtTest : StringSpec({
}
}

"Short - sort3" {
@Test fun shortSort3() = runTest {
checkAll(Arb.short(), Arb.short(), Arb.short()) { a, b, c ->
val (first, second, third) = sort(a, b, c)
val (aa, bb, cc) = listOf(a, b, c).sorted()
Expand All @@ -149,16 +150,16 @@ class ComparisonKtTest : StringSpec({
}
}

"Short - sortAll" {
@Test fun shortSortAll() = runTest {
checkAll(Arb.short(), Arb.short(), Arb.short(), Arb.short()) { a, b, c, d ->
val res = sort(a, b, c, d)
val expected = listOf(a, b, c, d).sorted()

res shouldBe expected
}
}

"Int - sort2" {
@Test fun intSort2() = runTest {
checkAll(Arb.int(), Arb.int()) { a, b ->
val (first, second) = sort(a, b)
val (aa, bb) = listOf(a, b).sorted()
Expand All @@ -168,7 +169,7 @@ class ComparisonKtTest : StringSpec({
}
}

"Int - sort3" {
@Test fun intSort3() = runTest {
checkAll(Arb.int(), Arb.int(), Arb.int()) { a, b, c ->
val (first, second, third) = sort(a, b, c)
val (aa, bb, cc) = listOf(a, b, c).sorted()
Expand All @@ -181,7 +182,7 @@ class ComparisonKtTest : StringSpec({
}
}

"Int - sortAll" {
@Test fun intSortAll() = runTest {
checkAll(Arb.int(), Arb.int(), Arb.int(), Arb.int()) { a, b, c, d ->
val res = sort(a, b, c, d)
val expected = listOf(a, b, c, d).sorted()
Expand All @@ -190,7 +191,7 @@ class ComparisonKtTest : StringSpec({
}
}

"Long - sort2" {
@Test fun longSort2() = runTest {
checkAll(Arb.long(), Arb.long()) { a, b ->
val (first, second) = sort(a, b)
val (aa, bb) = listOf(a, b).sorted()
Expand All @@ -202,7 +203,7 @@ class ComparisonKtTest : StringSpec({
}
}

"Long - sort3" {
@Test fun longSort3() = runTest {
checkAll(Arb.long(), Arb.long(), Arb.long()) { a, b, c ->
val (first, second, third) = sort(a, b, c)
val (aa, bb, cc) = listOf(a, b, c).sorted()
Expand All @@ -215,12 +216,12 @@ class ComparisonKtTest : StringSpec({
}
}

"Long - sortAll" {
@Test fun longSortAll() = runTest {
checkAll(Arb.long(), Arb.long(), Arb.long(), Arb.long()) { a, b, c, d ->
val res = sort(a, b, c, d)
val expected = listOf(a, b, c, d).sorted()

res shouldBe expected
}
}
})
}