diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 65c1d5e..d96928c 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -2,6 +2,7 @@ * Test coverage: Added tests for previously-untested public API functions `AsyncSeq.tryFirst`, `AsyncSeq.firstOrDefault`, `AsyncSeq.zipWithParallel`, `AsyncSeq.combineLatestWithAsync`, and `AsyncSeq.toObservable`. No functional changes. * Fixed Fable CI build: `Microsoft.Bcl.AsyncInterfaces` was pinned to a specific version (`10.0.7`) that was older than the version resolved transitively via `System.Threading.Channels`, causing a `NU1605` package downgrade error that made Fable's project cracker fail during `dotnet fable`. The reference now uses `Version="*"` (matching `System.Threading.Channels`) so both resolve consistently. (#334) +* Tests: Added comprehensive tests for `AsyncSeq.zapp`, `AsyncSeq.zappAsync`, and `AsyncSeq.compareWithAsync`, which previously had no dedicated test coverage. ### 4.17.0 diff --git a/tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs b/tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs index c3738f3..03f8dc0 100644 --- a/tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs +++ b/tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs @@ -5178,3 +5178,102 @@ let ``AsyncSeq.toObservable on empty sequence emits nothing`` () = use _sub = (AsyncSeq.toObservable (AsyncSeq.empty)).Subscribe(observer) Assert.IsTrue(completedEvent.Wait(2000)) Assert.AreEqual([||], received.ToArray()) + +// ===== zapp / zappAsync ===== + +[] +let ``AsyncSeq.zapp applies functions to corresponding elements`` () = + let fs = asyncSeq { yield (fun x -> x + 10); yield (fun x -> x * 2); yield (fun x -> x - 1) } + let vs = asyncSeq { yield 1; yield 2; yield 3 } + let result = AsyncSeq.zapp fs vs |> AsyncSeq.toArrayAsync |> Async.RunSynchronously + Assert.AreEqual([| 11; 4; 2 |], result) + +[] +let ``AsyncSeq.zapp stops when functions run out`` () = + let fs = asyncSeq { yield (fun x -> x + 1); yield (fun x -> x + 2) } + let vs = asyncSeq { yield 10; yield 20; yield 30 } + let result = AsyncSeq.zapp fs vs |> AsyncSeq.toArrayAsync |> Async.RunSynchronously + Assert.AreEqual([| 11; 22 |], result) + +[] +let ``AsyncSeq.zapp stops when values run out`` () = + let fs = asyncSeq { yield (fun x -> x + 1); yield (fun x -> x + 2); yield (fun x -> x + 3) } + let vs = asyncSeq { yield 5 } + let result = AsyncSeq.zapp fs vs |> AsyncSeq.toArrayAsync |> Async.RunSynchronously + Assert.AreEqual([| 6 |], result) + +[] +let ``AsyncSeq.zapp on empty functions returns empty`` () = + let fs = AsyncSeq.empty int> + let vs = asyncSeq { yield 1; yield 2; yield 3 } + let result = AsyncSeq.zapp fs vs |> AsyncSeq.toArrayAsync |> Async.RunSynchronously + Assert.AreEqual([||], result) + +[] +let ``AsyncSeq.zappAsync applies async functions to corresponding elements`` () = + let fs = asyncSeq { + yield (fun x -> async { return x + 10 }) + yield (fun x -> async { return x * 3 }) + } + let vs = asyncSeq { yield 5; yield 4 } + let result = AsyncSeq.zappAsync fs vs |> AsyncSeq.toArrayAsync |> Async.RunSynchronously + Assert.AreEqual([| 15; 12 |], result) + +[] +let ``AsyncSeq.zappAsync on empty source returns empty`` () = + let fs = asyncSeq { yield (fun x -> async { return x + 1 }) } + let vs = AsyncSeq.empty + let result = AsyncSeq.zappAsync fs vs |> AsyncSeq.toArrayAsync |> Async.RunSynchronously + Assert.AreEqual([||], result) + +// ===== compareWithAsync ===== + +[] +let ``AsyncSeq.compareWithAsync equal sequences returns 0`` () = + let result = + AsyncSeq.compareWithAsync + (fun a b -> async { return compare a b }) + (AsyncSeq.ofSeq [1;2;3]) + (AsyncSeq.ofSeq [1;2;3]) + |> Async.RunSynchronously + Assert.AreEqual(0, result) + +[] +let ``AsyncSeq.compareWithAsync shorter is less than longer`` () = + let result = + AsyncSeq.compareWithAsync + (fun a b -> async { return compare a b }) + (AsyncSeq.ofSeq [1;2]) + (AsyncSeq.ofSeq [1;2;3]) + |> Async.RunSynchronously + Assert.IsTrue(result < 0) + +[] +let ``AsyncSeq.compareWithAsync longer is greater than shorter`` () = + let result = + AsyncSeq.compareWithAsync + (fun a b -> async { return compare a b }) + (AsyncSeq.ofSeq [1;2;3]) + (AsyncSeq.ofSeq [1;2]) + |> Async.RunSynchronously + Assert.IsTrue(result > 0) + +[] +let ``AsyncSeq.compareWithAsync lexicographic difference`` () = + let result = + AsyncSeq.compareWithAsync + (fun a b -> async { return compare a b }) + (AsyncSeq.ofSeq [1;3]) + (AsyncSeq.ofSeq [1;2]) + |> Async.RunSynchronously + Assert.IsTrue(result > 0) + +[] +let ``AsyncSeq.compareWithAsync empty sequences returns 0`` () = + let result = + AsyncSeq.compareWithAsync + (fun a b -> async { return compare a b }) + AsyncSeq.empty + AsyncSeq.empty + |> Async.RunSynchronously + Assert.AreEqual(0, result)