-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathTaskSeq.Filter.Tests.fs
More file actions
76 lines (62 loc) · 2.35 KB
/
TaskSeq.Filter.Tests.fs
File metadata and controls
76 lines (62 loc) · 2.35 KB
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
module TaskSeq.Tests.Filter
open System
open Xunit
open FsUnit.Xunit
open FSharp.Control
//
// TaskSeq.filter
// TaskSeq.filterAsync
//
module EmptySeq =
[<Fact>]
let ``Null source is invalid`` () =
assertNullArg
<| fun () -> TaskSeq.filter (fun _ -> false) null
assertNullArg
<| fun () -> TaskSeq.filterAsync (fun _ -> Task.fromResult false) null
[<Theory; ClassData(typeof<TestEmptyVariants>)>]
let ``TaskSeq-filter has no effect`` variant =
Gen.getEmptyVariant variant
|> TaskSeq.filter ((=) 12)
|> TaskSeq.toListAsync
|> Task.map (List.isEmpty >> should be True)
[<Theory; ClassData(typeof<TestEmptyVariants>)>]
let ``TaskSeq-filterAsync has no effect`` variant =
Gen.getEmptyVariant variant
|> TaskSeq.filterAsync (fun x -> task { return x = 12 })
|> TaskSeq.toListAsync
|> Task.map (List.isEmpty >> should be True)
module Immutable =
[<Theory; ClassData(typeof<TestImmTaskSeq>)>]
let ``TaskSeq-filter filters correctly`` variant =
Gen.getSeqImmutable variant
|> TaskSeq.filter ((<=) 5) // greater than
|> TaskSeq.map char
|> TaskSeq.map ((+) '@')
|> TaskSeq.toArrayAsync
|> Task.map (String >> should equal "EFGHIJ")
[<Theory; ClassData(typeof<TestImmTaskSeq>)>]
let ``TaskSeq-filterAsync filters correctly`` variant =
Gen.getSeqImmutable variant
|> TaskSeq.filterAsync (fun x -> task { return x <= 5 })
|> TaskSeq.map char
|> TaskSeq.map ((+) '@')
|> TaskSeq.toArrayAsync
|> Task.map (String >> should equal "ABCDE")
module SideEffects =
[<Theory; ClassData(typeof<TestSideEffectTaskSeq>)>]
let ``TaskSeq-filter filters correctly`` variant =
Gen.getSeqWithSideEffect variant
|> TaskSeq.filter ((<=) 5) // greater than
|> TaskSeq.map char
|> TaskSeq.map ((+) '@')
|> TaskSeq.toArrayAsync
|> Task.map (String >> should equal "EFGHIJ")
[<Theory; ClassData(typeof<TestSideEffectTaskSeq>)>]
let ``TaskSeq-filterAsync filters correctly`` variant =
Gen.getSeqWithSideEffect variant
|> TaskSeq.filterAsync (fun x -> task { return x <= 5 })
|> TaskSeq.map char
|> TaskSeq.map ((+) '@')
|> TaskSeq.toArrayAsync
|> Task.map (String >> should equal "ABCDE")