Skip to content

Commit de928fb

Browse files
authored
Merge pull request #218 from fsprojects/refactor-tests
Refactor tests, clarify code
2 parents b66463c + 33a882d commit de928fb

File tree

4 files changed

+34
-59
lines changed

4 files changed

+34
-59
lines changed

src/FSharp.Control.TaskSeq.Test/TaskSeq.Skip.Tests.fs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ open FSharp.Control
1414

1515
exception SideEffectPastEnd of string
1616

17-
[<AutoOpen>]
18-
module With =
19-
/// Turns a sequence of numbers into a string, starting with A for '1'
20-
let verifyAsString expected =
21-
TaskSeq.map char
22-
>> TaskSeq.map ((+) '@')
23-
>> TaskSeq.toArrayAsync
24-
>> Task.map (String >> should equal expected)
25-
2617
module EmptySeq =
2718
[<Theory; ClassData(typeof<TestEmptyVariants>)>]
2819
let ``TaskSeq-skip(0) has no effect on empty input`` variant =
@@ -100,17 +91,17 @@ module Immutable =
10091
do!
10192
Gen.getSeqImmutable variant
10293
|> TaskSeq.skip 0
103-
|> verifyAsString "ABCDEFGHIJ"
94+
|> verifyDigitsAsString "ABCDEFGHIJ"
10495

10596
do!
10697
Gen.getSeqImmutable variant
10798
|> TaskSeq.skip 1
108-
|> verifyAsString "BCDEFGHIJ"
99+
|> verifyDigitsAsString "BCDEFGHIJ"
109100

110101
do!
111102
Gen.getSeqImmutable variant
112103
|> TaskSeq.skip 5
113-
|> verifyAsString "FGHIJ"
104+
|> verifyDigitsAsString "FGHIJ"
114105

115106
do!
116107
Gen.getSeqImmutable variant
@@ -143,17 +134,17 @@ module Immutable =
143134
do!
144135
Gen.getSeqImmutable variant
145136
|> TaskSeq.drop 0
146-
|> verifyAsString "ABCDEFGHIJ"
137+
|> verifyDigitsAsString "ABCDEFGHIJ"
147138

148139
do!
149140
Gen.getSeqImmutable variant
150141
|> TaskSeq.drop 1
151-
|> verifyAsString "BCDEFGHIJ"
142+
|> verifyDigitsAsString "BCDEFGHIJ"
152143

153144
do!
154145
Gen.getSeqImmutable variant
155146
|> TaskSeq.drop 5
156-
|> verifyAsString "FGHIJ"
147+
|> verifyDigitsAsString "FGHIJ"
157148

158149
do!
159150
Gen.getSeqImmutable variant
@@ -176,13 +167,13 @@ module SideEffects =
176167
let ``TaskSeq-skip skips over enough items`` variant =
177168
Gen.getSeqWithSideEffect variant
178169
|> TaskSeq.skip 5
179-
|> verifyAsString "FGHIJ"
170+
|> verifyDigitsAsString "FGHIJ"
180171

181172
[<Theory; ClassData(typeof<TestSideEffectTaskSeq>)>]
182173
let ``TaskSeq-drop skips over enough items`` variant =
183174
Gen.getSeqWithSideEffect variant
184175
|> TaskSeq.drop 5
185-
|> verifyAsString "FGHIJ"
176+
|> verifyDigitsAsString "FGHIJ"
186177

187178
[<Fact>]
188179
let ``TaskSeq-skip prove we do not skip side effects`` () = task {

src/FSharp.Control.TaskSeq.Test/TaskSeq.Take.Tests.fs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ open FSharp.Control
1414

1515
exception SideEffectPastEnd of string
1616

17-
[<AutoOpen>]
18-
module With =
19-
/// Turns a sequence of numbers into a string, starting with A for '1'
20-
let verifyAsString expected =
21-
TaskSeq.map char
22-
>> TaskSeq.map ((+) '@')
23-
>> TaskSeq.toArrayAsync
24-
>> Task.map (String >> should equal expected)
25-
2617
module EmptySeq =
2718
[<Theory; ClassData(typeof<TestEmptyVariants>)>]
2819
let ``TaskSeq-take(0) has no effect on empty input`` variant =
@@ -105,17 +96,17 @@ module Immutable =
10596
do!
10697
Gen.getSeqImmutable variant
10798
|> TaskSeq.take 1
108-
|> verifyAsString "A"
99+
|> verifyDigitsAsString "A"
109100

110101
do!
111102
Gen.getSeqImmutable variant
112103
|> TaskSeq.take 5
113-
|> verifyAsString "ABCDE"
104+
|> verifyDigitsAsString "ABCDE"
114105

115106
do!
116107
Gen.getSeqImmutable variant
117108
|> TaskSeq.take 10
118-
|> verifyAsString "ABCDEFGHIJ"
109+
|> verifyDigitsAsString "ABCDEFGHIJ"
119110
}
120111

