roman_numbers 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a63442949e877487bc70a6f74548a2c5656efc57
4
- data.tar.gz: d1e26b50ff30a72c472d0a7f19cdb329f6e0a648
3
+ metadata.gz: 154520d9143e2297d9ca4437b70f1eb36de4cf57
4
+ data.tar.gz: 6764dcb2c45acd10300909022016e5c400708ef8
5
5
  SHA512:
6
- metadata.gz: 6519d9e809a9ed4baead73af212e2200b7a182cee544fb358e27f7eaf72ee91de9ca5c6c0b86b5e8a4b5e686cc504ef25b8b96882ce0a56fa6b47ee9ebf29cec
7
- data.tar.gz: 10c0319e772228553c9e3d58b2d2218d7c17900ad518d90c622b94298e5a8b8f526501a7af60bfad9c2fefa5186cb6aa5c3050f5b4ad0d19792a2fdcf80feb08
6
+ metadata.gz: 2c0d2b3fb03daaed1778de72df60e8f94f1496870073a3111998f1fcec225e9366d8830fedfa4f1e966d8f7a16eaf1f7c55d42d680cc351f15e6e131704f12ee
7
+ data.tar.gz: 1bb43845ca739c2ebded476deb5d8088a199458edbdd1797e3675c1856cc3946c2b95ac6d51583d710b1bb69ef8a744dbff9b1110fdf27fa3e26a7459e736dd4
@@ -1,3 +1,3 @@
1
1
  module RomanNumbers
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
data/spec/helpers.rb CHANGED
@@ -1,28 +1,47 @@
1
1
  module Helpers
2
- def self.valid_inputs
2
+ def input_set_1
3
3
  [
4
- [1, 'I'],
5
- [5, 'V'],
6
- [10, 'X'],
7
- [50, 'L'],
8
- [100, 'C'],
9
- [500, 'D'],
10
- [1000, 'M'],
11
- [4, 'IV'],
12
- [9, 'IX'],
13
- [40, 'XL'],
14
- [90, 'XC'],
15
- [400, 'CD'],
16
- [900, 'CM'],
17
- [207, 'CCVII'],
18
- [1066, 'MLXVI'],
19
- [44, 'XLIV'],
20
- [49, 'XLIX'],
21
- [904, 'CMIV'],
22
- [944, 'CMXLIV'],
23
- [1904, 'MCMIV'],
24
- [1944, 'MCMXLIV'],
25
- [3999, 'MMMCMXCIX'],
4
+ {integer: 39, roman: 'XXXIX'},
5
+ {integer: 390, roman: 'CCCXC'},
26
6
  ]
27
7
  end
8
+ module_function :input_set_1
9
+ def input_set_2
10
+ [
11
+ {integer: 4, roman: 'IV'},
12
+ {integer: 9, roman: 'IX'},
13
+ {integer: 40, roman: 'XL'},
14
+ {integer: 90, roman: 'XC'},
15
+ {integer: 400, roman: 'CD'},
16
+ {integer: 900, roman: 'CM'},
17
+ ]
18
+ end
19
+ module_function :input_set_2
20
+ def valid_inputs
21
+ [
22
+ {integer: 1, roman: 'I'},
23
+ {integer: 5, roman: 'V'},
24
+ {integer: 10, roman: 'X'},
25
+ {integer: 50, roman: 'L'},
26
+ {integer: 100, roman: 'C'},
27
+ {integer: 500, roman: 'D'},
28
+ {integer: 1000, roman: 'M'},
29
+ {integer: 4, roman: 'IV'},
30
+ {integer: 9, roman: 'IX'},
31
+ {integer: 40, roman: 'XL'},
32
+ {integer: 90, roman: 'XC'},
33
+ {integer: 400, roman: 'CD'},
34
+ {integer: 900, roman: 'CM'},
35
+ {integer: 207, roman: 'CCVII'},
36
+ {integer: 1066, roman: 'MLXVI'},
37
+ {integer: 44, roman: 'XLIV'},
38
+ {integer: 49, roman: 'XLIX'},
39
+ {integer: 904, roman: 'CMIV'},
40
+ {integer: 944, roman: 'CMXLIV'},
41
+ {integer: 1904, roman: 'MCMIV'},
42
+ {integer: 1944, roman: 'MCMXLIV'},
43
+ {integer: 3999, roman: 'MMMCMXCIX'},
44
+ ]
45
+ end
46
+ module_function :valid_inputs
28
47
  end
@@ -1,55 +1,95 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
3
  module RomanNumbers
4
- describe RomanNumber do # EXAMPLE GROUP
4
+ describe RomanNumber do
5
+
6
+ $invalid_input_error = InvalidInputError
5
7
 
6
8
  before(:each) do
7
9
  @roman_number = RomanNumber.new(1)
8
10
  end
9
11
 
10
- describe '#convert_arabic_to_roman' do
11
- context 'For Valid Input' do
12
- Helpers.valid_inputs.each do |exp_input, exp_output|
13
- it %Q{returns #{exp_output} for #{exp_input} as input} do
14
- RomanNumber.new(exp_input).convert_decimal_to_roman.should == exp_output
12
+ describe '#convert_decimal_to_roman' do
13
+ shared_examples_for "works_with_valid_integral_roman_input_collection" do |array|
14
+ # Note: here array is array of hashes
15
+ array.each do |hsh|
16
+ it %Q{returns #{hsh[:integer]} for #{hsh[:roman]} as input} do
17
+ RomanNumber.new(hsh[:integer]).convert_decimal_to_roman.should == hsh[:roman]
15
18
  end
16
19
  end
17
20
  end
18
- context 'For Invalid Input' do
19
- exp_output = InvalidInputError
20
- [
21
- 4000, 0, -10, '10'
22
- ].each do |exp_input|
23
- it %Q{raises #{exp_output} for #{exp_input} as input} do
21
+
22
+ shared_examples_for "raises_error_on_invalid_roman_input_collection" do |array|
23
+ # Note: here array is array of integers
24
+ array.each do |integral_elem|
25
+ it %Q{raises #{$invalid_input_error} for #{integral_elem} as input} do
26
+ expect {
27
+ RomanNumber.new(integral_elem).convert_decimal_to_roman
28
+ }.to raise_error($invalid_input_error)
29
+ end
30
+ end
31
+ end
32
+
33
+ context %q(Symbols 'I', 'X', 'C', and 'M' cannot be repeated more than three times in succession) do
34
+ it_behaves_like "raises_error_on_invalid_roman_input_collection", %w(VIIII IIIIV XXXXI XXXXC CCCCX XCCCC MMMMC)
35
+ end
36
+
37
+ context %q(Symbols 'I', 'X', 'C', and 'M' can be repeated 4 times if 3rd and 4th are separated by smaller value) do
38
+ it_behaves_like "works_with_valid_integral_roman_input_collection", Helpers.input_set_1
39
+ end
40
+
41
+ context %q(Symbols 'D', 'L', 'V' can never be repeated in succession) do
42
+ it_behaves_like "raises_error_on_invalid_roman_input_collection", %w(DD DDC LL LLX VV VVI)
43
+ end
44
+
45
+ context %Q(Symbol 'I' can be subtrated from 'V' and 'X', and
46
+ Symbol 'L' can be subtracted from 'L' and 'C', and
47
+ Symbol 'C' can be subtracted from 'D' and 'M') do
48
+ it_behaves_like "works_with_valid_integral_roman_input_collection", Helpers.input_set_2
49
+ end
50
+
51
+ context %Q(Symbol 'I' can be subtrated from 'V' and 'X' only, and
52
+ Symbol 'X' can be subtracted from 'L' and 'C' only, and
53
+ Symbol 'C' can be subtracted from 'D' and 'M' only) do
54
+ it_behaves_like "raises_error_on_invalid_roman_input_collection", %w(IL IC ID IM XD XM)
55
+ end
56
+
57
+ context 'For Following Valid Inputs' do
58
+ it_behaves_like "works_with_valid_integral_roman_input_collection", Helpers.valid_inputs
59
+ end
60
+
61
+ context 'For Following Invalid Input' do
62
+ [4000, 0, -10, '10'].each do |exp_input|
63
+ it %Q{raises #{$invalid_input_error} for #{exp_input} as input} do
24
64
  expect {
25
65
  RomanNumber.new(exp_input).convert_decimal_to_roman
26
- }.to raise_error(exp_output)
66
+ }.to raise_error($invalid_input_error)
27
67
  end
28
68
  end
29
69
  end
30
70
  end
31
71
 
32
- describe '#convert_roman_to_arabic' do
72
+ describe '#convert_roman_to_decimal' do
33
73
  context 'For Valid Input' do
34
- Helpers.valid_inputs.each do |exp_output, exp_input|
35
- it %Q{returns #{exp_output} for #{exp_input} as input} do
36
- RomanNumber.new(exp_input).convert_roman_to_decimal.should == exp_output
74
+ Helpers.valid_inputs.each do |hsh|
75
+ it %Q{returns #{hsh[:roman]} for #{hsh[:integer]} as input} do
76
+ RomanNumber.new(hsh[:roman]).convert_roman_to_decimal.should == hsh[:integer]
37
77
  end
38
78
  end
39
79
  end
80
+
40
81
  context 'For Invalid Input' do
41
- exp_output = InvalidInputError
42
- %w(ABCDE CCCCVII CCVVVVI XXM).each do |exp_input|
43
- it %Q{raises #{exp_output} for #{exp_input} as input} do
82
+ %w(ABCDE CCCCVII CCVVVVI).each do |exp_input|
83
+ it %Q{raises #{$invalid_input_error} for #{exp_input} as input} do
44
84
  expect {
45
85
  RomanNumber.new(exp_input).convert_roman_to_decimal
46
- }.to raise_error(exp_output)
86
+ }.to raise_error($invalid_input_error)
47
87
  end
48
88
  end
49
89
  end
50
90
  end
51
91
 
52
- describe 'PRIVATE_INTERFACE' do
92
+ describe 'PRIVATE_INTERFACE (for developer)' do
53
93
  describe '#largest_repeatable_element' do
54
94
  # set 1
55
95
  [
@@ -93,7 +133,6 @@ module RomanNumbers
93
133
  end
94
134
  end
95
135
  end
96
-
97
136
  end
98
137
  end
99
138
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roman_numbers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Munish Goyal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-05 00:00:00.000000000 Z
11
+ date: 2015-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler