-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add implementation of TaskSeq.except/exceptOfSeq with tests and xml d…
…ocumentation
- Loading branch information
1 parent
c236b1a
commit 47dedbd
Showing
5 changed files
with
282 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
src/FSharp.Control.TaskSeq.Test/TaskSeq.Except.Tests.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
module TaskSeq.Tests.Except | ||
|
||
open System | ||
open Xunit | ||
open FsUnit.Xunit | ||
open FsToolkit.ErrorHandling | ||
|
||
open FSharp.Control | ||
|
||
// | ||
// TaskSeq.except | ||
// TaskSeq.exceptOfSeq | ||
// | ||
|
||
|
||
module EmptySeq = | ||
[<Theory; ClassData(typeof<TestEmptyVariants>)>] | ||
let ``TaskSeq-except`` variant = | ||
Gen.getEmptyVariant variant | ||
|> TaskSeq.except (Gen.getEmptyVariant variant) | ||
|> verifyEmpty | ||
|
||
[<Theory; ClassData(typeof<TestEmptyVariants>)>] | ||
let ``TaskSeq-exceptOfSeq`` variant = | ||
Gen.getEmptyVariant variant | ||
|> TaskSeq.exceptOfSeq Seq.empty | ||
|> verifyEmpty | ||
|
||
[<Theory; ClassData(typeof<TestEmptyVariants>)>] | ||
let ``TaskSeq-except v2`` variant = | ||
Gen.getEmptyVariant variant | ||
|> TaskSeq.except TaskSeq.empty | ||
|> verifyEmpty | ||
|
||
[<Theory; ClassData(typeof<TestEmptyVariants>)>] | ||
let ``TaskSeq-except v3`` variant = | ||
TaskSeq.empty | ||
|> TaskSeq.except (Gen.getEmptyVariant variant) | ||
|> verifyEmpty | ||
|
||
[<Theory; ClassData(typeof<TestEmptyVariants>)>] | ||
let ``TaskSeq-except no side effect in exclude seq if source seq is empty`` variant = | ||
let mutable i = 0 | ||
|
||
let exclude = taskSeq { | ||
i <- i + 1 | ||
yield 12 | ||
} | ||
|
||
TaskSeq.empty | ||
|> TaskSeq.except exclude | ||
|> verifyEmpty | ||
|> Task.map (fun () -> i |> should equal 0) // exclude seq is only enumerated after first item in source | ||
|
||
module Immutable = | ||
[<Theory; ClassData(typeof<TestImmTaskSeq>)>] | ||
let ``TaskSeq-except removes duplicates`` variant = | ||
TaskSeq.ofList [ 1; 1; 2; 3; 4; 12; 12; 12; 13; 13; 13; 13; 13; 99 ] | ||
|> TaskSeq.except (Gen.getSeqImmutable variant) | ||
|> TaskSeq.toArrayAsync | ||
|> Task.map (should equal [| 12; 13; 99 |]) | ||
|
||
[<Fact>] | ||
let ``TaskSeq-except removes duplicates with empty itemsToExcept`` () = | ||
TaskSeq.ofList [ 1; 1; 2; 3; 4; 12; 12; 12; 13; 13; 13; 13; 13; 99 ] | ||
|> TaskSeq.except TaskSeq.empty | ||
|> TaskSeq.toArrayAsync | ||
|> Task.map (should equal [| 1; 2; 3; 4; 12; 13; 99 |]) | ||
|
||
[<Theory; ClassData(typeof<TestImmTaskSeq>)>] | ||
let ``TaskSeq-except removes everything`` variant = | ||
Gen.getSeqImmutable variant | ||
|> TaskSeq.except (Gen.getSeqImmutable variant) | ||
|> verifyEmpty | ||
|
||
[<Theory; ClassData(typeof<TestImmTaskSeq>)>] | ||
let ``TaskSeq-except removes everything with duplicates`` variant = | ||
taskSeq { | ||
yield! Gen.getSeqImmutable variant | ||
yield! Gen.getSeqImmutable variant | ||
yield! Gen.getSeqImmutable variant | ||
yield! Gen.getSeqImmutable variant | ||
} | ||
|> TaskSeq.except (Gen.getSeqImmutable variant) | ||
|> verifyEmpty | ||
|
||
[<Theory; ClassData(typeof<TestImmTaskSeq>)>] | ||
let ``TaskSeq-exceptOfSeq removes duplicates`` variant = | ||
TaskSeq.ofList [ 1; 1; 2; 3; 4; 12; 12; 12; 13; 13; 13; 13; 13; 99 ] | ||
|> TaskSeq.exceptOfSeq [ 1..10 ] | ||
|> TaskSeq.toArrayAsync | ||
|> Task.map (should equal [| 12; 13; 99 |]) | ||
|
||
[<Fact>] | ||
let ``TaskSeq-exceptOfSeq removes duplicates with empty itemsToExcept`` () = | ||
TaskSeq.ofList [ 1; 1; 2; 3; 4; 12; 12; 12; 13; 13; 13; 13; 13; 99 ] | ||
|> TaskSeq.exceptOfSeq Seq.empty | ||
|> TaskSeq.toArrayAsync | ||
|> Task.map (should equal [| 1; 2; 3; 4; 12; 13; 99 |]) | ||
|
||
[<Theory; ClassData(typeof<TestImmTaskSeq>)>] | ||
let ``TaskSeq-exceptOfSeq removes everything`` variant = | ||
Gen.getSeqImmutable variant | ||
|> TaskSeq.exceptOfSeq [ 1..10 ] | ||
|> verifyEmpty | ||
|
||
[<Theory; ClassData(typeof<TestImmTaskSeq>)>] | ||
let ``TaskSeq-exceptOfSeq removes everything with duplicates`` variant = | ||
taskSeq { | ||
yield! Gen.getSeqImmutable variant | ||
yield! Gen.getSeqImmutable variant | ||
yield! Gen.getSeqImmutable variant | ||
yield! Gen.getSeqImmutable variant | ||
} | ||
|> TaskSeq.exceptOfSeq [ 1..10 ] | ||
|> verifyEmpty | ||
|
||
module SideEffects = | ||
[<Theory; ClassData(typeof<TestSideEffectTaskSeq>)>] | ||
let ``TaskSeq-except removes duplicates`` variant = | ||
TaskSeq.ofList [ 1; 1; 2; 3; 4; 12; 12; 12; 13; 13; 13; 13; 13; 99 ] | ||
|> TaskSeq.except (Gen.getSeqWithSideEffect variant) | ||
|> TaskSeq.toArrayAsync | ||
|> Task.map (should equal [| 12; 13; 99 |]) | ||
|
||
[<Theory; ClassData(typeof<TestSideEffectTaskSeq>)>] | ||
let ``TaskSeq-except removes everything`` variant = | ||
Gen.getSeqWithSideEffect variant | ||
|> TaskSeq.except (Gen.getSeqWithSideEffect variant) | ||
|> verifyEmpty | ||
|
||
[<Theory; ClassData(typeof<TestSideEffectTaskSeq>)>] | ||
let ``TaskSeq-except removes everything with duplicates`` variant = | ||
taskSeq { | ||
yield! Gen.getSeqWithSideEffect variant | ||
yield! Gen.getSeqWithSideEffect variant | ||
yield! Gen.getSeqWithSideEffect variant | ||
yield! Gen.getSeqWithSideEffect variant | ||
} | ||
|> TaskSeq.except (Gen.getSeqWithSideEffect variant) | ||
|> verifyEmpty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters