Skip to content

Commit

Permalink
Provide test coverage for currying (arrow-kt#2894)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgtout committed Feb 3, 2023
1 parent 09384c1 commit bacd904
Showing 1 changed file with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Int, Int> { 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<Int, Int, Int> { 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<Int, Int, Int, Int> { 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<Int, Int, Int, Int, Int> { 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<Int, Int, Int, Int, Int, Int> { 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<Int, Int, Int, Int, Int, Int, Int> { 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<Int, Int, Int, Int, Int, Int, Int, Int> { 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<Int, Int, Int, Int, Int, Int, Int, Int, Int> { 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<Int, Int, Int, Int, Int, Int, Int, Int, Int, Int> { 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
}
}

})

0 comments on commit bacd904

Please sign in to comment.