Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,39 @@ type ArrayModule() =
Assert.AreEqual([|null|], Array.distinctBy id [|null|])
let list = new System.Collections.Generic.List<int>()
Assert.AreEqual([|null, list|], Array.distinctBy id [|null, list|])


[<Test>]
member this.Except() =
// integer array
let intArr1 = [| yield! {1..100}
yield! {1..100} |]
let intArr2 = [| 1 .. 10 |]
let expectedIntArr = [| 11 .. 100 |]

Assert.AreEqual(expectedIntArr, Array.except intArr2 intArr1)

// string array
let strArr1 = [| "a"; "b"; "c"; "d"; "a" |]
let strArr2 = [| "b"; "c" |]
let expectedStrArr = [| "a"; "d" |]

Assert.AreEqual(expectedStrArr, Array.except strArr2 strArr1)

// empty array
let emptyIntArr = [| |]
Assert.AreEqual([|1..100|], Array.except emptyIntArr intArr1)
Assert.AreEqual(emptyIntArr, Array.except intArr1 emptyIntArr)
Assert.AreEqual(emptyIntArr, Array.except emptyIntArr emptyIntArr)
Assert.AreEqual(emptyIntArr, Array.except intArr1 intArr1)

// null array
let nullArr : int [] = null
CheckThrowsArgumentNullException(fun () -> Array.except nullArr emptyIntArr |> ignore)
CheckThrowsArgumentNullException(fun () -> Array.except emptyIntArr nullArr |> ignore)
CheckThrowsArgumentNullException(fun () -> Array.except nullArr nullArr |> ignore)

()

[<Test>]
member this.Take() =
Assert.AreEqual([||],Array.take 0 [||])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,35 @@ type ListModule() =
Assert.AreEqual([5,1; 2,2; 3,2],List.countBy id [5;2;2;3;3])
Assert.AreEqual([3,3; 2,2; 1,3],List.countBy (fun x -> if x < 3 then x else 3) [5;2;1;2;3;3;1;1])

[<Test>]
member this.Except() =
// integer list
let intList1 = [ yield! {1..100}
yield! {1..100} ]
let intList2 = [1..10]
let expectedIntList = [11..100]

Assert.AreEqual(expectedIntList, List.except intList2 intList1)

// string list
let strList1 = ["a"; "b"; "c"; "d"; "a"]
let strList2 = ["b"; "c"]
let expectedStrList = ["a"; "d"]

Assert.AreEqual(expectedStrList, List.except strList2 strList1)

// empty list
let emptyIntList = []
Assert.AreEqual([1..100], List.except emptyIntList intList1)
Assert.AreEqual(emptyIntList, List.except intList1 emptyIntList)
Assert.AreEqual(emptyIntList, List.except emptyIntList emptyIntList)
Assert.AreEqual(emptyIntList, List.except intList1 intList1)

// null seq
let nullSeq : int [] = null
CheckThrowsArgumentNullException(fun () -> List.except nullSeq emptyIntList |> ignore)
()

[<Test>]
member this.Exists() =
// integer List
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,46 @@ type SeqModule() =

CheckThrowsArgumentNullException(fun () -> Seq.distinctBy funcInt nullSeq |> ignore)
()


[<Test>]
member this.Except() =
// integer Seq
let intSeq1 = seq { yield! {1..100}
yield! {1..100} }
let intSeq2 = {1..10}
let expectedIntSeq = {11..100}

VerifySeqsEqual expectedIntSeq <| Seq.except intSeq2 intSeq1

// string Seq
let strSeq1 = seq ["a"; "b"; "c"; "d"; "a"]
let strSeq2 = seq ["b"; "c"]
let expectedStrSeq = seq ["a"; "d"]

VerifySeqsEqual expectedStrSeq <| Seq.except strSeq2 strSeq1

// double Seq
// Sequences with nan do not behave, due to the F# generic equality comparisons
// let floatSeq1 = seq [1.0; 1.0; System.Double.MaxValue; nan; nan]
//
// VerifySeqsEqual [1.0; System.Double.MaxValue; nan; nan] <| Seq.except [] floatSeq1
// VerifySeqsEqual [1.0; System.Double.MaxValue] <| Seq.except [nan] floatSeq1

// empty Seq
let emptyIntSeq = Seq.empty<int>
VerifySeqsEqual {1..100} <| Seq.except emptyIntSeq intSeq1
VerifySeqsEqual emptyIntSeq <| Seq.except intSeq1 emptyIntSeq
VerifySeqsEqual emptyIntSeq <| Seq.except emptyIntSeq emptyIntSeq
VerifySeqsEqual emptyIntSeq <| Seq.except intSeq1 intSeq1

