bases 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/bases/algorithms.rb +2 -5
- data/lib/bases/number.rb +1 -1
- data/lib/bases/version.rb +1 -1
- data/test/number_test.rb +0 -17
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09949ca6bf4b1e6442e726203a2aeae222614d51
|
4
|
+
data.tar.gz: 0b4081d84df9f903203b62ff9288dc7ed3d96463
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfbe2cd859cd229b9120afa16da456e2d888e9c75842cf3475713ab2489ed7bdaeec905f69719893d3c5531a022c2e32e7fc1c0c324a74094c5faef592c592ec
|
7
|
+
data.tar.gz: 13606dcf2dfcd180ef186412717ac358b230dfbaa1f00099eb066c049f1db5e541b767e3600d71651b63cd0b2e7df85a444ec97b401209b2ddd870045276705b
|
data/.gitignore
CHANGED
data/lib/bases/algorithms.rb
CHANGED
@@ -33,11 +33,8 @@ module Bases::Algorithms
|
|
33
33
|
# The numeric base is the number of digits in the source base.
|
34
34
|
numeric_base = source_base.count
|
35
35
|
|
36
|
-
digits_ary.
|
37
|
-
|
38
|
-
# in the `@source_base` array.
|
39
|
-
digit_value_in_base10 = source_base.find_index(digit)
|
40
|
-
value + (digit_value_in_base10 * (numeric_base**position))
|
36
|
+
digits_ary.reduce(0) do |acc, digit|
|
37
|
+
source_base.find_index(digit) + numeric_base * acc
|
41
38
|
end
|
42
39
|
end
|
43
40
|
end
|
data/lib/bases/number.rb
CHANGED
data/lib/bases/version.rb
CHANGED
data/test/number_test.rb
CHANGED
@@ -104,23 +104,6 @@ class NumberTest < Minitest::Test
|
|
104
104
|
assert_equal 0, n('').in_base(10).to_i
|
105
105
|
end
|
106
106
|
|
107
|
-
def test_bignums_are_supported
|
108
|
-
value = n('//////////////').in_base(BASE64).to_i
|
109
|
-
assert_instance_of Bignum, value
|
110
|
-
|
111
|
-
# MD5 are hex numbers, very big ones too!
|
112
|
-
hex = Digest::MD5.hexdigest('foo bar')
|
113
|
-
|
114
|
-
# They convert easily to bignums...
|
115
|
-
assert_instance_of Bignum, n(hex).in_base(16).to_i
|
116
|
-
|
117
|
-
# ...and to base 3 numbers (check that the resulting number is composed of
|
118
|
-
# only the 0, 1 and 2 digits.
|
119
|
-
binary_digits = n(hex).in_base(16).to_base(3)
|
120
|
-
.split('').uniq.map(&:to_i).sort
|
121
|
-
assert_equal [0, 1, 2], binary_digits
|
122
|
-
end
|
123
|
-
|
124
107
|
def test_to_base_outputting_an_array
|
125
108
|
assert_equal %w(b a b a), n(10).to_base([:a, :b], array: true)
|
126
109
|
assert_equal %w(1 0), n(2).to_base(2, array: true)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bases
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrea Leopardi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
requirements: []
|
137
137
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.4.5
|
139
139
|
signing_key:
|
140
140
|
specification_version: 4
|
141
141
|
summary: Convert bases like a mofo.
|
@@ -145,4 +145,3 @@ test_files:
|
|
145
145
|
- test/monkeypatches_test.rb
|
146
146
|
- test/number_test.rb
|
147
147
|
- test/test_helper.rb
|
148
|
-
has_rdoc:
|