Skip to content

Commit

Permalink
Merge pull request #228 from fsprojects/remove-dead-code
Browse files Browse the repository at this point in the history
Cleanup: remove dead code, improve test coverage
  • Loading branch information
abelbraaksma authored Dec 28, 2023
2 parents 35d5bb7 + da701b6 commit 641c284
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/FSharp.Control.TaskSeq.Test/TaskSeq.Append.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ module SideEffects =
|> validateSequence
|> Task.map (fun () -> i |> should equal 2)

[<Theory; ClassData(typeof<TestImmTaskSeq>)>]
let ``TaskSeq-appendSeq consumes whole sequence once incl after-effects`` variant =
[<Fact>]
let ``TaskSeq-appendSeq consumes whole sequence once incl after-effects`` () =
let mutable i = 0

let ts = taskSeq {
Expand All @@ -108,8 +108,8 @@ module SideEffects =
|> validateSequence
|> Task.map (fun () -> i |> should equal 2)

[<Theory; ClassData(typeof<TestImmTaskSeq>)>]
let ``TaskSeq-prependSeq consumes whole sequence once incl after-effects`` variant =
[<Fact>]
let ``TaskSeq-prependSeq consumes whole sequence once incl after-effects`` () =
let mutable i = 0

taskSeq {
Expand Down
10 changes: 6 additions & 4 deletions src/FSharp.Control.TaskSeq.Test/TaskSeq.Except.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ module EmptySeq =
let ``TaskSeq-except no side effect in exclude seq if source seq is empty`` variant =
let mutable i = 0

// The `exclude` argument of TaskSeq.except is only iterated after the first item
// from the input. With empty input, this is not evaluated
let exclude = taskSeq {
i <- i + 1
i <- i + 1 // we test that we never get here
yield 12
}

TaskSeq.empty
Gen.getEmptyVariant variant
|> TaskSeq.except exclude
|> verifyEmpty
|> Task.map (fun () -> i |> should equal 0) // exclude seq is only enumerated after first item in source
Expand Down Expand Up @@ -96,8 +98,8 @@ module Immutable =
|> TaskSeq.except (Gen.getSeqImmutable variant)
|> verifyEmpty

[<Theory; ClassData(typeof<TestImmTaskSeq>)>]
let ``TaskSeq-exceptOfSeq removes duplicates`` variant =
[<Fact>]
let ``TaskSeq-exceptOfSeq removes duplicates`` () =
TaskSeq.ofList [ 1; 1; 2; 3; 4; 12; 12; 12; 13; 13; 13; 13; 13; 99 ]
|> TaskSeq.exceptOfSeq [ 1..10 ]
|> TaskSeq.toArrayAsync
Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Control.TaskSeq.Test/TaskSeq.Pick.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ module Immutable =
twentyFive |> should equal "foo"
}

[<Theory; ClassData(typeof<TestImmTaskSeq>)>]
let ``TaskSeq-pick happy path first item of seq`` variant = task {
[<Fact>]
let ``TaskSeq-pick happy path first item of seq`` () = task {
let! first =
Gen.sideEffectTaskSeqMicro 50L<µs> 1000L<µs> 50
|> TaskSeq.pick (fun x -> if x = 1 then Some $"first{x}" else None) // dummy tasks seq starts at 1
Expand Down
11 changes: 6 additions & 5 deletions src/FSharp.Control.TaskSeq.Test/TaskSeq.Realworld.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ type AsyncBufferedReader(_output: ITestOutputHelper, data, blockSize) =
let! bytesRead = buffered.ReadAsync(mem, 0, mem.Length) // offset refers to offset in target buffer, not source
lastPos <- buffered.Position

let x: seq<Guid> = seq { 1 } |> Seq.cast

if bytesRead > 0 then
current <- ValueSome mem
return true
Expand Down Expand Up @@ -102,11 +100,14 @@ type ``Real world tests``(output: ITestOutputHelper) =

[<Fact(Skip = "Broken test, faulty streaming test-implementation")>]
let ``Reading a 10MB buffered IAsync stream from start to finish`` () = task {
// TODO: fix this test Remove underscores of the vars and rerun the test with
// all lined uncommented
let mutable count = 0
use reader = AsyncBufferedReader(output, Array.init 2048 byte, 256)
use reader = new AsyncBufferedReader(output, Array.init 2048 byte, 256)
let expected = Array.init 256 byte

let ts = taskSeq {
// TODO: use this
let _ts = taskSeq {
for data in reader do
do count <- count + 1

Expand All @@ -116,7 +117,7 @@ type ``Real world tests``(output: ITestOutputHelper) =
yield data
}

// the following is extremely slow, which is why we just use F#'s comparison instead
// the following is extremely slow in XUnit/FsUnit, which is why we just use F#'s comparison instead
// Using this takes 67s, compared to 0.25s using normal F# comparison.
// reader |> TaskSeq.toArray |> should equal expected // VERY SLOW!!

Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Control.TaskSeq.Test/TaskSeq.ToXXX.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ module SideEffects =

[<Theory; ClassData(typeof<TestSideEffectTaskSeq>)>]
let ``TaskSeq-toListAsync should execute side effects multiple times`` variant = task {
let tq = Gen.sideEffectTaskSeq 10
let tq = Gen.getSeqWithSideEffect variant
let! (results1: list<_>) = tq |> TaskSeq.toListAsync
let! (results2: list<_>) = tq |> TaskSeq.toListAsync
results1 |> should equal [ 1..10 ]
Expand Down

0 comments on commit 641c284

Please sign in to comment.