Unit testing FsUnit-值或构造函数';应该';没有定义

Unit testing FsUnit-值或构造函数';应该';没有定义,unit-testing,f#,fsunit,Unit Testing,F#,Fsunit,好的,我在看FsUnit为一些F#代码开发测试,我在看BowlingGame.fsx上的示例 要参加第一次测试: [<Test>] let ``with simple scores should get the expected score.`` () = scoreBowls [1;2;3] |> should equal 6 有什么建议吗 编辑:下面添加了完整的源代码 module Calculations.UnitTests open NUnit.Framework

好的,我在看FsUnit为一些F#代码开发测试,我在看BowlingGame.fsx上的示例

要参加第一次测试:

[<Test>] 
let ``with simple scores should get the expected score.`` () =
scoreBowls [1;2;3] |> should equal 6
有什么建议吗

编辑:下面添加了完整的源代码

module Calculations.UnitTests

open NUnit.Framework
open FsUnit

let (|EndOfGame|IncompleteStrike|Strike|Normal|Other|) (l, frame) =
    match l with
    | _ when frame = 11            -> EndOfGame(0)
    | [10;s]                       -> IncompleteStrike(10+s+s)
    | 10::s::n::tail               -> Strike(10+s+n, s::n::tail)
    |  f::s::n::tail when f+s = 10 -> Normal(f+s+n,  n::tail)
    |  f::s::n::tail               -> Normal(f+s,    n::tail)
    | ls                           -> Other(List.fold (+) 0 ls)

let scoreBowls bowls =
    let rec scoreBowls' frame l current_score =
        let nextframe = scoreBowls' (frame+1)
        match (l, frame) with
        | EndOfGame(score)        -> current_score + score
        | IncompleteStrike(score) -> current_score + score
        | Strike(score, l)        -> nextframe l (current_score + score)
        | Normal(score, l)        -> nextframe l (current_score + score)
        | Other(score)            -> current_score + score
    scoreBowls' 1 bowls 0

[<Test>] 
let ``with simple scores should get the expected score.`` () =
    scoreBowls [1;2;3] |> should equal 6

[<Test>]
let ``with a spare should get the expected score (spare).`` () =
    scoreBowls [2;8;1] |> should equal 12

[<Test>]
let ``with a strike should get the expected score (strike).`` () =
    scoreBowls [10;1;2] |> should equal 16

[<Test>]
let ``that is perfect should get a score of 300.``() =
    scoreBowls [for i in 1..18 -> 10] |> should equal 300

[<Test>]
let ``with spares in the last frame should get the expected score (spare in last frame).`` () =
    scoreBowls ([for i in 1..18 -> 0] @ [2;8;1]) |> should equal 11

[<Test>]
let ``with a strike in the last frame should get the expected score (strike in last frame).`` () =
    scoreBowls ([for i in 1..18 -> 0] @ [10;10;1]) |> should equal 21

[<Test>] 
let ``with double strikes should add the score of the first strike to the score of the second.``     () =
    scoreBowls [10;10;1] |> should equal 33

[<Test>]
let ``that looks like an average bowler's game should get the expected score (example game).`` () =
    scoreBowls [1;4;4;5;6;4;5;5;10;0;1;7;3;6;4;10;2;8;6] |> should equal 133
