Skip to content

Commit

Permalink
tryFindIndexBack and tryIndexFind work in reverse
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Jul 29, 2015
1 parent 675252d commit 38b6406
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/fsharp/FSharp.Core.PropertyTests/ListProperties.fs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,19 @@ let ``tryFindBack and tryFind work in reverse`` () =
Check.QuickThrowOnFailure tryFindBack_and_tryFind<string>
Check.QuickThrowOnFailure tryFindBack_and_tryFind<NormalFloat>

let tryFindIndexBack_and_tryFindIndex<'a when 'a : comparison> (xs : list<'a>) predicate =
let a = xs |> List.tryFindIndexBack predicate
let b = xs |> List.rev |> List.tryFindIndex predicate
match a,b with
| Some a, Some b -> a = (xs.Length - b - 1)
| _ -> a = b

[<Test>]
let ``tryFindIndexBack and tryIndexFind work in reverse`` () =
Check.QuickThrowOnFailure tryFindIndexBack_and_tryFindIndex<int>
Check.QuickThrowOnFailure tryFindIndexBack_and_tryFindIndex<string>
Check.QuickThrowOnFailure tryFindIndexBack_and_tryFindIndex<NormalFloat>

let rev<'a when 'a : comparison> (xs : list<'a>) =
let list = System.Collections.Generic.List<_>()
for x in xs do
Expand Down

0 comments on commit 38b6406

Please sign in to comment.