-
Notifications
You must be signed in to change notification settings - Fork 683
Closed
Description
Some of the assertions on collections now look like the following:
infix fun <T> Collection<T>.shouldHaveSize(size: Int): Collection<T> {
...
return this
}
I suggest to change this to
infix fun <T, C : Collection<T>> C.shouldHaveSize(size: Int): C {
...
return this
}
The benefit of this is that you then can do the following:
val (_, _, third) = listOf(1, 2, 3) shouldHaveSize 3
third.shouldBe(3)
A second example:
When
fun <T> Iterable<T>.shouldNotContainDuplicates(): Iterable<T> {
...
return this
}
is changed to
fun <T, I : Iterable<T>> I.shouldNotContainDuplicates(): I {
...
return this
}
This will then allow you to write something like the following in your tests.
class Game(val name: String, players: Iterable<String>) : Iterable<String> by players
val game = Game("Risk", listOf("p1", "p2", "p3", "p4")).shouldNotContainDuplicates()
game.name shouldBe "Risk"
These are only a few examples of functions that could be improved in this way
Metadata
Metadata
Assignees
Labels
No labels