模块计算.UnitTests
打开NUnit.Framework
开放式FSU
let(| EndOfGame |不完全罢工|罢工|正常|其他|)(l,框架)=
匹配
|当frame=11->EndOfGame(0)时
|[10;s]>不完全罢工(10+s+s)
|10:s:n:tail->Strike(10+s+n,s:n:tail)
|f+s=10时的f::s::n::tail->Normal(f+s+n,n::tail)
|f::s::n::tail->Normal(f+s,n::tail)
|ls->其他(List.fold(+)0 ls)
让我们把碗放在碗里=
让rec scoreBowls的框架l当前_得分=
让nextframe=scoreBowls'(框架+1)
将(l,框架)与
|EndOfGame(分数)->当前分数+分数
|未完成罢工(分数)->当前罢工分数+分数
|罢工(分数,l)->下一帧l(当前分数+分数)
|正常(分数,l)->下一帧l(当前分数+分数)
|其他(分数)->当前分数+分数
得分碗1个0个
[] 
让具有简单分数的``得到期望分数。`()=
记分牌[1;2;3]|>应等于6
[]
让``有空余的人应该得到期望的分数(空余)。`()=
记分牌[2;8;1]|>应该等于12
[]
让``有一个罢工应该得到预期的分数(罢工)。`()=
记分牌[10;1;2]|>应该等于16
[]
让``完美的应该得到300分。`()=
记分牌[对于1..18->10中的i]|>应等于300
[]
让``在最后一帧中有备件时应获得预期分数(在最后一帧中有备件)。`()=
记分牌([1..18->0中的i]@[2;8;1])|>应该等于11
[]
让``在最后一帧中罢工应获得预期分数(在最后一帧罢工)。`()=
记分牌([1..18->0中的i]@[10;10;1])|>应该等于21
[] 
让``双击得分的人将第一击得分与第二击得分相加。`()=
记分牌[10;10;1]|>应该等于33分
[]
让``看起来像一个普通投球手的比赛应该得到预期的分数(示例赛)。`()=
记分牌[1;4;4;5;6;4;5;5;10;0;1;7;3;6;4;10;2;8;6]|>应该等于133

可能您引用的FsUnit版本错误,与您选择的框架不兼容?删除对FsUnit的引用,然后使用NuGet再次添加。

我无法用VS2013 RTM重新编写。@ildjarn源代码added@Nick我不是用NuGet的VS2013 Express for Desktop和FsUnit复制的。它在项目参考中显示为FsUnit.NUnit 1.3.0.1。努尼特为2.6.3
module Calculations.UnitTests

open NUnit.Framework
open FsUnit

let (|EndOfGame|IncompleteStrike|Strike|Normal|Other|) (l, frame) =
    match l with
    | _ when frame = 11            -> EndOfGame(0)
    | [10;s]                       -> IncompleteStrike(10+s+s)
    | 10::s::n::tail               -> Strike(10+s+n, s::n::tail)
    |  f::s::n::tail when f+s = 10 -> Normal(f+s+n,  n::tail)
    |  f::s::n::tail               -> Normal(f+s,    n::tail)
    | ls                           -> Other(List.fold (+) 0 ls)

let scoreBowls bowls =
    let rec scoreBowls' frame l current_score =
        let nextframe = scoreBowls' (frame+1)
        match (l, frame) with
        | EndOfGame(score)        -> current_score + score
        | IncompleteStrike(score) -> current_score + score
        | Strike(score, l)        -> nextframe l (current_score + score)
        | Normal(score, l)        -> nextframe l (current_score + score)
        | Other(score)            -> current_score + score
    scoreBowls' 1 bowls 0

[<Test>] 
let ``with simple scores should get the expected score.`` () =
    scoreBowls [1;2;3] |> should equal 6

[<Test>]
let ``with a spare should get the expected score (spare).`` () =
    scoreBowls [2;8;1] |> should equal 12

[<Test>]
let ``with a strike should get the expected score (strike).`` () =
    scoreBowls [10;1;2] |> should equal 16

[<Test>]
let ``that is perfect should get a score of 300.``() =
    scoreBowls [for i in 1..18 -> 10] |> should equal 300

[<Test>]
let ``with spares in the last frame should get the expected score (spare in last frame).`` () =
    scoreBowls ([for i in 1..18 -> 0] @ [2;8;1]) |> should equal 11

[<Test>]
let ``with a strike in the last frame should get the expected score (strike in last frame).`` () =
    scoreBowls ([for i in 1..18 -> 0] @ [10;10;1]) |> should equal 21

[<Test>] 
let ``with double strikes should add the score of the first strike to the score of the second.``     () =
    scoreBowls [10;10;1] |> should equal 33

[<Test>]
let ``that looks like an average bowler's game should get the expected score (example game).`` () =
    scoreBowls [1;4;4;5;6;4;5;5;10;0;1;7;3;6;4;10;2;8;6] |> should equal 133