121112
[<Theory; ClassData(typeof<TestImmTaskSeq>)>]
@@ -148,41 +139,41 @@ module Immutable =
148139
do!
149140
Gen.getSeqImmutable variant
150141
|> TaskSeq.truncate 1
151-
|> verifyAsString "A"
142+
|> verifyDigitsAsString "A"
152143

153144
do!
154145
Gen.getSeqImmutable variant
155146
|> TaskSeq.truncate 5
156-
|> verifyAsString "ABCDE"
147+
|> verifyDigitsAsString "ABCDE"
157148

158149
do!
159150
Gen.getSeqImmutable variant
160151
|> TaskSeq.truncate 10
161-
|> verifyAsString "ABCDEFGHIJ"
152+
|> verifyDigitsAsString "ABCDEFGHIJ"
162153

163154
do!
164155
Gen.getSeqImmutable variant
165156
|> TaskSeq.truncate 11
166-
|> verifyAsString "ABCDEFGHIJ"
157+
|> verifyDigitsAsString "ABCDEFGHIJ"
167158

168159
do!
169160
Gen.getSeqImmutable variant
170161
|> TaskSeq.truncate 10_000_000
171-
|> verifyAsString "ABCDEFGHIJ"
162+
|> verifyDigitsAsString "ABCDEFGHIJ"
172163
}
173164

174165
module SideEffects =
175166
[<Theory; ClassData(typeof<TestSideEffectTaskSeq>)>]
176167
let ``TaskSeq-take gets enough items`` variant =
177168
Gen.getSeqWithSideEffect variant
178169
|> TaskSeq.take 5
179-
|> verifyAsString "ABCDE"
170+
|> verifyDigitsAsString "ABCDE"
180171

181172
[<Theory; ClassData(typeof<TestSideEffectTaskSeq>)>]
182173
let ``TaskSeq-truncate gets enough items`` variant =
183174
Gen.getSeqWithSideEffect variant
184175
|> TaskSeq.truncate 5
185-
|> verifyAsString "ABCDE"
176+
|> verifyDigitsAsString "ABCDE"
186177

187178
[<Fact>]
188179
let ``TaskSeq-take prove it does not read beyond the last yield`` () = task {
@@ -212,7 +203,7 @@ module SideEffects =
212203
do SideEffectPastEnd "at the end" |> raise // we SHOULD NOT get here
213204
}
214205

215-
items |> TaskSeq.take 3 |> verifyAsString "ABC"
206+
items |> TaskSeq.take 3 |> verifyDigitsAsString "ABC"
216207

217208

218209
[<Fact>]

src/FSharp.Control.TaskSeq.Test/TaskSeq.TakeWhile.Tests.fs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ module With =
2525
| true, false -> TaskSeq.takeWhileInclusive
2626
| true, true -> fun pred -> TaskSeq.takeWhileInclusiveAsync (pred >> Task.fromResult)
2727

28-
/// Turns a sequence of numbers into a string, starting with A for '1'
29-
let verifyAsString expected =
30-
TaskSeq.map char
31-
>> TaskSeq.map ((+) '@')
32-
>> TaskSeq.toArrayAsync
33-
>> Task.map (String >> should equal expected)
34-
3528
/// This is the base condition as one would expect in actual code
3629
let inline cond x = x <> 6
3730

@@ -82,65 +75,65 @@ module Immutable =
8275
do!
8376
Gen.getSeqImmutable variant
8477
|> TaskSeq.takeWhile condWithGuard
85-
|> verifyAsString "ABCDE"
78+
|> verifyDigitsAsString "ABCDE"
8679

8780
do!
8881
Gen.getSeqImmutable variant
8982
|> TaskSeq.takeWhileAsync (fun x -> task { return condWithGuard x })
90-
|> verifyAsString "ABCDE"
83+
|> verifyDigitsAsString "ABCDE"
9184
}
9285

