1- module FSharpy.Tests.Choose
1+ namespace FSharpy.Tests
22
33open System
44open System.Threading .Tasks
@@ -8,50 +8,75 @@ open FsUnit.Xunit
88open FsToolkit.ErrorHandling
99
1010open FSharpy
11+ open Xunit.Abstractions
12+ open System.Reflection
1113
12- [<Fact( Timeout = 10_000 ) >]
13- let ``ZHang timeout test`` () = task {
14- let! empty = Task.Delay 30
15-
16- empty |> should be Null
17- }
18-
19- [<Fact( Timeout = 10_000 ) >]
20- let ``TaskSeq - choose on an empty sequence`` () = task {
21- let! empty =
22- TaskSeq.empty
23- |> TaskSeq.choose ( fun _ -> Some 42 )
24- |> TaskSeq.toListAsync
25-
26- List.isEmpty empty |> should be True
27- }
28-
29- [<Fact( Timeout = 10_000 ) >]
30- let ``TaskSeq - chooseAsync on an empty sequence`` () = task {
31- let! empty =
32- TaskSeq.empty
33- |> TaskSeq.chooseAsync ( fun _ -> task { return Some 42 })
34- |> TaskSeq.toListAsync
35-
36- List.isEmpty empty |> should be True
37- }
38-
39- [<Fact( Timeout = 10_000 ) >]
40- let ``TaskSeq - choose can convert and filter`` () = task {
41- let! alphabet =
42- createDummyTaskSeqWith 50 L< µs> 1000 L< µs> 50
43- |> TaskSeq.choose ( fun number -> if number <= 26 then Some( char number + '@' ) else None)
44- |> TaskSeq.toArrayAsync
45-
46- String alphabet |> should equal " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
47- }
48-
49- [<Fact( Timeout = 10_000 ) >]
50- let ``TaskSeq - chooseAsync can convert and filter`` () = task {
51- let! alphabet =
52- createDummyTaskSeqWith 50 L< µs> 1000 L< µs> 50
53- |> TaskSeq.choose ( fun number -> if number <= 26 then Some( char number + '@' ) else None)
54- |> TaskSeq.toArrayAsync
55-
56- String alphabet |> should equal " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
57- }
14+ [<AutoOpen>]
15+ module Log =
16+ let inline log ( output : ITestOutputHelper ) =
17+ let name = MethodBase.GetCurrentMethod() .Name
18+ output.WriteLine $" Starting test: {name}"
19+
20+
21+ type Choose ( output : ITestOutputHelper ) =
22+
23+ [<Fact( Timeout = 10_000 ) >]
24+ let ``ZHang timeout test`` () =
25+ log output
26+
27+ task {
28+ let! empty = Task.Delay 30
29+ empty |> should be Null
30+ }
31+
32+ [<Fact( Timeout = 10_000 ) >]
33+ let ``TaskSeq - choose on an empty sequence`` () =
34+ log output
35+
36+ task {
37+ let! empty =
38+ TaskSeq.empty
39+ |> TaskSeq.choose ( fun _ -> Some 42 )
40+ |> TaskSeq.toListAsync
41+
42+ List.isEmpty empty |> should be True
43+ }
44+
45+ [<Fact( Timeout = 10_000 ) >]
46+ let ``TaskSeq - chooseAsync on an empty sequence`` () =
47+ log output
48+
49+ task {
50+ let! empty =
51+ TaskSeq.empty
52+ |> TaskSeq.chooseAsync ( fun _ -> task { return Some 42 })
53+ |> TaskSeq.toListAsync
54+
55+ List.isEmpty empty |> should be True
56+ }
57+
58+ [<Fact( Timeout = 10_000 ) >]
59+ let ``TaskSeq - choose can convert and filter`` () =
60+ log output
61+
62+ task {
63+ let! alphabet =
64+ createDummyTaskSeqWith 50 L< µs> 1000 L< µs> 50
65+ |> TaskSeq.choose ( fun number -> if number <= 26 then Some( char number + '@' ) else None)
66+ |> TaskSeq.toArrayAsync
67+
68+ String alphabet |> should equal " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
69+ }
70+
71+ [<Fact( Timeout = 10_000 ) >]
72+ let ``TaskSeq - chooseAsync can convert and filter`` () =
73+ log output
74+
75+ task {
76+ let! alphabet =
77+ createDummyTaskSeqWith 50 L< µs> 1000 L< µs> 50
78+ |> TaskSeq.choose ( fun number -> if number <= 26 then Some( char number + '@' ) else None)
79+ |> TaskSeq.toArrayAsync
80+
81+ String alphabet |> should equal " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
82+ }
0 commit comments