Skip to content

Commit 0b5b735

Browse files
authored
Merge pull request #188 from fsprojects/feature/additional-coverage-utils-edge-cases
Daily Test Coverage Improver: Add 13 comprehensive edge case and branch coverage tests
2 parents 399d22c + c00773e commit 0b5b735

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,3 +2113,114 @@ let ``Seq.ofAsyncSeq with exception should propagate``() =
21132113

21142114
#endif
21152115

2116+
// ----------------------------------------------------------------------------
2117+
// Additional Coverage Tests targeting uncovered edge cases and branches
2118+
2119+
[<Test>]
2120+
let ``AsyncSeq.bufferByCount with size 1 should work`` () =
2121+
let source = asyncSeq { yield 1; yield 2; yield 3 }
2122+
let result = AsyncSeq.bufferByCount 1 source |> AsyncSeq.toListSynchronously
2123+
Assert.AreEqual([[|1|]; [|2|]; [|3|]], result)
2124+
2125+
[<Test>]
2126+
let ``AsyncSeq.bufferByCount with empty sequence should return empty`` () =
2127+
let result = AsyncSeq.bufferByCount 2 AsyncSeq.empty |> AsyncSeq.toListSynchronously
2128+
Assert.AreEqual([], result)
2129+
2130+
[<Test>]
2131+
let ``AsyncSeq.bufferByCount with size larger than sequence should return partial`` () =
2132+
let source = asyncSeq { yield 1; yield 2 }
2133+
let result = AsyncSeq.bufferByCount 5 source |> AsyncSeq.toListSynchronously
2134+
Assert.AreEqual([[|1; 2|]], result)
2135+
2136+
[<Test>]
2137+
let ``AsyncSeq.pairwise with empty sequence should return empty`` () =
2138+
let result = AsyncSeq.pairwise AsyncSeq.empty |> AsyncSeq.toListSynchronously
2139+
Assert.AreEqual([], result)
2140+
2141+
[<Test>]
2142+
let ``AsyncSeq.pairwise with single element should return empty`` () =
2143+
let source = asyncSeq { yield 42 }
2144+
let result = AsyncSeq.pairwise source |> AsyncSeq.toListSynchronously
2145+
Assert.AreEqual([], result)
2146+
2147+
[<Test>]
2148+
let ``AsyncSeq.pairwise with three elements should produce two pairs`` () =
2149+
let source = asyncSeq { yield 1; yield 2; yield 3 }
2150+
let result = AsyncSeq.pairwise source |> AsyncSeq.toListSynchronously
2151+
Assert.AreEqual([(1, 2); (2, 3)], result)
2152+
2153+
[<Test>]
2154+
let ``AsyncSeq.distinctUntilChangedWith should work with custom equality`` () =
2155+
let source = asyncSeq { yield "a"; yield "A"; yield "B"; yield "b"; yield "c" }
2156+
let customEq (x: string) (y: string) = x.ToLower() = y.ToLower()
2157+
let result = AsyncSeq.distinctUntilChangedWith customEq source |> AsyncSeq.toListSynchronously
2158+
Assert.AreEqual(["a"; "B"; "c"], result)
2159+
2160+
[<Test>]
2161+
let ``AsyncSeq.distinctUntilChangedWith with all same elements should return single`` () =
2162+
let source = asyncSeq { yield 1; yield 1; yield 1 }
2163+
let result = AsyncSeq.distinctUntilChangedWith (=) source |> AsyncSeq.toListSynchronously
2164+
Assert.AreEqual([1], result)
2165+
2166+
[<Test>]
2167+
let ``AsyncSeq.append with both sequences having exceptions should propagate first`` () =
2168+
async {
2169+
let seq1 = asyncSeq { yield 1; failwith "error1" }
2170+
let seq2 = asyncSeq { yield 2; failwith "error2" }
2171+
let combined = AsyncSeq.append seq1 seq2
2172+
2173+
try
2174+
let! _ = AsyncSeq.toListAsync combined
2175+
Assert.Fail("Expected exception to be thrown")
2176+
with
2177+
| ex when ex.Message = "error1" ->
2178+
() // Expected - first sequence's error should be thrown
2179+
| ex ->
2180+
Assert.Fail($"Unexpected exception: {ex.Message}")
2181+
} |> Async.RunSynchronously
2182+
2183+
[<Test>]
2184+
let ``AsyncSeq.concat with nested exceptions should propagate properly`` () =
2185+
async {
2186+
let nested = asyncSeq {
2187+
yield asyncSeq { yield 1; yield 2 }
2188+
yield asyncSeq { failwith "nested error" }
2189+
yield asyncSeq { yield 3 }
2190+
}
2191+
let flattened = AsyncSeq.concat nested
2192+
2193+
try
2194+
let! result = AsyncSeq.toListAsync flattened
2195+
Assert.Fail("Expected exception to be thrown")
2196+
with
2197+
| ex when ex.Message = "nested error" ->
2198+
() // Expected
2199+
| ex ->
2200+
Assert.Fail($"Unexpected exception: {ex.Message}")
2201+
} |> Async.RunSynchronously
2202+
2203+
[<Test>]
2204+
let ``AsyncSeq.choose with all None should return empty`` () =
2205+
let source = asyncSeq { yield 1; yield 2; yield 3 }
2206+
let result = AsyncSeq.choose (fun _ -> None) source |> AsyncSeq.toListSynchronously
2207+
Assert.AreEqual([], result)
2208+
2209+
[<Test>]
2210+
let ``AsyncSeq.choose with mixed Some and None should filter correctly`` () =
2211+
let source = asyncSeq { yield 1; yield 2; yield 3; yield 4 }
2212+
let chooser x = if x % 2 = 0 then Some (x * 2) else None
2213+
let result = AsyncSeq.choose chooser source |> AsyncSeq.toListSynchronously
2214+
Assert.AreEqual([4; 8], result)
2215+
2216+
[<Test>]
2217+
let ``AsyncSeq.chooseAsync with async transformation should work`` () =
2218+
async {
2219+
let source = asyncSeq { yield 1; yield 2; yield 3; yield 4 }
2220+
let chooserAsync x = async {
2221+
if x % 2 = 0 then return Some (x * 3) else return None
2222+
}
2223+
let! result = AsyncSeq.chooseAsync chooserAsync source |> AsyncSeq.toListAsync
2224+
Assert.AreEqual([6; 12], result)
2225+
} |> Async.RunSynchronously
2226+

0 commit comments

Comments
 (0)