Reputation: 198238
Say I wanna check if the result (an integer) should >=4
and <=15
, I can write such assertion in a ScalaTest test:
assert(num >= 4)
assert(num <= 15)
It works but can be improved in my opinion. Is there any better way to check it in Scalatest?
Upvotes: 3
Views: 4224
Reputation: 4100
Something like this will work (using Matchers
):
val beWithin4and5 = be >= 4 and be <= 5
value should beWithin4And5
Upvotes: 5
Reputation: 2631
You can use a matcher. Checking a range for the numbers you gave don't make much sense but this does for example :
numberExample should be (6 +- 1)
Here the test will fail if numberExample
is lower than 5 or greater than 7.
If what you wanted is either 4 or 5 you can do this :
numberExample should (equal 4 or 5)
Upvotes: 2