binToDec 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e23798a36dd2aa538b7f2b1ecc4b9db202e2a38a
4
- data.tar.gz: 044e39d8106d5821a6f8d844d9c28c9fe2904459
3
+ metadata.gz: f29ce3797c9016ea5929be748b10abf05fedceec
4
+ data.tar.gz: 39c1c194ab47c6b893aaa8e8f6904e7af1e6aca9
5
5
  SHA512:
6
- metadata.gz: 7ef8cf3fb5fb0a0c1b0ad8d89af3ad32275db25d947c421780d04fe2d7ba84beed7d8451855488dd67c6c0f55371b4f796dccc15244b51936c9a18614cd66b11
7
- data.tar.gz: d7cf0eb0da645f21bf32dfcfc7ae3bd6a21024f73645cb9ee073fde40c54adfaa74761646b91488a98c57ff71f92cd4a3c1be5b1eadf0781bed08e387e5e88c0
6
+ metadata.gz: b6f9b4760ec0a41c994f47114f270f398f98c80dfeb17f52204ba6a15bb7f5a31f48aada53620421c63896b3e4c8cdcbcdc29bb293b99eb97a186953548dcaf5
7
+ data.tar.gz: 79be66dd2362227f630391c2f647b36ae2b0c95a8da277fbbe90fea4316164c1cfdec1ffa7404782cd78fbd99fa3f06a1e43517635f9fe21ba78ba1f562abde5
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+ desc "Run tests"
7
+ task :default => :test
data/lib/binToDec.rb CHANGED
@@ -1,14 +1,19 @@
1
1
  module Converter
2
2
  def self.binToDec(arg1)
3
- #TEST FOR BINARY INPUT: my_test_file will be equal to 1 only if binary number is input
3
+
4
+ #code written by Tom Dowling (tomgdow)
5
+
6
+ #TEST FOR BINARY INPUT
7
+ #my_test will be equal to 1 only if arg1 is a binary number
4
8
  my_test = arg1.to_s.split(//).map { |i| i.to_i }.find_all { |value| value > 0 }.inject(:*)
9
+
5
10
  if my_test ==1
6
11
  # Generate a binary number using the "move to the right and double" method
7
12
  result = arg1.to_s.split(//).map { |i| i.to_i }.inject(0) { |accumulator, value| (accumulator + value) * 2 }
8
13
  #The above result will be double what it should be, so need to divide by 2
9
14
  return result/2
10
15
  else
11
- return "!Not a binary number: #{arg1}"
16
+ return "!Not binary: #{arg1}"
12
17
  end
13
18
  end
14
19
  end
@@ -0,0 +1,31 @@
1
+ require 'test/unit'
2
+ require 'binToDec'
3
+ class BinaryTest < Test::Unit::TestCase
4
+
5
+ # Test if a valid binary number gives the correct result
6
+ def test_binary_true
7
+ assert_equal 8,
8
+ Converter.binToDec(1000)
9
+ end
10
+
11
+ # Test if an valid binary number given an incorrect value
12
+ def test_binary_false
13
+ assert_not_equal 9,
14
+ Converter.binToDec(1000)
15
+ end
16
+
17
+ # Test if a invalid binary number gives correct error message
18
+
19
+ def test_non_binary_true
20
+ assert_equal "!Not binary: 2222",
21
+ Converter.binToDec(2222)
22
+ end
23
+
24
+ # Test if a invalid binary number gives correct error message
25
+
26
+ def test_non_binary_false
27
+ assert_not_equal "On the Rails, Matz, and off the Rails. Such is life",
28
+ Converter.binToDec(2222)
29
+ end
30
+
31
+ end # End of Class
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binToDec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - tomgdow
@@ -10,15 +10,18 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2013-12-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A simple gem
13
+ description: An experimental gem
14
14
  email: thomasgdowling@gmail.com
15
15
  executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - Rakefile
19
20
  - lib/binToDec.rb
21
+ - test/test_binToDec.rb
20
22
  homepage: http://rubygems.org/gems/binToDec
21
- licenses: []
23
+ licenses:
24
+ - MIT
22
25
  metadata: {}
23
26
  post_install_message:
24
27
  rdoc_options: []
@@ -39,5 +42,6 @@ rubyforge_project:
39
42
  rubygems_version: 2.1.5
40
43
  signing_key:
41
44
  specification_version: 4
42
- summary: Convert a Binary Number to Decimal
43
- test_files: []
45
+ summary: Convert a Binary Number to Decimal only if input is binary
46
+ test_files:
47
+ - test/test_binToDec.rb