Skip to content

Commit

Permalink
findIndexBack and findIndex work in reverse
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Jul 29, 2015
1 parent ae080f7 commit a9bc063
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ let ``findBack is consistent`` () =
Check.QuickThrowOnFailure findBack<string>
Check.QuickThrowOnFailure findBack<NormalFloat>

let findIndex<'a when 'a : equality> (xs : 'a []) index =
let s = run (fun () -> xs |> Seq.findIndex index)
let l = run (fun () -> xs |> List.ofArray |> List.findIndex index)
let a = run (fun () -> xs |> Array.findIndex index)
let findIndex<'a when 'a : equality> (xs : 'a []) predicate =
let s = run (fun () -> xs |> Seq.findIndex predicate)
let l = run (fun () -> xs |> List.ofArray |> List.findIndex predicate)
let a = run (fun () -> xs |> Array.findIndex predicate)
s = a && l = a

[<Test>]
Expand All @@ -250,10 +250,10 @@ let ``findIndex is consistent`` () =
Check.QuickThrowOnFailure findIndex<string>
Check.QuickThrowOnFailure findIndex<NormalFloat>

let findIndexBack<'a when 'a : equality> (xs : 'a []) index =
let s = run (fun () -> xs |> Seq.findIndexBack index)
let l = run (fun () -> xs |> List.ofArray |> List.findIndexBack index)
let a = run (fun () -> xs |> Array.findIndexBack index)
let findIndexBack<'a when 'a : equality> (xs : 'a []) predicate =
let s = run (fun () -> xs |> Seq.findIndexBack predicate)
let l = run (fun () -> xs |> List.ofArray |> List.findIndexBack predicate)
let a = run (fun () -> xs |> Array.findIndexBack predicate)
s = a && l = a

[<Test>]
Expand Down
14 changes: 14 additions & 0 deletions src/fsharp/FSharp.Core.PropertyTests/ListProperties.fs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ let ``findBack and find work in reverse`` () =
Check.QuickThrowOnFailure findBack_and_find<string>
Check.QuickThrowOnFailure findBack_and_find<NormalFloat>

let findIndexBack_and_findIndex<'a when 'a : comparison> (xs : list<'a>) (F (_, predicate)) =
let a = run (fun () -> xs |> List.findIndex predicate)
let b = run (fun () -> xs |> List.rev |> List.findIndexBack predicate)
match a,b with
| Success a, Success b -> a = (xs.Length - b - 1)
| _ -> a = b

[<Test>]
let ``findIndexBack and findIndex work in reverse`` () =
Check.QuickThrowOnFailure findIndexBack_and_findIndex<int>
Check.QuickThrowOnFailure findIndexBack_and_findIndex<string>
Check.QuickThrowOnFailure findIndexBack_and_findIndex<NormalFloat>


let distinct_works_like_set<'a when 'a : comparison> (xs : 'a list) =
let a = List.distinct xs
let b = Set.ofList xs
Expand Down

0 comments on commit a9bc063

Please sign in to comment.