Skip to content

Commit

Permalink
scan is consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Jul 29, 2015
1 parent 5adfd14 commit add03c7
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,19 @@ let ``rev is consistent`` () =
Check.QuickThrowOnFailure rev<string>
Check.QuickThrowOnFailure rev<NormalFloat>

let scan<'a,'b when 'b : equality> (xs : 'a []) f (start:'b) =
let s = run (fun () -> xs |> Seq.scan f start |> Seq.toArray)
let l = run (fun () -> xs |> List.ofArray |> List.scan f start |> Seq.toArray)
let a = run (fun () -> xs |> Array.scan f start)
s = a && l = a

[<Test>]
let ``scan is consistent`` () =
Check.QuickThrowOnFailure scan<int,int>
Check.QuickThrowOnFailure scan<string,string>
Check.QuickThrowOnFailure scan<float,int>
Check.QuickThrowOnFailure scan<float,string>

let sort<'a when 'a : comparison> (xs : 'a []) =
let s = xs |> Seq.sort
let l = xs |> List.ofArray |> List.sort
Expand Down

0 comments on commit add03c7

Please sign in to comment.