Skip to content

Commit

Permalink
+ Test
Browse files Browse the repository at this point in the history
  • Loading branch information
gusty committed Nov 8, 2023
1 parent 71c5222 commit 7476e04
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/FSharpPlus/Control/Collection.fs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,11 @@ type GroupBy =
type ChunkBy =
static member ChunkBy (x: Id<'T> , f: 'T->'Key, _: Id<'Key*Id<'T>> , [<Optional>]_impl: ChunkBy) = let a = Id.run x in Id.create (f a, x)
static member ChunkBy (x: seq<'T> , f: 'T->'Key, _: seq<'Key*seq<'T>> , [<Optional>]_impl: ChunkBy) = Seq.chunkBy f x |> Seq.map (fun (x,y) -> x, y :> _ seq)
static member ChunkBy (x: list<'T>, f: 'T->'Key, _: list<'Key*list<'T>>, [<Optional>]_impl: ChunkBy) = List.chunkBy f x
static member ChunkBy (x: list<'T>, f: 'T->'Key, _: list<'Key*list<'T>>, [<Optional>]_impl: ChunkBy) =
#if TEST_TRACE
Traces.add "ChunkBy, list<'T>"
#endif
List.chunkBy f x
static member ChunkBy (x: 'T [] , f: 'T->'Key, _: ('Key*('T [])) [] , [<Optional>]_impl: ChunkBy) = Seq.chunkBy f x |> Seq.map (fun (x,y) -> x, Seq.toArray y) |> Seq.toArray

static member inline Invoke (projection: 'T->'Key) (source: '``Collection<'T>``) : '``Collection<'Key * 'Collection<'T>>`` =
Expand Down
24 changes: 24 additions & 0 deletions tests/FSharpPlus.Tests/Collections.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace FSharpPlus.Tests

open FSharpPlus
open FSharpPlus.Data
open NUnit.Framework

#if TEST_TRACE
open FSharpPlus.Internals
#endif

module Collections2 =

[<Test>]
let chunkBy () =
#if TEST_TRACE
Traces.reset()
#endif
let source = [1; 2; 3; 5; 7; 9]
let expected = [(1, [1]); (0, [2]); (1, [3; 5; 7; 9])]
let actual = List.chunkBy (flip (%) 2) source
CollectionAssert.AreEqual(expected, actual)
#if TEST_TRACE
CollectionAssert.AreEqual (["ChunkBy, list<'T>"], Traces.get())
#endif
1 change: 1 addition & 0 deletions tests/FSharpPlus.Tests/FSharpPlus.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<Compile Include="Parsing.fs" />
<Compile Include="Traversals.fs" />
<Compile Include="Indexables.fs" />
<Compile Include="Collections.fs" />
<Compile Include="Validations.fs" />
<Compile Include="Task.fs" />
<Compile Include="ValueTask.fs" />
Expand Down

0 comments on commit 7476e04

Please sign in to comment.