diff --git a/src/FSharpy.TaskSeq.Test/FSharpy.TaskSeq.Test.fsproj b/src/FSharpy.TaskSeq.Test/FSharpy.TaskSeq.Test.fsproj index e46e9dc9..133bb357 100644 --- a/src/FSharpy.TaskSeq.Test/FSharpy.TaskSeq.Test.fsproj +++ b/src/FSharpy.TaskSeq.Test/FSharpy.TaskSeq.Test.fsproj @@ -1,4 +1,4 @@ - + net6.0 @@ -10,14 +10,6 @@ - - - - - - - - diff --git a/src/FSharpy.TaskSeq.Test/TaskSeq.Choose.Tests.fs b/src/FSharpy.TaskSeq.Test/TaskSeq.Choose.Tests.fs deleted file mode 100644 index bcd08c7d..00000000 --- a/src/FSharpy.TaskSeq.Test/TaskSeq.Choose.Tests.fs +++ /dev/null @@ -1,49 +0,0 @@ -module FSharpy.Tests.Choose - -open System -open Xunit -open FsUnit.Xunit -open FsToolkit.ErrorHandling - -open FSharpy - - -[] -let ``TaskSeq-choose on an empty sequence`` () = task { - let! empty = - TaskSeq.empty - |> TaskSeq.choose (fun _ -> Some 42) - |> TaskSeq.toListAsync - - List.isEmpty empty |> should be True -} - -[] -let ``TaskSeq-chooseAsync on an empty sequence`` () = task { - let! empty = - TaskSeq.empty - |> TaskSeq.chooseAsync (fun _ -> task { return Some 42 }) - |> TaskSeq.toListAsync - - List.isEmpty empty |> should be True -} - -[] -let ``TaskSeq-choose can convert and filter`` () = task { - let! alphabet = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.choose (fun number -> if number <= 26 then Some(char number + '@') else None) - |> TaskSeq.toArrayAsync - - String alphabet |> should equal "ABCDEFGHIJKLMNOPQRSTUVWXYZ" -} - -[] -let ``TaskSeq-chooseAsync can convert and filter`` () = task { - let! alphabet = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.choose (fun number -> if number <= 26 then Some(char number + '@') else None) - |> TaskSeq.toArrayAsync - - String alphabet |> should equal "ABCDEFGHIJKLMNOPQRSTUVWXYZ" -} diff --git a/src/FSharpy.TaskSeq.Test/TaskSeq.Collect.Tests.fs b/src/FSharpy.TaskSeq.Test/TaskSeq.Collect.Tests.fs deleted file mode 100644 index 3d405e2d..00000000 --- a/src/FSharpy.TaskSeq.Test/TaskSeq.Collect.Tests.fs +++ /dev/null @@ -1,65 +0,0 @@ -module FSharpy.Tests.Collect - -open Xunit -open FsUnit.Xunit -open FsToolkit.ErrorHandling - -open FSharpy - -[] -let ``TaskSeq-collect operates in correct order`` () = task { - let! sq = - createDummyTaskSeq 10 - |> TaskSeq.collect (fun item -> taskSeq { - yield char (item + 64) - yield char (item + 65) - }) - |> TaskSeq.toSeqCachedAsync - - sq - |> Seq.map string - |> String.concat "" - |> should equal "ABBCCDDEEFFGGHHIIJJK" -} - -[] -let ``TaskSeq-collectSeq operates in correct order`` () = task { - let! sq = - createDummyTaskSeq 10 - |> TaskSeq.collectSeq (fun item -> seq { - yield char (item + 64) - yield char (item + 65) - }) - |> TaskSeq.toSeqCachedAsync - - sq - |> Seq.map string - |> String.concat "" - |> should equal "ABBCCDDEEFFGGHHIIJJK" -} - -[] -let ``TaskSeq-collect with empty task sequences`` () = task { - let! sq = - createDummyTaskSeq 10 - |> TaskSeq.collect (fun _ -> TaskSeq.ofSeq Seq.empty) - |> TaskSeq.toSeqCachedAsync - - Seq.isEmpty sq |> should be True -} - -[] -let ``TaskSeq-collectSeq with empty sequences`` () = task { - let! sq = - createDummyTaskSeq 10 - |> TaskSeq.collectSeq (fun _ -> Seq.empty) - |> TaskSeq.toSeqCachedAsync - - Seq.isEmpty sq |> should be True -} - -[] -let ``TaskSeq-empty is empty`` () = task { - let! sq = TaskSeq.empty |> TaskSeq.toSeqCachedAsync - Seq.isEmpty sq |> should be True -} diff --git a/src/FSharpy.TaskSeq.Test/TaskSeq.Filter.Tests.fs b/src/FSharpy.TaskSeq.Test/TaskSeq.Filter.Tests.fs deleted file mode 100644 index 79c413cd..00000000 --- a/src/FSharpy.TaskSeq.Test/TaskSeq.Filter.Tests.fs +++ /dev/null @@ -1,53 +0,0 @@ -module FSharpy.Tests.Filter - -open System -open Xunit -open FsUnit.Xunit -open FsToolkit.ErrorHandling - -open FSharpy - -[] -let ``TaskSeq-filter on an empty sequence`` () = task { - let! empty = - TaskSeq.empty - |> TaskSeq.filter ((=) 12) - |> TaskSeq.toListAsync - - List.isEmpty empty |> should be True -} - -[] -let ``TaskSeq-filterAsync on an empty sequence`` () = task { - let! empty = - TaskSeq.empty - |> TaskSeq.filterAsync (fun x -> task { return x = 12 }) - |> TaskSeq.toListAsync - - List.isEmpty empty |> should be True -} - -[] -let ``TaskSeq-filter filters correctly`` () = task { - let! alphabet = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.filter ((<=) 26) // lambda of '>' etc inverts order of args, so this means 'greater than' - |> TaskSeq.map char - |> TaskSeq.map ((+) '@') - |> TaskSeq.toArrayAsync - - // we filtered all digits above-or-equal-to 26 - String alphabet |> should equal "Z[\]^_`abcdefghijklmnopqr" -} - -[] -let ``TaskSeq-filterAsync filters correctly`` () = task { - let! alphabet = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.filterAsync (fun x -> task { return x <= 26 }) - |> TaskSeq.map char - |> TaskSeq.map ((+) '@') - |> TaskSeq.toArrayAsync - - String alphabet |> should equal "ABCDEFGHIJKLMNOPQRSTUVWXYZ" -} diff --git a/src/FSharpy.TaskSeq.Test/TaskSeq.Find.Tests.fs b/src/FSharpy.TaskSeq.Test/TaskSeq.Find.Tests.fs deleted file mode 100644 index dcf58b28..00000000 --- a/src/FSharpy.TaskSeq.Test/TaskSeq.Find.Tests.fs +++ /dev/null @@ -1,247 +0,0 @@ -module FSharpy.Tests.Find - -open Xunit -open FsUnit.Xunit -open FsToolkit.ErrorHandling - -open FSharpy -open System.Collections.Generic - -// -// TaskSeq.find -// TaskSeq.findAsync -// the tryXXX versions are at the bottom half -// - -[] -let ``TaskSeq-find on an empty sequence raises KeyNotFoundException`` () = task { - fun () -> TaskSeq.empty |> TaskSeq.find ((=) 12) |> Task.ignore - |> should throwAsyncExact typeof -} - -[] -let ``TaskSeq-find on an empty sequence raises KeyNotFoundException - variant`` () = task { - fun () -> taskSeq { do () } |> TaskSeq.find ((=) 12) |> Task.ignore - |> should throwAsyncExact typeof -} - -[] -let ``TaskSeq-findAsync on an empty sequence raises KeyNotFoundException`` () = task { - fun () -> - TaskSeq.empty - |> TaskSeq.findAsync (fun x -> task { return x = 12 }) - |> Task.ignore - |> should throwAsyncExact typeof -} - -[] -let ``TaskSeq-find sad path raises KeyNotFoundException`` () = task { - fun () -> - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.find ((=) 0) // dummy tasks sequence starts at 1 - |> Task.ignore - - |> should throwAsyncExact typeof -} - -[] -let ``TaskSeq-findAsync sad path raises KeyNotFoundException`` () = task { - fun () -> - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.findAsync (fun x -> task { return x = 0 }) // dummy tasks sequence starts at 1 - |> Task.ignore - - |> should throwAsyncExact typeof -} - -[] -let ``TaskSeq-find sad path raises KeyNotFoundException variant`` () = task { - fun () -> - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.find ((=) 51) // dummy tasks sequence ends at 50 - |> Task.ignore - - |> should throwAsyncExact typeof -} - -[] -let ``TaskSeq-findAsync sad path raises KeyNotFoundException variant`` () = task { - fun () -> - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.findAsync (fun x -> task { return x = 51 }) // dummy tasks sequence ends at 50 - |> Task.ignore - - |> should throwAsyncExact typeof -} - - -[] -let ``TaskSeq-find happy path middle of seq`` () = task { - let! twentyFive = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.find (fun x -> x < 26 && x > 24) - - twentyFive |> should equal 25 -} - -[] -let ``TaskSeq-findAsync happy path middle of seq`` () = task { - let! twentyFive = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.findAsync (fun x -> task { return x < 26 && x > 24 }) - - twentyFive |> should equal 25 -} - -[] -let ``TaskSeq-find happy path first item of seq`` () = task { - let! first = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.find ((=) 1) // dummy tasks seq starts at 1 - - first |> should equal 1 -} - -[] -let ``TaskSeq-findAsync happy path first item of seq`` () = task { - let! first = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.findAsync (fun x -> task { return x = 1 }) // dummy tasks seq starts at 1 - - first |> should equal 1 -} - -[] -let ``TaskSeq-find happy path last item of seq`` () = task { - let! last = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.find ((=) 50) // dummy tasks seq ends at 50 - - last |> should equal 50 -} - -[] -let ``TaskSeq-findAsync happy path last item of seq`` () = task { - let! last = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.findAsync (fun x -> task { return x = 50 }) // dummy tasks seq ends at 50 - - last |> should equal 50 -} - -// -// TaskSeq.tryFind -// TaskSeq.tryFindAsync -// - -[] -let ``TaskSeq-tryFind on an empty sequence returns None`` () = task { - let! nothing = TaskSeq.empty |> TaskSeq.tryFind ((=) 12) - nothing |> should be None' -} - -[] -let ``TaskSeq-tryFindAsync on an empty sequence returns None`` () = task { - let! nothing = - TaskSeq.empty - |> TaskSeq.tryFindAsync (fun x -> task { return x = 12 }) - - nothing |> should be None' -} - -[] -let ``TaskSeq-tryFind sad path returns None`` () = task { - let! nothing = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.tryFind ((=) 0) // dummy tasks sequence starts at 1 - - nothing |> should be None' -} - -[] -let ``TaskSeq-tryFindAsync sad path return None`` () = task { - let! nothing = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.tryFindAsync (fun x -> task { return x = 0 }) // dummy tasks sequence starts at 1 - - nothing |> should be None' -} - -[] -let ``TaskSeq-tryFind sad path returns None variant`` () = task { - let! nothing = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.tryFind ((<=) 51) // dummy tasks sequence ends at 50 (inverted sign in lambda!) - - nothing |> should be None' -} - -[] -let ``TaskSeq-tryFindAsync sad path return None - variant`` () = task { - let! nothing = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.tryFindAsync (fun x -> task { return x >= 51 }) // dummy tasks sequence ends at 50 - - nothing |> should be None' -} - - -[] -let ``TaskSeq-tryFind happy path middle of seq`` () = task { - let! twentyFive = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.tryFind (fun x -> x < 26 && x > 24) - - twentyFive |> should be Some' - twentyFive |> should equal (Some 25) -} - -[] -let ``TaskSeq-tryFindAsync happy path middle of seq`` () = task { - let! twentyFive = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.tryFindAsync (fun x -> task { return x < 26 && x > 24 }) - - twentyFive |> should be Some' - twentyFive |> should equal (Some 25) -} - -[] -let ``TaskSeq-tryFind happy path first item of seq`` () = task { - let! first = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.tryFind ((=) 1) // dummy tasks seq starts at 1 - - first |> should be Some' - first |> should equal (Some 1) -} - -[] -let ``TaskSeq-tryFindAsync happy path first item of seq`` () = task { - let! first = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.tryFindAsync (fun x -> task { return x = 1 }) // dummy tasks seq starts at 1 - - first |> should be Some' - first |> should equal (Some 1) -} - -[] -let ``TaskSeq-tryFind happy path last item of seq`` () = task { - let! last = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.tryFind ((=) 50) // dummy tasks seq ends at 50 - - last |> should be Some' - last |> should equal (Some 50) -} - -[] -let ``TaskSeq-tryFindAsync happy path last item of seq`` () = task { - let! last = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.tryFindAsync (fun x -> task { return x = 50 }) // dummy tasks seq ends at 50 - - last |> should be Some' - last |> should equal (Some 50) -} diff --git a/src/FSharpy.TaskSeq.Test/TaskSeq.Fold.Tests.fs b/src/FSharpy.TaskSeq.Test/TaskSeq.Fold.Tests.fs deleted file mode 100644 index fa6e310b..00000000 --- a/src/FSharpy.TaskSeq.Test/TaskSeq.Fold.Tests.fs +++ /dev/null @@ -1,49 +0,0 @@ -module FSharpy.Tests.Fold - -open System.Text -open Xunit -open FsUnit.Xunit -open FsToolkit.ErrorHandling - -open FSharpy - - -[] -let ``TaskSeq-fold folds with every item`` () = task { - let! alphabet = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 26 - |> TaskSeq.fold (fun (state: StringBuilder) item -> state.Append(char item + '@')) (StringBuilder()) - - alphabet.ToString() - |> should equal "ABCDEFGHIJKLMNOPQRSTUVWXYZ" -} - -[] -let ``TaskSeq-foldAsync folds with every item`` () = task { - let! alphabet = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 26 - |> TaskSeq.foldAsync - (fun (state: StringBuilder) item -> task { return state.Append(char item + '@') }) - (StringBuilder()) - - alphabet.ToString() - |> should equal "ABCDEFGHIJKLMNOPQRSTUVWXYZ" -} - -[] -let ``TaskSeq-fold takes state on empty IAsyncEnumberable`` () = task { - let! empty = - TaskSeq.empty - |> TaskSeq.fold (fun _ item -> char (item + 64)) '_' - - empty |> should equal '_' -} - -[] -let ``TaskSeq-foldAsync takes state on empty IAsyncEnumerable`` () = task { - let! alphabet = - TaskSeq.empty - |> TaskSeq.foldAsync (fun _ item -> task { return char (item + 64) }) '_' - - alphabet |> should equal '_' -} diff --git a/src/FSharpy.TaskSeq.Test/TaskSeq.Head.Tests.fs b/src/FSharpy.TaskSeq.Test/TaskSeq.Head.Tests.fs deleted file mode 100644 index f11ad2ac..00000000 --- a/src/FSharpy.TaskSeq.Test/TaskSeq.Head.Tests.fs +++ /dev/null @@ -1,57 +0,0 @@ -module FSharpy.Tests.Head - -open System -open Xunit -open FsUnit.Xunit -open FsToolkit.ErrorHandling - -open FSharpy - - -[] -let ``TaskSeq-head throws on empty sequences`` () = task { - fun () -> TaskSeq.empty |> TaskSeq.head |> Task.ignore - |> should throwAsyncExact typeof -} - -[] -let ``TaskSeq-head throws on empty sequences - variant`` () = task { - fun () -> taskSeq { do () } |> TaskSeq.head |> Task.ignore - |> should throwAsyncExact typeof -} - -[] -let ``TaskSeq-tryHead returns None on empty sequences`` () = task { - let! nothing = TaskSeq.empty |> TaskSeq.tryHead - nothing |> should be None' -} - -[] -let ``TaskSeq-head gets the first item in a longer sequence`` () = task { - let! head = createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 |> TaskSeq.head - - head |> should equal 1 -} - -[] -let ``TaskSeq-head gets the only item in a singleton sequence`` () = task { - let! head = taskSeq { yield 10 } |> TaskSeq.head - head |> should equal 10 -} - -[] -let ``TaskSeq-tryHead gets the first item in a longer sequence`` () = task { - let! head = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.tryHead - - head |> should be Some' - head |> should equal (Some 1) -} - -[] -let ``TaskSeq-tryHead gets the only item in a singleton sequence`` () = task { - let! head = taskSeq { yield 10 } |> TaskSeq.tryHead - head |> should be Some' - head |> should equal (Some 10) -} diff --git a/src/FSharpy.TaskSeq.Test/TaskSeq.Item.Tests.fs b/src/FSharpy.TaskSeq.Test/TaskSeq.Item.Tests.fs deleted file mode 100644 index 85c058fc..00000000 --- a/src/FSharpy.TaskSeq.Test/TaskSeq.Item.Tests.fs +++ /dev/null @@ -1,243 +0,0 @@ -module FSharpy.Tests.Item - -open System -open Xunit -open FsUnit.Xunit -open FsToolkit.ErrorHandling - -open FSharpy - - -[] -let ``TaskSeq-item throws on empty sequences`` () = task { - fun () -> TaskSeq.empty |> TaskSeq.item 0 |> Task.ignore - |> should throwAsyncExact typeof -} - -[] -let ``TaskSeq-item throws on empty sequence - variant`` () = task { - fun () -> taskSeq { do () } |> TaskSeq.item 50000 |> Task.ignore - |> should throwAsyncExact typeof -} - -[] -let ``TaskSeq-item throws when not found`` () = task { - fun () -> - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.item 51 - |> Task.ignore - |> should throwAsyncExact typeof -} - -[] -let ``TaskSeq-item throws when not found - variant`` () = task { - fun () -> - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.item Int32.MaxValue - |> Task.ignore - |> should throwAsyncExact typeof -} - -[] -let ``TaskSeq-item throws when accessing 2nd item in singleton sequence`` () = task { - fun () -> taskSeq { yield 10 } |> TaskSeq.item 1 |> Task.ignore // zero-based! - |> should throwAsyncExact typeof -} - -[] -let ``TaskSeq-item always throws with negative values`` () = task { - let make50 () = createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - - fun () -> make50 () |> TaskSeq.item -1 |> Task.ignore - |> should throwAsyncExact typeof - - fun () -> make50 () |> TaskSeq.item -10000 |> Task.ignore - |> should throwAsyncExact typeof - - fun () -> make50 () |> TaskSeq.item Int32.MinValue |> Task.ignore - |> should throwAsyncExact typeof - - fun () -> TaskSeq.empty |> TaskSeq.item -1 |> Task.ignore - |> should throwAsyncExact typeof - - fun () -> TaskSeq.empty |> TaskSeq.item -10000 |> Task.ignore - |> should throwAsyncExact typeof - - fun () -> - TaskSeq.empty - |> TaskSeq.item Int32.MinValue - |> Task.ignore - |> should throwAsyncExact typeof -} - -[] -let ``TaskSeq-tryItem returns None on empty sequences`` () = task { - let! nothing = TaskSeq.empty |> TaskSeq.tryItem 0 - nothing |> should be None' -} - -[] -let ``TaskSeq-tryItem returns None on empty sequence - variant`` () = task { - let! nothing = taskSeq { do () } |> TaskSeq.tryItem 50000 - nothing |> should be None' -} - -[] -let ``TaskSeq-tryItem returns None when not found`` () = task { - let! nothing = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.tryItem 50 // zero-based index, so a sequence of 50 items has its last item at index 49 - - nothing |> should be None' -} - -[] -let ``TaskSeq-tryItem returns None when not found - variant`` () = task { - let! nothing = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.tryItem Int32.MaxValue - - nothing |> should be None' -} - -[] -let ``TaskSeq-tryItem returns None when accessing 2nd item in singleton sequence`` () = task { - let! nothing = taskSeq { yield 10 } |> TaskSeq.tryItem 1 // zero-based! - nothing |> should be None' -} - -[] -let ``TaskSeq-tryItem returns None throws with negative values`` () = task { - let make50 () = createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - - let! nothing = make50 () |> TaskSeq.tryItem -1 - nothing |> should be None' - - let! nothing = make50 () |> TaskSeq.tryItem -10000 - nothing |> should be None' - - let! nothing = make50 () |> TaskSeq.tryItem Int32.MinValue - nothing |> should be None' - - let! nothing = TaskSeq.empty |> TaskSeq.tryItem -1 - nothing |> should be None' - - let! nothing = TaskSeq.empty |> TaskSeq.tryItem -10000 - nothing |> should be None' - - let! nothing = TaskSeq.empty |> TaskSeq.tryItem Int32.MinValue - nothing |> should be None' -} - -[] -let ``TaskSeq-item can get the first item in a longer sequence`` () = task { - let! head = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.item 0 - - head |> should equal 1 -} - -[] -let ``TaskSeq-item can get the last item in a longer sequence`` () = task { - let! head = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.item 49 - - head |> should equal 50 -} - -[] -let ``TaskSeq-item can get the first item in a singleton sequence`` () = task { - let! head = taskSeq { yield 10 } |> TaskSeq.item 0 // zero-based index! - head |> should equal 10 -} - -[] -let ``TaskSeq-tryItem can get the first item in a longer sequence`` () = task { - let! head = - createDummyTaskSeqWith 50L<µs> 1000L<µs> 50 - |> TaskSeq.tryItem 0 // zero-based! - - head |> should be Some' - head |> should equal (Some 1) -} - -[] -let ``TaskSeq-tryItem in a very long sequence (5_000 items - slow variant)`` () = task { - let! head = createDummyDirectTaskSeq 5_001 |> TaskSeq.tryItem 5_000 // zero-based! - - head |> should be Some' - head |> should equal (Some 5_001) -} - -[] -let ``TaskSeq-tryItem in a very long sequence (50_000 items - slow variant)`` () = task { - let! head = createDummyDirectTaskSeq 50_001 |> TaskSeq.tryItem 50_000 // zero-based! - - head |> should be Some' - head |> should equal (Some 50_001) -} - -[] -let ``TaskSeq-tryItem in a very long sequence (50_000 items - fast variant)`` () = task { - let! head = - // using taskSeq instead of the delayed-task approach above, which creates an extra closure for each - // task, we can really see the speed of the 'taskSeq' CE!! This is - taskSeq { - for i in [ 0..50_000 ] do - yield i - } - |> TaskSeq.tryItem 50_000 // zero-based! - - head |> should be Some' - head |> should equal (Some 50_000) -} - -[] -let ``TaskSeq-tryItem in a very long sequence (50_000 items - using sync Seq)`` () = task { - // this test is just for smoke-test perf comparison with TaskSeq above - let head = - seq { - for i in [ 0..50_000 ] do - yield i - } - |> Seq.tryItem 50_000 // zero-based! - - head |> should be Some' - head |> should equal (Some 50_000) -} - -[] -let ``TaskSeq-tryItem in a very long sequence (500_000 items - fast variant)`` () = task { - let! head = - taskSeq { - for i in [ 0..500_000 ] do - yield i - } - |> TaskSeq.tryItem 500_000 // zero-based! - - head |> should be Some' - head |> should equal (Some 500_000) -} - -[] -let ``TaskSeq-tryItem in a very long sequence (500_000 items - using sync Seq)`` () = task { - // this test is just for smoke-test perf comparison with TaskSeq above - let head = - seq { - for i in [ 0..500_000 ] do - yield i - } - |> Seq.tryItem 500_000 // zero-based! - - head |> should be Some' - head |> should equal (Some 500_000) -} - -[] -let ``TaskSeq-tryItem gets the first item in a singleton sequence`` () = task { - let! head = taskSeq { yield 10 } |> TaskSeq.tryItem 0 // zero-based! - head |> should be Some' - head |> should equal (Some 10) -} diff --git a/src/FSharpy.TaskSeq.Test/TaskSeq.Iter.Tests.fs b/src/FSharpy.TaskSeq.Test/TaskSeq.Iter.Tests.fs deleted file mode 100644 index f8418b21..00000000 --- a/src/FSharpy.TaskSeq.Test/TaskSeq.Iter.Tests.fs +++ /dev/null @@ -1,48 +0,0 @@ -module FSharpy.Tests.Iter - -open Xunit -open FsUnit.Xunit -open FsToolkit.ErrorHandling - -open FSharpy - - -[] -let ``TaskSeq-iteri should go over all items`` () = task { - let tq = createDummyTaskSeq 10 - let mutable sum = 0 - do! tq |> TaskSeq.iteri (fun i _ -> sum <- sum + i) - sum |> should equal 45 // index starts at 0 -} - -[] -let ``TaskSeq-iter should go over all items`` () = task { - let tq = createDummyTaskSeq 10 - let mutable sum = 0 - do! tq |> TaskSeq.iter (fun item -> sum <- sum + item) - sum |> should equal 55 // task-dummies started at 1 -} - -[] -let ``TaskSeq-iteriAsync should go over all items`` () = task { - let tq = createDummyTaskSeq 10 - let mutable sum = 0 - - do! - tq - |> TaskSeq.iteriAsync (fun i _ -> task { sum <- sum + i }) - - sum |> should equal 45 // index starts at 0 -} - -[] -let ``TaskSeq-iterAsync should go over all items`` () = task { - let tq = createDummyTaskSeq 10 - let mutable sum = 0 - - do! - tq - |> TaskSeq.iterAsync (fun item -> task { sum <- sum + item }) - - sum |> should equal 55 // task-dummies started at 1 -}