我有一套F#功能,对同样的投入采用不同的算法,如《战略》模式。 为了采纳正确的战略,我想根据投入论点来调整,并将这一职能作为价值:
let equalStrategy points : seq<double> =
...
let multiplyStrategy fact或 (points: seq<double>) =
...
let getStrategy relationship =
match relationship with
| "=" -> equalStrategy
| "*5" -> multiplyStrategy 5.0
| _ -> raise (new System.NotImplementedException(" relationship not handled"))
Now I want to write some unit tests to make sure that I return the right strategy, so I tried something like this in nUnit :
[<TestCase("=")>]
[<Test>]
member self.getEqualstrategy( relationship:string ) =
let strategy = getStrategy relationship
Assert.AreEqual( strategy, equalStrategy )
现在,我认为该守则是正确的,我将做我想要做的事情,但这一说法失败,因为职能似乎没有为它们规定平等行动。 因此,我的问题是:
(a) is there a way to compare 2 functions to see if they are the same, i.e. let isFoo bar = foo == bar, that I can use in an nUnit assertion?
或
(b) is there another unit testing framew或k that will do this assertion f或 me in F#?