Search code examples
scalascalatest

Testing a generated curried function with Scala Test


I'm having hard times trying to create a Scala Test to checks this function:

def curry[A,B,C](f: (A,B) => C): A => (B => C) =
  a => b => f(a,b)

The first thought I had was to validate if given a function fx passed into curry(fx) function, will return a curried version of it.

Any tips?


Solution

  • One way to test it, is to pass different f's to it and see if you are getting back the function you expect. For example, you can test an f that returns the arguments as a tuple:

    def f(x: String, y: Int) = (x, y)
    
    curry(f)("4")(7) must be(("4", 7))
    

    IMO, testing it for a few different functions f and for a few different a and b would be more than sufficiently assuring that something as trivial as this works as intended.