9386
[<Theory; ClassData(typeof<TestImmTaskSeq>)>]
9487
let ``TaskSeq-takeWhile+A does not pick first item when false`` variant = task {
9588
do!
9689
Gen.getSeqImmutable variant
9790
|> TaskSeq.takeWhile ((=) 0)
98-
|> verifyAsString ""
91+
|> verifyDigitsAsString ""
9992

10093
do!
10194
Gen.getSeqImmutable variant
10295
|> TaskSeq.takeWhileAsync ((=) 0 >> Task.fromResult)
103-
|> verifyAsString ""
96+
|> verifyDigitsAsString ""
10497
}
10598

10699
[<Theory; ClassData(typeof<TestImmTaskSeq>)>]
107100
let ``TaskSeq-takeWhileInclusive+A filters correctly`` variant = task {
108101
do!
109102
Gen.getSeqImmutable variant
110103
|> TaskSeq.takeWhileInclusive condWithGuard
111-
|> verifyAsString "ABCDEF"
104+
|> verifyDigitsAsString "ABCDEF"
112105

113106
do!
114107
Gen.getSeqImmutable variant
115108
|> TaskSeq.takeWhileInclusiveAsync (fun x -> task { return condWithGuard x })
116-
|> verifyAsString "ABCDEF"
109+
|> verifyDigitsAsString "ABCDEF"
117110
}
118111

119112
[<Theory; ClassData(typeof<TestImmTaskSeq>)>]
120113
let ``TaskSeq-takeWhileInclusive+A always pick at least the first item`` variant = task {
121114
do!
122115
Gen.getSeqImmutable variant
123116
|> TaskSeq.takeWhileInclusive ((=) 0)
124-
|> verifyAsString "A"
117+
|> verifyDigitsAsString "A"
125118

126119
do!
127120
Gen.getSeqImmutable variant
128121
|> TaskSeq.takeWhileInclusiveAsync ((=) 0 >> Task.fromResult)
129-
|> verifyAsString "A"
122+
|> verifyDigitsAsString "A"
130123
}
131124

132125
module SideEffects =
133126
[<Theory; ClassData(typeof<TestSideEffectTaskSeq>)>]
134127
let ``TaskSeq-takeWhile filters correctly`` variant =
135128
Gen.getSeqWithSideEffect variant
136129
|> TaskSeq.takeWhile condWithGuard
137-
|> verifyAsString "ABCDE"
130+
|> verifyDigitsAsString "ABCDE"
138131

139132
[<Theory; ClassData(typeof<TestSideEffectTaskSeq>)>]
140133
let ``TaskSeq-takeWhileAsync filters correctly`` variant =
141134
Gen.getSeqWithSideEffect variant
142135
|> TaskSeq.takeWhileAsync (fun x -> task { return condWithGuard x })
143-
|> verifyAsString "ABCDE"
136+
|> verifyDigitsAsString "ABCDE"
144137

145138
[<Theory>]
146139
[<InlineData(false, false)>]
@@ -246,7 +239,7 @@ module Other =
246239
[ 1; 2; 2; 3; 3; 2; 1 ]
247240
|> TaskSeq.ofSeq
248241
|> functionToTest (fun x -> x <= 2)
249-
|> verifyAsString (if inclusive then "ABBC" else "ABB")
242+
|> verifyDigitsAsString (if inclusive then "ABBC" else "ABB")
250243

251244
[<Theory>]
252245
[<InlineData(false, false)>]
@@ -262,4 +255,4 @@ module Other =
262255
}
263256
|> TaskSeq.ofSeq
264257
|> functionToTest (fun x -> x <= 2)
265-
|> verifyAsString (if inclusive then "ABBC" else "ABB")
258+
|> verifyDigitsAsString (if inclusive then "ABBC" else "ABB")

src/FSharp.Control.TaskSeq.Test/TestUtils.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ module TestUtils =
141141
|> TaskSeq.toArrayAsync
142142
|> Task.map (should equal [| 1..10 |])
143143

144-
/// Turns a sequence of numbers into a string, starting with A for '1'
144+
/// Turns a sequence of integers into a string, starting with A for '1', Z for 26 etc.
145145
let verifyDigitsAsString expected =
146-
TaskSeq.map char
147-
>> TaskSeq.map ((+) '@')
146+
TaskSeq.map (char: int -> char)
147+
>> TaskSeq.map ((+) '@') // turns int(1) into char('A') etc
148148
>> TaskSeq.toArrayAsync
149149
>> Task.map (String >> should equal expected)
150150

0 commit comments

Comments
 (0)