-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
241c889
commit 1653dd9
Showing
2 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#! ruby | ||
require 'test/unit' | ||
require 'base_convert' | ||
|
||
# Just additional tests beyond original tc_number | ||
# for version 3.1. | ||
|
||
class TestKeys < Test::Unit::TestCase | ||
include BaseConvert | ||
|
||
def test_keys_base64 | ||
[BASE64, :base64, :b64].each do |digits| | ||
n = Number.new 63, digits: digits | ||
assert_equal 64, n.base | ||
assert_equal 63, n.to_i | ||
assert_equal '/', n.to_s | ||
assert_equal BASE64, n.digits | ||
end | ||
|
||
[:base64, :b64].each do |base| | ||
n = Number.new 63, base: :base64 | ||
assert_equal 64, n.base | ||
assert_equal 63, n.to_i | ||
assert_equal '/', n.to_s | ||
assert_equal BASE64, n.digits | ||
end | ||
end | ||
|
||
def test_keys_all | ||
(DIGITS.keys + BASE.keys).uniq.each do |key| | ||
digits = DIGITS[key] || G94 | ||
base = BASE[key] | ||
|
||
n = Number.new base: key | ||
assert_equal 0, n.to_i | ||
assert_equal digits[0], n.to_s | ||
assert_equal base, n.base | ||
assert_equal digits, n.digits | ||
|
||
e = Number.new '', base: key | ||
assert_equal 0, e.to_i | ||
assert_equal '', e.to_s | ||
assert_equal base, e.base | ||
assert_equal digits, e.digits | ||
end | ||
|
||
DIGITS.keys.each do |key| | ||
digits = DIGITS[key] | ||
base = BASE[key] | ||
|
||
n = Number.new digits: key | ||
assert_equal 0, n.to_i | ||
assert_equal digits[0], n.to_s | ||
assert_equal base, n.base | ||
assert_equal digits, n.digits | ||
|
||
e = Number.new '', digits: key | ||
assert_equal 0, e.to_i | ||
assert_equal '', e.to_s | ||
assert_equal base, e.base | ||
assert_equal digits, e.digits | ||
end | ||
end | ||
end |