1
exercism fetch fsharp bowling

BowlingTest.fs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
module BowlingTest

open Xunit
open FsUnit.Xunit

open Bowling

let rollMany rolls game = List.fold (fun game pins -> roll pins game) game rolls

[<Fact>]
let ``Should be able to score a game with all zeros`` () =
    let rolls = [0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0]
    let game = rollMany rolls (newGame())
    score game |> should equal <| Some 0
    
[<Fact(Skip = "Remove to run test")>]
let ``Should be able to score a game with no strikes or spares`` () =
    let rolls = [3; 6; 3; 6; 3; 6; 3; 6; 3; 6; 3; 6; 3; 6; 3; 6; 3; 6; 3; 6]
    let game = rollMany rolls (newGame())
    score game |> should equal <| Some 90
    
[<Fact(Skip = "Remove to run test")>]
let ``A spare followed by zeros is worth ten points`` () =
    let rolls = [6; 4; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0]
    let game = rollMany rolls (newGame())
    score game |> should equal <| Some 10
    
[<Fact(Skip = "Remove to run test")>]
let ``Points scored in the roll after a spare are counted twice`` () =
    let rolls = [6; 4; 3; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0]
    let game = rollMany rolls (newGame())
    score game |> should equal <| Some 16
    
[<Fact(Skip = "Remove to run test")>]
let ``Consecutive spares each get a one roll bonus`` () =
    let rolls = [5; 5; 3; 7; 4; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0]
    let game = rollMany rolls (newGame())
    score game |> should equal <| Some 31
    
[<Fact(Skip = "Remove to run test")>]
let ``A spare in the last frame gets a one roll bonus that is counted once`` () =
    let rolls = [0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 7; 3; 7]
    let game = rollMany rolls (newGame())
    score game |> should equal <| Some 17
    
[<Fact(Skip = "Remove to run test")>]
let ``A strike earns ten points in frame with a single roll`` () =
    let rolls = [10; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0]
    let game = rollMany rolls (newGame())
    score game |> should equal <| Some 10
    
[<Fact(Skip = "Remove to run test")>]
let ``Points scored in the two rolls after a strike are counted twice as a bonus`` () =
    let rolls = [10; 5; 3; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0]
    let game = rollMany rolls (newGame())
    score game |> should equal <| Some 26
    
[<Fact(Skip = "Remove to run test")>]
let ``Consecutive strikes each get the two roll bonus`` () =
    let rolls = [10; 10; 10; 5; 3; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0]
    let game = rollMany rolls (newGame())
    score game |> should equal <| Some 81
    
[<Fact(Skip = "Remove to run test")>]
let ``A strike in the last frame gets a two roll bonus that is counted once`` () =
    let rolls = [0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 10; 7; 1]
    let game = rollMany rolls (newGame())
    score game |> should equal <| Some 18
    
[<Fact(Skip = "Remove to run test")>]
let ``Rolling a spare with the two roll bonus does not get a bonus roll`` () =
    let rolls = [0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 10; 7; 3]
    let game = rollMany rolls (newGame())
    score game |> should equal <| Some 20
    
[<Fact(Skip = "Remove to run test")>]
let ``Strikes with the two roll bonus do not get bonus rolls`` () =
    let rolls = [0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 10; 10; 10]
    let game = rollMany rolls (newGame())
    score game |> should equal <| Some 30
    
[<Fact(Skip = "Remove to run test")>]
let ``A strike with the one roll bonus after a spare in the last frame does not get a bonus`` () =
    let rolls = [0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 7; 3; 10]
    let game = rollMany rolls (newGame())
    score game |> should equal <| Some 20
    
[<Fact(Skip = "Remove to run test")>]
let ``All strikes is a perfect game`` () =
    let rolls = [10; 10; 10; 10; 10; 10; 10; 10; 10; 10; 10; 10]
    let game = rollMany rolls (newGame())
    score game |> should equal <| Some 300
    
[<Fact(Skip = "Remove to run test")>]
let ``Rolls can not score negative points`` () =
    let rolls = [-1; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0]
    let game = rollMany rolls (newGame())
    score game |> should equal None
    
[<Fact(Skip = "Remove to run test")>]
let ``A roll can not score more than 10 points`` () =
    let rolls = [11; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0]
    let game = rollMany rolls (newGame())
    score game |> should equal None
    
[<Fact(Skip = "Remove to run test")>]
let ``Two rolls in a frame can not score more than 10 points`` () =
    let rolls = [5; 6; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0]
    let game = rollMany rolls (newGame())
    score game |> should equal None
    
[<Fact(Skip = "Remove to run test")>]
let ``Two bonus rolls after a strike in the last frame can not score more than 10 points`` () =
    let rolls = [0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 10; 5; 6]
    let game = rollMany rolls (newGame())
    score game |> should equal None
    
[<Fact(Skip = "Remove to run test")>]
let ``An unstarted game can not be scored`` () =
    let rolls = []
    let game = rollMany rolls (newGame())
    score game |> should equal None
    
[<Fact(Skip = "Remove to run test")>]
let ``An incomplete game can not be scored`` () =
    let rolls = [0; 0]
    let game = rollMany rolls (newGame())
    score game |> should equal None
    
[<Fact(Skip = "Remove to run test")>]
let ``A game with more than ten frames can not be scored`` () =
    let rolls = [0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0]
    let game = rollMany rolls (newGame())
    score game |> should equal None
    
[<Fact(Skip = "Remove to run test")>]
let ``Bonus rolls for a strike in the last frame must be rolled before score can be calculated`` () =
    let rolls = [0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 10]
    let game = rollMany rolls (newGame())
    score game |> should equal None
    
[<Fact(Skip = "Remove to run test")>]
let ``Both bonus rolls for a strike in the last frame must be rolled before score can be calculated`` () =
    let rolls = [0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 10; 10]
    let game = rollMany rolls (newGame())
    score game |> should equal None
    
[<Fact(Skip = "Remove to run test")>]
let ``Bonus roll for a spare in the last frame must be rolled before score can be calculated`` () =
    let rolls = [0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 7; 3]
    let game = rollMany rolls (newGame())
    score game |> should equal None