Skip to content

Commit 91d7a00

Browse files
Merge pull request #248 from fsprojects/copilot/sub-pr-229
Strengthen sortBy/maxBy/minBy tests with two distinct projections
2 parents 9c267f1 + 9d2fcde commit 91d7a00

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

tests/FSharpx.Collections.Tests/NonEmptyListTests.fs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,20 @@ module NonEmptyListTests =
353353

354354
testPropertyWithConfig
355355
config10k
356-
"sortBy produces sorted output"
356+
"sortBy with identity projection produces ascending sorted output"
357357
(Prop.forAll(neListOfInt())
358358
<| fun nel ->
359359
let sorted = NonEmptyList.sortBy id nel |> NonEmptyList.toList
360-
let expected = nel |> NonEmptyList.toList |> List.sort
360+
let expected = nel |> NonEmptyList.toList |> List.sortBy id
361+
sorted = expected)
362+
363+
testPropertyWithConfig
364+
config10k
365+
"sortBy with negation projection produces descending sorted output"
366+
(Prop.forAll(neListOfInt())
367+
<| fun nel ->
368+
let sorted = NonEmptyList.sortBy (fun x -> -x) nel |> NonEmptyList.toList
369+
let expected = nel |> NonEmptyList.toList |> List.sortBy (fun x -> -x)
361370
sorted = expected)
362371

363372
testPropertyWithConfig
@@ -371,12 +380,24 @@ module NonEmptyListTests =
371380

372381
testPropertyWithConfig
373382
config10k
374-
"maxBy returns maximum element"
383+
"maxBy with identity projection returns maximum element"
375384
(Prop.forAll(neListOfInt())
376385
<| fun nel -> NonEmptyList.maxBy id nel = (nel |> NonEmptyList.toList |> List.max))
377386

378387
testPropertyWithConfig
379388
config10k
380-
"minBy returns minimum element"
389+
"maxBy with negation projection returns minimum element"
390+
(Prop.forAll(neListOfInt())
391+
<| fun nel -> NonEmptyList.maxBy (fun x -> -x) nel = (nel |> NonEmptyList.toList |> List.min))
392+
393+
testPropertyWithConfig
394+
config10k
395+
"minBy with identity projection returns minimum element"
396+
(Prop.forAll(neListOfInt())
397+
<| fun nel -> NonEmptyList.minBy id nel = (nel |> NonEmptyList.toList |> List.min))
398+
399+
testPropertyWithConfig
400+
config10k
401+
"minBy with negation projection returns maximum element"
381402
(Prop.forAll(neListOfInt())
382-
<| fun nel -> NonEmptyList.minBy id nel = (nel |> NonEmptyList.toList |> List.min)) ]
403+
<| fun nel -> NonEmptyList.minBy (fun x -> -x) nel = (nel |> NonEmptyList.toList |> List.max)) ]

0 commit comments

Comments
 (0)