// null Seq
let nullSeq : seq<int> = null
CheckThrowsArgumentNullException(fun () -> Seq.except nullSeq emptyIntSeq |> ignore)
CheckThrowsArgumentNullException(fun () -> Seq.except emptyIntSeq nullSeq |> ignore)
CheckThrowsArgumentNullException(fun () -> Seq.except nullSeq nullSeq |> ignore)

()

[<Test>]
member this.Exists() =

Expand Down
3 changes: 3 additions & 0 deletions src/fsharp/FSharp.Core.Unittests/SurfaceArea.net40.fs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ Microsoft.FSharp.Collections.ArrayModule: T[] Create[T](Int32, T)
Microsoft.FSharp.Collections.ArrayModule: T[] DistinctBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Distinct[T](T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Empty[T]()
Microsoft.FSharp.Collections.ArrayModule: T[] Except[T](System.Collections.Generic.IEnumerable`1[T], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] GetSubArray[T](T[], Int32, Int32)
Microsoft.FSharp.Collections.ArrayModule: T[] Initialize[T](Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
Expand Down Expand Up @@ -309,6 +310,7 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] DistinctBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Distinct[T](Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Empty[T]()
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Except[T](System.Collections.Generic.IEnumerable`1[T], Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Initialize[T](Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] OfArray[T](T[])
Expand Down Expand Up @@ -448,6 +450,7 @@ Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] DistinctBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Distinct[T](System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Empty[T]()
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Except[T](System.Collections.Generic.IEnumerable`1[T], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] InitializeInfinite[T](Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Initialize[T](Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
Expand Down
3 changes: 3 additions & 0 deletions src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable259.fs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Microsoft.FSharp.Collections.ArrayModule: T[] Create[T](Int32, T)
Microsoft.FSharp.Collections.ArrayModule: T[] DistinctBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Distinct[T](T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Empty[T]()
Microsoft.FSharp.Collections.ArrayModule: T[] Except[T](System.Collections.Generic.IEnumerable`1[T], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] GetSubArray[T](T[], Int32, Int32)
Microsoft.FSharp.Collections.ArrayModule: T[] Initialize[T](Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
Expand Down Expand Up @@ -296,6 +297,7 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] DistinctBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Distinct[T](Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Empty[T]()
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Except[T](System.Collections.Generic.IEnumerable`1[T], Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Initialize[T](Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] OfArray[T](T[])
Expand Down Expand Up @@ -435,6 +437,7 @@ Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] DistinctBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Distinct[T](System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Empty[T]()
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Except[T](System.Collections.Generic.IEnumerable`1[T], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] InitializeInfinite[T](Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Initialize[T](Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
Expand Down
3 changes: 3 additions & 0 deletions src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable47.fs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ Microsoft.FSharp.Collections.ArrayModule: T[] Create[T](Int32, T)
Microsoft.FSharp.Collections.ArrayModule: T[] DistinctBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Distinct[T](T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Empty[T]()
Microsoft.FSharp.Collections.ArrayModule: T[] Except[T](System.Collections.Generic.IEnumerable`1[T], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] GetSubArray[T](T[], Int32, Int32)
Microsoft.FSharp.Collections.ArrayModule: T[] Initialize[T](Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
Expand Down Expand Up @@ -293,6 +294,7 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] DistinctBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Distinct[T](Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Empty[T]()
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Except[T](System.Collections.Generic.IEnumerable`1[T], Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Initialize[T](Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] OfArray[T](T[])
Expand Down Expand Up @@ -432,6 +434,7 @@ Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] DistinctBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Distinct[T](System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Empty[T]()
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Except[T](System.Collections.Generic.IEnumerable`1[T], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] InitializeInfinite[T](Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Initialize[T](Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
Expand Down
3 changes: 3 additions & 0 deletions src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable7.fs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ Microsoft.FSharp.Collections.ArrayModule: T[] Create[T](Int32, T)
Microsoft.FSharp.Collections.ArrayModule: T[] DistinctBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Distinct[T](T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Empty[T]()
Microsoft.FSharp.Collections.ArrayModule: T[] Except[T](System.Collections.Generic.IEnumerable`1[T], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] GetSubArray[T](T[], Int32, Int32)
Microsoft.FSharp.Collections.ArrayModule: T[] Initialize[T](Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
Expand Down Expand Up @@ -309,6 +310,7 @@ Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] DistinctBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Distinct[T](Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Empty[T]()
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Except[T](System.Collections.Generic.IEnumerable`1[T], Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] Initialize[T](Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[T] OfArray[T](T[])
Expand Down Expand Up @@ -448,6 +450,7 @@ Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] DistinctBy[T,TKey](Microsoft.FSharp.Core.FSharpFunc`2[T,TKey], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Distinct[T](System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Empty[T]()
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Except[T](System.Collections.Generic.IEnumerable`1[T], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Filter[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] InitializeInfinite[T](Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Initialize[T](Int32, Microsoft.FSharp.Core.FSharpFunc`2[System.Int32,T])
Expand Down
Loading