Skip to content

Commit

Permalink
splitInto produces chunks exactly count chunks with equal size (+/- 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Jul 29, 2015
1 parent 6ae9f88 commit 350a7c1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/fsharp/FSharp.Core.PropertyTests/ListProperties.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ let sort_and_sortby (xs : list<float>) (xs2 : list<float>) =
result := false
!result

[<Test>]
let ``splitInto produces chunks exactly `count` chunks with equal size (+/- 1)``() =
let prop (a: _ list) (PositiveInt count') =
let count = min a.Length count'
match a |> List.splitInto count' |> Seq.toList with
| [] -> a = []
| h :: [] -> (a.Length = 1 || count = 1) && h = a
| chunks ->
let lastChunk = chunks |> List.last
let lastLength = lastChunk |> List.length

chunks.Length = count
&&
chunks |> List.forall (fun c -> List.length c = lastLength || List.length c = lastLength + 1)

Check.QuickThrowOnFailure prop

[<Test>]
let ``sort behaves like sortby id`` () =
Check.QuickThrowOnFailure sort_and_sortby
Expand Down

0 comments on commit 350a7c1

Please sign in to comment.