FSharp.Collections.Immutable icon indicating copy to clipboard operation
FSharp.Collections.Immutable copied to clipboard

`skipWhile` and `takeWhile` are reversed

Open marklam opened this issue 2 years ago • 0 comments

This test compares the behaviour between the methods for ImmutableList and Array

#r "nuget:FSharp.Collections.Immutable"
#r "nuget:Unquote"

open FSharp.Collections.Immutable
open Swensen.Unquote.Assertions

let xs = [ "one"; "two"; "three"; "four" ]
let xsIL = ImmutableList.ofList xs
let xsA = Array.ofList xs

let notThree = (<>) "three"

test <@ (xsIL |> ImmutableList.skipWhile notThree |> ImmutableList.toArray) = (xsA |> Array.skipWhile notThree) @>
test <@ (xsIL |> ImmutableList.takeWhile notThree |> ImmutableList.toArray) = (xsA |> Array.takeWhile notThree) @>
Test failed:

xsIL |> (fun list -> ImmutableList.skipWhile notThree list) |> ImmutableList.toArray = (xsA |> (fun array -> Array.skipWhile notThree array))
seq ["one"; "two"; "three"; "four"] |> (fun list -> ImmutableList.skipWhile notThree list) |> ImmutableList.toArray = ([|"one"; "two"; "three"; "four"|] |> (fun array -> Array.skipWhile notThree array))
seq ["one"; "two"] |> ImmutableList.toArray = [|"three"; "four"|]
[|"one"; "two"|] = [|"three"; "four"|]
false


Test failed:

xsIL |> (fun list -> ImmutableList.takeWhile notThree list) |> ImmutableList.toArray = (xsA |> (fun array -> Array.takeWhile notThree array))
seq ["one"; "two"; "three"; "four"] |> (fun list -> ImmutableList.takeWhile notThree list) |> ImmutableList.toArray = ([|"one"; "two"; "three"; "four"|] |> (fun array -> Array.takeWhile notThree array))
seq ["three"; "four"] |> ImmutableList.toArray = [|"one"; "two"|]
[|"three"; "four"|] = [|"one"; "two"|]
false

marklam avatar Jul 18 '23 15:07 marklam