https://kotlinlang.org logo
#kotest
Title
# kotest
j

Jonathan Olsson

09/19/2023, 8:35 AM
Is it just me or is there no matcher that verifies that a collection is sorted descending?
Copy code
shouldBeMonotonicallyDecreasing
seems to do the work:
Copy code
listOf(10, 9, 8, 8, 6).shouldBeMonotonicallyDecreasing()
Didn't find it in documentation though, or perhaps I am blind? 😛
l

LeoColman

09/19/2023, 12:26 PM
Monotonically is 1 by 1 tho
j

Jonathan Olsson

09/19/2023, 12:27 PM
No, there is a strictlyDecreasing for that purpose. 🤷
l

LeoColman

09/19/2023, 12:27 PM
list.shouldBeSortedBy { transform }
I'd use this guy
Or go
list.reverse().shouldBeSorted()
I see space for a
list.shouldBeSortedDesc()
if you want to open a ticket for that
j

Jonathan Olsson

09/19/2023, 12:33 PM
list.reverse() is what I'd choose in the absence of a desc variant. 🙂
but the monotonicallyDecreasing worked too but not sure whether it is supported (since lacking in documentation).
I can open a question on the github page. 👍
k

Klitos Kyriacou

09/19/2023, 12:51 PM
Remember there's
list.asReversed()
which iterates in reverse order without actually creating a reversed list.
👍 2