diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/CurryingTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/CurryingTest.kt new file mode 100644 index 00000000000..ed48d327f92 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/CurryingTest.kt @@ -0,0 +1,72 @@ +package arrow.core + +import io.kotest.core.spec.style.StringSpec +import io.kotest.property.checkAll +import io.kotest.matchers.shouldBe + +class CurryingTest : StringSpec({ + + "Result of calling a 2-arity curried function should be same as calling the uncurried function" { + checkAll { a1, a2 -> + val add = { p1: Int, p2: Int -> p1 + p2 } + add.curried()(a1)(a2) shouldBe a1 + a2 + } + } + + "Result of calling a 3-arity curried function should be same as calling the uncurried function" { + checkAll { a1, a2, a3 -> + val add = { p1: Int, p2: Int, p3: Int -> p1 + p2 + p3 } + add.curried()(a1)(a2)(a3) shouldBe a1 + a2 + a3 + } + } + + "Result of calling a 4-arity curried function should be same as calling the uncurried function" { + checkAll { a1, a2, a3, a4 -> + val add = { p1: Int, p2: Int, p3: Int, p4: Int -> p1 + p2 + p3 + p4 } + add.curried()(a1)(a2)(a3)(a4) shouldBe a1 + a2 + a3 + a4 + } + } + + "Result of calling a 5-arity curried function should be same as calling the uncurried function" { + checkAll { a1, a2, a3, a4, a5 -> + val add = { p1: Int, p2: Int, p3: Int, p4: Int, p5: Int -> p1 + p2 + p3 + p4 + p5 } + add.curried()(a1)(a2)(a3)(a4)(a5) shouldBe a1 + a2 + a3 + a4 + a5 + } + } + + "Result of calling a 6-arity curried function should be same as calling the uncurried function" { + checkAll { a1, a2, a3, a4, a5, a6 -> + val add = { p1: Int, p2: Int, p3: Int, p4: Int, p5: Int, p6: Int -> p1 + p2 + p3 + p4 + p5 + p6 } + add.curried()(a1)(a2)(a3)(a4)(a5)(a6) shouldBe a1 + a2 + a3 + a4 + a5 + a6 + } + } + + "Result of calling a 7-arity curried function should be same as calling the uncurried function" { + checkAll { a1, a2, a3, a4, a5, a6, a7 -> + val add = { p1: Int, p2: Int, p3: Int, p4: Int, p5: Int, p6: Int, p7: Int -> p1 + p2 + p3 + p4 + p5 + p6 + p7 } + add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7) shouldBe a1 + a2 + a3 + a4 + a5 + a6 + a7 + } + } + + "Result of calling a 8-arity curried function should be same as calling the uncurried function" { + checkAll { a1, a2, a3, a4, a5, a6, a7, a8 -> + val add = { p1: Int, p2: Int, p3: Int, p4: Int, p5: Int, p6: Int, p7: Int, p8: Int -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 } + add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8) shouldBe a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + } + } + + "Result of calling a 9-arity curried function should be same as calling the uncurried function" { + checkAll { a1, a2, a3, a4, a5, a6, a7, a8, a9 -> + val add = { p1: Int, p2: Int, p3: Int, p4: Int, p5: Int, p6: Int, p7: Int, p8: Int, p9: Int -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 } + add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9) shouldBe a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + } + } + + "Result of calling a 10-arity curried function should be same as calling the uncurried function" { + checkAll { a1, a2, a3, a4, a5, a6, a7, a8, a9, a10-> + val add = { p1: Int, p2: Int, p3: Int, p4: Int, p5: Int, p6: Int, p7: Int, p8: Int, p9: Int, p10: Int -> p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 } + add.curried()(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8)(a9)(a10) shouldBe a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + } + } + +})