samedi 30 janvier 2016

Unit test function returning function in F#

I have written the following function in F# which, given two points, returns a function representing the line which passes throught the two points:

let getFunction (point1:float*float) (point2:float*float) =
    let x1 = fst point1
    let y1 = snd point1
    let x2 = fst point2
    let y2 = snd point2
    let m = (y2-y1)/(x2-x1)
    let n = y1-x1*m
    fun x -> m*x+n

I would like to unit test this function, but I haven't find how to do it, since I can't use a function in a equality assertion. I have thought about generating a secuence of random points and testing the application of the function against the expected result for each point, but I was wondering if there is a better way.

Aucun commentaire:

Enregistrer un commentaire