Skip to content

Commit

Permalink
chunkBySize revealed bug - references dotnet#501
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Jun 17, 2015
1 parent b7c523f commit 91e35ef
Showing 1 changed file with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@ let ``append is consistent`` () =
Check.QuickThrowOnFailure append<string>
Check.QuickThrowOnFailure append<NormalFloat>

let averageFloat (xs : NormalFloat []) =
let xs = xs |> Array.map float
let s = run (fun () -> xs |> Seq.average)
let l = run (fun () -> xs |> List.ofArray |> List.average)
let a = run (fun () -> xs |> Array.average)
s = a && l = a

[<Test>]
let ``average is consistent`` () =
Check.QuickThrowOnFailure averageFloat

let averageBy (xs : float []) f =
let xs = xs |> Array.map float
let f x = (f x : NormalFloat) |> float
let s = run (fun () -> xs |> Seq.averageBy f)
let l = run (fun () -> xs |> List.ofArray |> List.averageBy f)
let a = run (fun () -> xs |> Array.averageBy f)
s = a && l = a

[<Test>]
let ``averageBy is consistent`` () =
Check.QuickThrowOnFailure averageBy

let contains<'a when 'a : equality> (xs : 'a []) x =
let s = xs |> Seq.contains x
let l = xs |> List.ofArray |> List.contains x
Expand All @@ -54,6 +77,18 @@ let ``choose is consistent`` () =
Check.QuickThrowOnFailure contains<string>
Check.QuickThrowOnFailure contains<float>

let chunkBySize<'a when 'a : equality> (xs : 'a []) size =
let s = run (fun () -> xs |> Seq.chunkBySize size |> Seq.map Seq.toArray |> Seq.toArray)
let l = run (fun () -> xs |> List.ofArray |> List.chunkBySize size |> Seq.map Seq.toArray |> Seq.toArray)
let a = run (fun () -> xs |> Array.chunkBySize size |> Seq.map Seq.toArray |> Seq.toArray)
s = a && l = a

[<Test>]
let ``chunkBySize is consistent`` () =
Check.QuickThrowOnFailure chunkBySize<int>
Check.QuickThrowOnFailure chunkBySize<string>
Check.QuickThrowOnFailure chunkBySize<NormalFloat>

let collect<'a> (xs : 'a []) f =
let s = xs |> Seq.collect f
let l = xs |> List.ofArray |> List.collect (fun x -> f x |> List.ofArray)
Expand Down Expand Up @@ -112,28 +147,4 @@ let sort<'a when 'a : comparison> (xs : 'a []) =
let ``sort is consistent`` () =
Check.QuickThrowOnFailure sort<int>
Check.QuickThrowOnFailure sort<string>
Check.QuickThrowOnFailure sort<NormalFloat>


let averageFloat (xs : NormalFloat []) =
let xs = xs |> Array.map float
let s = run (fun () -> xs |> Seq.average)
let l = run (fun () -> xs |> List.ofArray |> List.average)
let a = run (fun () -> xs |> Array.average)
s = a && l = a

[<Test>]
let ``average is consistent`` () =
Check.QuickThrowOnFailure averageFloat

let averageBy (xs : float []) f =
let xs = xs |> Array.map float
let f x = (f x : NormalFloat) |> float
let s = run (fun () -> xs |> Seq.averageBy f)
let l = run (fun () -> xs |> List.ofArray |> List.averageBy f)
let a = run (fun () -> xs |> Array.averageBy f)
s = a && l = a

[<Test>]
let ``averageBy is consistent`` () =
Check.QuickThrowOnFailure averageBy
Check.QuickThrowOnFailure sort<NormalFloat>

0 comments on commit 91e35ef

Please sign in to comment.