-
-
Save simonbaird/5352062 to your computer and use it in GitHub Desktop.
This file contains 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
# For @echorand :) | |
require 'test/unit' | |
class Float | |
class NoYouCantBecauseMaths < RuntimeError; end | |
def even? | |
raise NoYouCantBecauseMaths unless whole_number? | |
to_i.even? | |
end | |
def odd? | |
raise NoYouCantBecauseMaths unless whole_number? | |
to_i.odd? | |
end | |
private | |
def whole_number? | |
self == to_i | |
end | |
end | |
class FloatEvenOddTest < Test::Unit::TestCase | |
def test_the_madness | |
assert !10.odd? | |
assert 10.even? | |
assert 11.odd? | |
assert !11.even? | |
assert !10.0.odd? | |
assert 10.0.even? | |
assert !11.0.even? | |
assert 11.0.odd? | |
assert !1.234.send(:whole_number?) | |
assert !1.001.send(:whole_number?) | |
assert 1.000.send(:whole_number?) | |
assert_raise(Float::NoYouCantBecauseMaths) { 6.50.even? } | |
assert_raise(Float::NoYouCantBecauseMaths) { 6.50.odd? } | |
end | |
end |
This file contains 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
Loaded suite foo | |
Started | |
. | |
Finished in 0.000342 seconds. | |
1 tests, 13 assertions, 0 failures, 0 errors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment