You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
infixfun <T, C:Collection<T>> C.shouldHaveSize(size:Int): C {
...
returnthis
}
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> {
...
returnthis
}
is changed to
fun <T, I:Iterable<T>> I.shouldNotContainDuplicates(): I {
...
returnthis
}
This will then allow you to write something like the following in your tests.
classGame(valname: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
The text was updated successfully, but these errors were encountered:
hanszt
changed the title
Addapt assertion extensions for Collections and Iterables to use bounded types
Adapt assertion extensions for Collections and Iterables to use bounded types
Apr 2, 2024
Personally I feel the following code would be confusing to me, as well as to most developers: val game = Game("Risk", listOf("p1", "p2", "p3", "p4")).shouldNotContainDuplicates()
should I ever encounter that, I'd rather refactor it like this:
val game = Game("Risk", listOf("p1", "p2", "p3", "p4"))
game. players.shouldNotContainDuplicates()
So I don't perceive this change as a big improvement.
Some of the assertions on collections now look like the following:
I suggest to change this to
The benefit of this is that you then can do the following:
A second example:
When
is changed to
This will then allow you to write something like the following in your tests.
These are only a few examples of functions that could be improved in this way
The text was updated successfully, but these errors were encountered: