Permalink
Browse files

add Key-Index validation for STANDARD_CHARS

  • Loading branch information...
1 parent be3a2d3 commit f06afa9e8f22ca4e6235337f6f1b84201febd9f1 @kachick committed May 7, 2012
Showing with 5 additions and 1 deletion.
  1. +1 −1 lib/integer/base/standard_chars.rb
  2. +4 −0 test/test_integer-base.rb
@@ -3,7 +3,7 @@ class Integer; module Base
# {1 => :"0",
# 2 => :"0", :"1"}
# 36 => :"0", :"1", ... , :"35"}
- STANDARD_CHARS = {}.tap {|standards|
+ STANDARD_CHARS = Hash.new{|*|raise KeyError}.tap {|standards|
1.upto 10 do |n|
standards[n] = ('0'..((n - 1).to_s)).map(&:to_sym).freeze
end
@@ -78,6 +78,10 @@ def test_standards
assert_equal('101'.to_i(27), Integer::Base.parse('101', Integer::Base::STANDARD_CHARS[27]))
assert_equal('11'.to_i(36), Integer::Base.parse('11', Integer::Base::STANDARD_CHARS[36]))
assert_equal('101'.to_i(36), Integer::Base.parse('101', Integer::Base::STANDARD_CHARS[36]))
+
+ assert_raises KeyError do
+ Integer::Base::STANDARD_CHARS[37]
+ end
end
def test_upper36

0 comments on commit f06afa9

Please sign in to comment.