binToDec 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/binToDec.rb +1 -1
- data/test/test_binToDec.rb +12 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a51651cd7f62b2e423961e82c36a5c8cd5a796ef
|
4
|
+
data.tar.gz: fd354f842b69a530f9c1b312c4a4637622141ab2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bf49af41382fae8994266b0a93724912d58914a3f2139b6e57c245442f2c6c82c49e8474f959d6fe5da47ce1f1fdab3673444caaa5e8e5c18c9ef5e020bc36e
|
7
|
+
data.tar.gz: b626d9c48c613b5a0d6d89f51387e98bf3da8eaf1d8af9b1f0195a6c40b88098fe62fb1a49a059ee60a2f9df9170e6cb1e8bcddf3994e989b6e529ebab8f0cd3
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
**binToDec** is written in Ruby, and converts a binary number to a decimal only if
|
5
5
|
the argument is binary.
|
6
|
-
|
6
|
+
If the argument is not binary, an exception is raised.
|
7
7
|
It should be considered an experimental gem.
|
8
8
|
|
9
9
|
## Installation
|
@@ -32,7 +32,7 @@ The program uses the following test to determine if the input is binary:
|
|
32
32
|
`arg1.to_s.split(//).map { |i| i.to_i }.find_all { |value| value > 0 }.inject(:*)`
|
33
33
|
|
34
34
|
|
35
|
-
|
35
|
+
If the test passes, the program uses the following code to convert the input (arg1) to binary.
|
36
36
|
|
37
37
|
`arg1.to_s.split(//).map { |i| i.to_i }.inject(0) { |accumulator, value| (accumulator + value) * 2 }`
|
38
38
|
|
data/lib/binToDec.rb
CHANGED
data/test/test_binToDec.rb
CHANGED
@@ -14,18 +14,20 @@ class BinaryTest < Test::Unit::TestCase
|
|
14
14
|
Converter.binToDec(1000)
|
15
15
|
end
|
16
16
|
|
17
|
-
# Test if
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
# Test if an invalid binary number raises an exception
|
18
|
+
def test_non_binary_true
|
19
|
+
|
20
|
+
assert_raise RuntimeError do
|
21
|
+
Converter.binToDec(2222)
|
22
|
+
end
|
22
23
|
end
|
23
24
|
|
24
|
-
# Test if
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
# Test if an valid binary number does not raise an exception
|
26
|
+
def test_non_binary_false
|
27
|
+
|
28
|
+
assert_nothing_raised RuntimeError do
|
29
|
+
Converter.binToDec(1000)
|
30
|
+
end
|
29
31
|
end
|
30
32
|
|
31
33
|
end # End of Class
|