Skip to content

How to check that a collection is sorted #1260

Answered by robstoll
SerVB asked this question in Q&A
Discussion options

You must be logged in to vote

I see, you take another approach than Atrium (and also assertJ IMO) is made for.
The subject of the expectation (i.e. expect(x) => x = subject) should be the result of an operation and not the values you expect.
I think you should take a data driven approach to test your comparable and not only rely on a long list. Much easier to understand your tests and also covers more checks would be something like:

@Test fun `test MyType comparable implementation`() {
  listOf(
    Triple(MyType(1), MyType(2), -1)
    Triple(MyType(2), MyType(2), 0),
    Triple(MyType(2), MyType(3), 1)
  ).forEach { (first, second, compareToResult) ->
    if (compareToResult < 0) {
      expect(first) {
        toBeL…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
5 replies
@SerVB
Comment options

@robstoll
Comment options

@SerVB
Comment options

@robstoll
Comment options

@SerVB
Comment options

Comment options

You must be logged in to vote
1 reply
@SerVB
Comment options

Answer selected by robstoll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants