Created
May 24, 2017 21:08
-
-
Save drusepth/1972c40fd030ce3ef06e4e4dc9b22eaa to your computer and use it in GitHub Desktop.
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
| # Standard function | |
| def divide param_x, param_y | |
| return Infinity if param_y.zero? | |
| param_x.to_f / param_y.to_f | |
| end | |
| # Doable implementation with tests block in-function | |
| def divide_with_tests param_x, param_y | |
| return Infinity if param_y.zero? | |
| param_x / param_y.to_f | |
| tests do | |
| assert self(0, 3) == 0 | |
| assert self(6, 3) == 2 | |
| assert self(3, 0) == Infinity | |
| end | |
| end | |
| # Ideal implementation with tests in a separate block than method code | |
| def divide_with_tests param_x, param_y | |
| return Infinity if param_y.zero? | |
| param_x / param_y.to_f | |
| tests | |
| assert self(0, 3) == 0 | |
| assert self(6, 3) == 2 | |
| assert self(3, 0) == Infinity | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment