Created
January 27, 2011 18:01
-
-
Save kastner/798901 to your computer and use it in GitHub Desktop.
numberish.rb
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
class Numberish | |
def self.convert(input) | |
if input.to_i > 0 && input.to_i.to_s == input | |
return input.to_i | |
else | |
return input | |
end | |
end | |
end | |
if $0 == __FILE__ | |
require 'test/unit' | |
class TestNumberish < Test::Unit::TestCase | |
def test_1 | |
assert_equal 1, Numberish.convert("1") | |
end | |
def test_plus_1 | |
assert_equal "+1", Numberish.convert("+1") | |
end | |
def test_auto | |
assert_equal "auto", Numberish.convert("auto") | |
end | |
def test_negative_1 | |
assert_equal "-1", Numberish.convert("-1") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment