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 @@ -144,6 +144,57 @@ type ArrayModule() =

()

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

// int Seq
Assert.AreEqual([| [|1..4|]; [|5..8|] |], Array.chunkBySize 4 [|1..8|])
Assert.AreEqual([| [|1..4|]; [|5..8|]; [|9..10|] |], Array.chunkBySize 4 [|1..10|])
Assert.AreEqual([| [|1|]; [|2|]; [|3|]; [|4|] |], Array.chunkBySize 1 [|1..4|])

// string Seq
Assert.AreEqual([| [|"a"; "b"|]; [|"c";"d"|]; [|"e"|] |], Array.chunkBySize 2 [|"a";"b";"c";"d";"e"|])

// empty Seq
Assert.AreEqual([||], Array.chunkBySize 3 [||])

// null Seq
let nullArr:_[] = null
CheckThrowsArgumentNullException (fun () -> Array.chunkBySize 3 nullArr |> ignore)

// invalidArg
CheckThrowsArgumentException (fun () -> Array.chunkBySize 0 [|1..10|] |> ignore)
CheckThrowsArgumentException (fun () -> Array.chunkBySize -1 [|1..10|] |> ignore)

()

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

// int array
Assert.AreEqual([| [|1..4|]; [|5..7|]; [|8..10|] |], Array.splitInto 3 [|1..10|])
Assert.AreEqual([| [|1..4|]; [|5..8|]; [|9..11|] |], Array.splitInto 3 [|1..11|])
Assert.AreEqual([| [|1..4|]; [|5..8|]; [|9..12|] |], Array.splitInto 3 [|1..12|])

Assert.AreEqual([| [|1..2|]; [|3|]; [|4|]; [|5|] |], Array.splitInto 4 [|1..5|])
Assert.AreEqual([| [|1|]; [|2|]; [|3|]; [|4|] |], Array.splitInto 20 [|1..4|])

// string array
Assert.AreEqual([| [|"a"; "b"|]; [|"c";"d"|]; [|"e"|] |], Array.splitInto 3 [|"a";"b";"c";"d";"e"|])

// empty array
Assert.AreEqual([| |], Array.splitInto 3 [| |])

// null array
let nullArr:_[] = null
CheckThrowsArgumentNullException (fun () -> Array.splitInto 3 nullArr |> ignore)

// invalidArg
CheckThrowsArgumentException (fun () -> Array.splitInto 0 [|1..10|] |> ignore)
CheckThrowsArgumentException (fun () -> Array.splitInto -1 [|1..10|] |> ignore)

()

[<Test>]
member this.distinct() =
// distinct should work on empty array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,50 @@ type ListModule() =
Assert.AreEqual(22.476666666666666666666666667M, averageOfDecimal)

()


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

// int list
Assert.AreEqual([ [1..4]; [5..8] ], List.chunkBySize 4 [1..8])
Assert.AreEqual([ [1..4]; [5..8]; [9..10] ], List.chunkBySize 4 [1..10])
Assert.AreEqual([ [1]; [2]; [3]; [4] ], List.chunkBySize 1 [1..4])

// string list
Assert.AreEqual([ ["a"; "b"]; ["c";"d"]; ["e"] ], List.chunkBySize 2 ["a";"b";"c";"d";"e"])

// empty list
Assert.AreEqual([], List.chunkBySize 3 [])

// invalidArg
CheckThrowsArgumentException (fun () -> List.chunkBySize 0 [1..10] |> ignore)
CheckThrowsArgumentException (fun () -> List.chunkBySize -1 [1..10] |> ignore)

()

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

// int list
Assert.AreEqual([ [1..4]; [5..7]; [8..10] ], List.splitInto 3 [1..10])
Assert.AreEqual([ [1..4]; [5..8]; [9..11] ], List.splitInto 3 [1..11])
Assert.AreEqual([ [1..4]; [5..8]; [9..12] ], List.splitInto 3 [1..12])

Assert.AreEqual([ [1..2]; [3]; [4]; [5] ], List.splitInto 4 [1..5])
Assert.AreEqual([ [1]; [2]; [3]; [4] ], List.splitInto 20 [1..4])

// string list
Assert.AreEqual([ ["a"; "b"]; ["c";"d"]; ["e"] ], List.splitInto 3 ["a";"b";"c";"d";"e"])

// empty list
Assert.AreEqual([], List.splitInto 3 [])

// invalidArg
CheckThrowsArgumentException (fun () -> List.splitInto 0 [1..10] |> ignore)
CheckThrowsArgumentException (fun () -> List.splitInto -1 [1..10] |> ignore)

()

[<Test>]
member this.distinct() =
// distinct should work on empty list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,74 @@ type SeqModule() =

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


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

let verify expected actual =
Seq.zip expected actual
|> Seq.iter ((<||) VerifySeqsEqual)

// int Seq
verify [[1..4];[5..8]] <| Seq.chunkBySize 4 {1..8}
verify [[1..4];[5..8];[9..10]] <| Seq.chunkBySize 4 {1..10}
verify [[1]; [2]; [3]; [4]] <| Seq.chunkBySize 1 {1..4}

Seq.chunkBySize 2 (Seq.initInfinite id)
|> Seq.take 3
|> verify [[0;1];[2;3];[4;5]]

Seq.chunkBySize 1 (Seq.initInfinite id)
|> Seq.take 5
|> verify [[0];[1];[2];[3];[4]]

// string Seq
verify [["a"; "b"];["c";"d"];["e"]] <| Seq.chunkBySize 2 ["a";"b";"c";"d";"e"]

// empty Seq
verify Seq.empty <| Seq.chunkBySize 3 Seq.empty

// null Seq
let nullSeq:seq<_> = null
CheckThrowsArgumentNullException (fun () -> Seq.chunkBySize 3 nullSeq |> ignore)

// invalidArg
CheckThrowsArgumentException (fun () -> Seq.chunkBySize 0 {1..10} |> ignore)
CheckThrowsArgumentException (fun () -> Seq.chunkBySize -1 {1..10} |> ignore)

()

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

let verify expected actual =
Seq.zip expected actual
|> Seq.iter ((<||) VerifySeqsEqual)

// int Seq
Seq.splitInto 3 {1..10} |> verify (seq [ {1..4}; {5..7}; {8..10} ])
Seq.splitInto 3 {1..11} |> verify (seq [ {1..4}; {5..8}; {9..11} ])
Seq.splitInto 3 {1..12} |> verify (seq [ {1..4}; {5..8}; {9..12} ])

Seq.splitInto 4 {1..5} |> verify (seq [ [1..2]; [3]; [4]; [5] ])
Seq.splitInto 20 {1..4} |> verify (seq [ [1]; [2]; [3]; [4] ])

// string Seq
Seq.splitInto 3 ["a";"b";"c";"d";"e"] |> verify ([ ["a"; "b"]; ["c";"d"]; ["e"] ])

// empty Seq
VerifySeqsEqual [] <| Seq.splitInto 3 []

// null Seq
let nullSeq:seq<_> = null
CheckThrowsArgumentNullException (fun () -> Seq.splitInto 3 nullSeq |> ignore)

// invalidArg
CheckThrowsArgumentException (fun () -> Seq.splitInto 0 [1..10] |> ignore)
CheckThrowsArgumentException (fun () -> Seq.splitInto -1 [1..10] |> ignore)

()

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

Expand Down
6 changes: 6 additions & 0 deletions src/fsharp/FSharp.Core.Unittests/SurfaceArea.net40.fs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ Microsoft.FSharp.Collections.ArrayModule: T[] Truncate[T](Int32, T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Unfold[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpOption`1[System.Tuple`2[T,TState]]], TState)
Microsoft.FSharp.Collections.ArrayModule: T[] Where[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] ZeroCreate[T](Int32)
Microsoft.FSharp.Collections.ArrayModule: T[][] ChunkBySize[T](Int32, T[])
Microsoft.FSharp.Collections.ArrayModule: T[][] SplitInto[T](Int32, T[])
Microsoft.FSharp.Collections.ArrayModule: T[][] Windowed[T](Int32, T[])
Microsoft.FSharp.Collections.ArrayModule: Void CopyTo[T](T[], Int32, T[], Int32, Int32)
Microsoft.FSharp.Collections.ArrayModule: Void Fill[T](T[], Int32, Int32, T)
Expand Down Expand Up @@ -289,6 +291,8 @@ Microsoft.FSharp.Collections.ListModule: Int32 FindIndexBack[T](Microsoft.FSharp
Microsoft.FSharp.Collections.ListModule: Int32 FindIndex[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Int32 GetHashCode()
Microsoft.FSharp.Collections.ListModule: Int32 Length[T](Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[Microsoft.FSharp.Collections.FSharpList`1[T]] ChunkBySize[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[Microsoft.FSharp.Collections.FSharpList`1[T]] SplitInto[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[Microsoft.FSharp.Collections.FSharpList`1[T]] Windowed[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`2[System.Int32,T]] Indexed[T](Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`2[T,T]] Pairwise[T](Microsoft.FSharp.Collections.FSharpList`1[T])
Expand Down Expand Up @@ -441,6 +445,8 @@ Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[TResult] Map[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[TState] ScanBack[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[TState,TState]], System.Collections.Generic.IEnumerable`1[T], TState)
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[TState] Scan[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpFunc`2[T,TState]], TState, System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T[]] ChunkBySize[T](Int32, System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T[]] SplitInto[T](Int32, System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T[]] Windowed[T](Int32, System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Append[T](System.Collections.Generic.IEnumerable`1[T], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Cache[T](System.Collections.Generic.IEnumerable`1[T])
Expand Down
6 changes: 6 additions & 0 deletions src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable259.fs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ Microsoft.FSharp.Collections.ArrayModule: T[] Truncate[T](Int32, T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Unfold[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpOption`1[System.Tuple`2[T,TState]]], TState)
Microsoft.FSharp.Collections.ArrayModule: T[] Where[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] ZeroCreate[T](Int32)
Microsoft.FSharp.Collections.ArrayModule: T[][] ChunkBySize[T](Int32, T[])
Microsoft.FSharp.Collections.ArrayModule: T[][] SplitInto[T](Int32, T[])
Microsoft.FSharp.Collections.ArrayModule: T[][] Windowed[T](Int32, T[])
Microsoft.FSharp.Collections.ArrayModule: Void CopyTo[T](T[], Int32, T[], Int32, Int32)
Microsoft.FSharp.Collections.ArrayModule: Void Fill[T](T[], Int32, Int32, T)
Expand Down Expand Up @@ -276,6 +278,8 @@ Microsoft.FSharp.Collections.ListModule: Int32 FindIndexBack[T](Microsoft.FSharp
Microsoft.FSharp.Collections.ListModule: Int32 FindIndex[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Int32 GetHashCode()
Microsoft.FSharp.Collections.ListModule: Int32 Length[T](Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[Microsoft.FSharp.Collections.FSharpList`1[T]] ChunkBySize[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[Microsoft.FSharp.Collections.FSharpList`1[T]] SplitInto[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[Microsoft.FSharp.Collections.FSharpList`1[T]] Windowed[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`2[System.Int32,T]] Indexed[T](Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`2[T,T]] Pairwise[T](Microsoft.FSharp.Collections.FSharpList`1[T])
Expand Down Expand Up @@ -428,6 +432,8 @@ Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[TResult] Map[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[TState] ScanBack[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[TState,TState]], System.Collections.Generic.IEnumerable`1[T], TState)
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[TState] Scan[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpFunc`2[T,TState]], TState, System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T[]] ChunkBySize[T](Int32, System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T[]] SplitInto[T](Int32, System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T[]] Windowed[T](Int32, System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Append[T](System.Collections.Generic.IEnumerable`1[T], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Cache[T](System.Collections.Generic.IEnumerable`1[T])
Expand Down
6 changes: 6 additions & 0 deletions src/fsharp/FSharp.Core.Unittests/SurfaceArea.portable47.fs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ Microsoft.FSharp.Collections.ArrayModule: T[] Truncate[T](Int32, T[])
Microsoft.FSharp.Collections.ArrayModule: T[] Unfold[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpOption`1[System.Tuple`2[T,TState]]], TState)
Microsoft.FSharp.Collections.ArrayModule: T[] Where[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], T[])
Microsoft.FSharp.Collections.ArrayModule: T[] ZeroCreate[T](Int32)
Microsoft.FSharp.Collections.ArrayModule: T[][] ChunkBySize[T](Int32, T[])
Microsoft.FSharp.Collections.ArrayModule: T[][] SplitInto[T](Int32, T[])
Microsoft.FSharp.Collections.ArrayModule: T[][] Windowed[T](Int32, T[])
Microsoft.FSharp.Collections.ArrayModule: Void CopyTo[T](T[], Int32, T[], Int32, Int32)
Microsoft.FSharp.Collections.ArrayModule: Void Fill[T](T[], Int32, Int32, T)
Expand Down Expand Up @@ -273,6 +275,8 @@ Microsoft.FSharp.Collections.ListModule: Int32 FindIndexBack[T](Microsoft.FSharp
Microsoft.FSharp.Collections.ListModule: Int32 FindIndex[T](Microsoft.FSharp.Core.FSharpFunc`2[T,System.Boolean], Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Int32 GetHashCode()
Microsoft.FSharp.Collections.ListModule: Int32 Length[T](Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[Microsoft.FSharp.Collections.FSharpList`1[T]] ChunkBySize[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[Microsoft.FSharp.Collections.FSharpList`1[T]] SplitInto[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[Microsoft.FSharp.Collections.FSharpList`1[T]] Windowed[T](Int32, Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`2[System.Int32,T]] Indexed[T](Microsoft.FSharp.Collections.FSharpList`1[T])
Microsoft.FSharp.Collections.ListModule: Microsoft.FSharp.Collections.FSharpList`1[System.Tuple`2[T,T]] Pairwise[T](Microsoft.FSharp.Collections.FSharpList`1[T])
Expand Down Expand Up @@ -425,6 +429,8 @@ Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[TResult] Map[T,TResult](Microsoft.FSharp.Core.FSharpFunc`2[T,TResult], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[TState] ScanBack[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[T,Microsoft.FSharp.Core.FSharpFunc`2[TState,TState]], System.Collections.Generic.IEnumerable`1[T], TState)
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[TState] Scan[T,TState](Microsoft.FSharp.Core.FSharpFunc`2[TState,Microsoft.FSharp.Core.FSharpFunc`2[T,TState]], TState, System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T[]] ChunkBySize[T](Int32, System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T[]] SplitInto[T](Int32, System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T[]] Windowed[T](Int32, System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Append[T](System.Collections.Generic.IEnumerable`1[T], System.Collections.Generic.IEnumerable`1[T])
Microsoft.FSharp.Collections.SeqModule: System.Collections.Generic.IEnumerable`1[T] Cache[T](System.Collections.Generic.IEnumerable`1[T])
Expand Down
Loading