-
-
Save liango2/9eba6502b8bdd73dd975 to your computer and use it in GitHub Desktop.
Scala preconditions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val rnd = Math.random() | |
| val n = Math.abs(rnd) | |
| assert(n > 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val speedFromSensor: Double = ... | |
| assume(speedFromSensor >= 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def doublePositive(n: Int): Int = { | |
| require(n > 0) | |
| n * 2 // logic | |
| } ensuring(n => n >= 0 && n % 2 == 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment