Skip to content

Commit 1fd0718

Browse files
committed
Added some List tests
1 parent 83b0d40 commit 1fd0718

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/fable-library/List.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ let slice (lower: int option) (upper: int option) (xs: 'T list) =
434434
else newList <| xs.Values.GetRange(xs.Count - 1 - upper, upper - lower + 1)
435435

436436
let splitAt i (xs: 'T list) =
437-
if i < 0 then invalidArg "i" LanguagePrimitives.ErrorStrings.InputMustBeNonNegativeString
438-
if i > xs.Count then invalidArg "i" "The input sequence has an insufficient number of elements."
437+
if i < 0 then invalidArg "index" LanguagePrimitives.ErrorStrings.InputMustBeNonNegativeString
438+
if i > xs.Count then invalidArg "index" "The input sequence has an insufficient number of elements."
439439
take i xs, skip i xs
440440

441441
let distinctBy (projection: 'T -> 'Key) (xs: 'T list) ([<Inject>] eq: IEqualityComparer<'Key>) =
@@ -447,8 +447,8 @@ let distinct (xs: 'T list) ([<Inject>] eq: IEqualityComparer<'T>) =
447447

448448
let exactlyOne (xs: 'T list) =
449449
match xs.Count with
450-
| 0 -> invalidArg "list" LanguagePrimitives.ErrorStrings.InputSequenceEmptyString
451450
| 1 -> head xs
451+
| 0 -> invalidArg "list" LanguagePrimitives.ErrorStrings.InputSequenceEmptyString
452452
| _ -> invalidArg "list" "Input list too long"
453453

454454
let groupBy (projection: 'T -> 'Key) (xs: 'T list)([<Inject>] eq: IEqualityComparer<'Key>): ('Key * 'T list) list =

tests/Main/ListTests.fs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,26 @@ module List =
4242

4343
let tests =
4444
testList "Lists" [
45-
// TODO: Empty lists may be represented as null, make sure they don't conflict with None
4645
testCase "Some [] works" <| fun () ->
4746
let xs: int list option = Some []
4847
let ys: int list option = None
4948
Option.isSome xs |> equal true
5049
Option.isNone ys |> equal true
5150

51+
testCase "List equality works" <| fun () ->
52+
let xs = [1;2;3]
53+
let ys = [1;2;3]
54+
let zs = [1;4;3]
55+
xs = ys |> equal true
56+
xs = zs |> equal false
57+
58+
testCase "List comparison works" <| fun () ->
59+
let xs = [1;2;3]
60+
let ys = [1;2;3]
61+
let zs = [1;4;3]
62+
xs < ys |> equal false
63+
xs < zs |> equal true
64+
5265
testCase "Pattern matching with lists works" <| fun () ->
5366
match [] with [] -> true | _ -> false
5467
|> equal true
@@ -302,9 +315,9 @@ let tests =
302315
|> List.sum |> equal 9
303316

304317
testCase "List.rev works" <| fun () ->
305-
let xs = [1; 2]
318+
let xs = [1; 2; 3]
306319
let ys = xs |> List.rev
307-
equal 2 ys.Head
320+
equal 3 ys.Head
308321

309322
testCase "List.scan works" <| fun () ->
310323
let xs = [1; 2; 3; 4]

0 commit comments

Comments
 (0)