I was wondering if there is a way to test a function embedded within another function in Scala? Or the only to test it is to lift it as a top level function??
def processNumbers(n: Int): Int = {
def isEven(num: Int): Boolean = num % 2 == 0
if (isEven(n)) 0 else -1
}
For example, in the code snippet above I would like to be able to unit test isEven
without having to make it the top level function.
By "top-level", I meant writing it at the same level as the "parent" function. In this case it would look like:
def isEven(num: Int): Boolean = num % 2 == 0
def processNumbers(n: Int): Int = if (isEven(n)) 0 else -1