Skip to content

Commit 399d22c

Browse files
authored
Merge pull request fsprojects#186 from fsprojects/feature/additional-test-coverage-improvements
Daily Test Coverage Improver: Add comprehensive tests for intervalMs and validation edge cases
2 parents cfef22b + 7dae418 commit 399d22c

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,86 @@ let ``Seq.ofAsyncSeq with exception`` () =
18821882
Seq.ofAsyncSeq asyncSeqWithError |> Seq.toList |> ignore
18831883
) |> ignore
18841884

1885+
[<Test>]
1886+
let ``AsyncSeq.intervalMs should generate sequence with timestamps``() =
1887+
let result =
1888+
AsyncSeq.intervalMs 50
1889+
|> AsyncSeq.take 3
1890+
|> AsyncSeq.toListAsync
1891+
|> AsyncOps.timeoutMs 1000
1892+
|> Async.RunSynchronously
1893+
1894+
Assert.AreEqual(3, result.Length)
1895+
// Verify timestamps are increasing
1896+
Assert.IsTrue(result.[1] > result.[0])
1897+
Assert.IsTrue(result.[2] > result.[1])
1898+
1899+
[<Test>]
1900+
let ``AsyncSeq.intervalMs with zero period should work``() =
1901+
let result =
1902+
AsyncSeq.intervalMs 0
1903+
|> AsyncSeq.take 2
1904+
|> AsyncSeq.toListAsync
1905+
|> AsyncOps.timeoutMs 500
1906+
|> Async.RunSynchronously
1907+
1908+
Assert.AreEqual(2, result.Length)
1909+
1910+
[<Test>]
1911+
let ``AsyncSeq.take with negative count should throw ArgumentException``() =
1912+
Assert.Throws<System.ArgumentException>(fun () ->
1913+
AsyncSeq.ofSeq [1;2;3]
1914+
|> AsyncSeq.take -1
1915+
|> AsyncSeq.toListAsync
1916+
|> Async.RunSynchronously
1917+
|> ignore
1918+
) |> ignore
1919+
1920+
[<Test>]
1921+
let ``AsyncSeq.skip with negative count should throw ArgumentException``() =
1922+
Assert.Throws<System.ArgumentException>(fun () ->
1923+
AsyncSeq.ofSeq [1;2;3]
1924+
|> AsyncSeq.skip -1
1925+
|> AsyncSeq.toListAsync
1926+
|> Async.RunSynchronously
1927+
|> ignore
1928+
) |> ignore
1929+
1930+
[<Test>]
1931+
let ``AsyncSeq.take zero should return empty sequence``() =
1932+
let expected = []
1933+
let actual =
1934+
AsyncSeq.ofSeq [1;2;3]
1935+
|> AsyncSeq.take 0
1936+
|> AsyncSeq.toListAsync
1937+
|> Async.RunSynchronously
1938+
1939+
Assert.AreEqual(expected, actual)
1940+
1941+
[<Test>]
1942+
let ``AsyncSeq.skip zero should return original sequence``() =
1943+
let expected = [1;2;3]
1944+
let actual =
1945+
AsyncSeq.ofSeq [1;2;3]
1946+
|> AsyncSeq.skip 0
1947+
|> AsyncSeq.toListAsync
1948+
|> Async.RunSynchronously
1949+
1950+
Assert.AreEqual(expected, actual)
1951+
1952+
[<Test>]
1953+
let ``AsyncSeq.replicateInfinite with exception should propagate exception``() =
1954+
let exceptionMsg = "test exception"
1955+
let expected = System.ArgumentException(exceptionMsg)
1956+
1957+
Assert.Throws<System.ArgumentException>(fun () ->
1958+
AsyncSeq.replicateInfinite (raise expected)
1959+
|> AsyncSeq.take 2
1960+
|> AsyncSeq.toListAsync
1961+
|> Async.RunSynchronously
1962+
|> ignore
1963+
) |> ignore
1964+
18851965
#if (NETSTANDARD2_1 || NETCOREAPP3_0)
18861966
[<Test>]
18871967
let ``AsyncSeq.ofAsyncEnum should roundtrip successfully``() =

0 commit comments

Comments
 (0)