Решение на Четвърта задача - Unit тестване от Иво Яков

Обратно към всички решения

Към профила на Иво Яков

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 1 неуспешни тест(а)

Код

RSpec.describe 'Version' do
describe '#initialize' do
it 'can initialize with a string argument' do
expect { Version.new('1.2.3') }.not_to raise_error
expect { Version.new('') }.not_to raise_error
end
it 'can initialize with no arguments' do
expect { Version.new }.not_to raise_error
end
it 'can initialize with Object of type Version as argument' do
expect { Version.new(Version.new('1.2')) }.not_to raise_error
end
it 'can find invalid argument empty string' do
expect { Version.new(' ') }.to raise_error(ArgumentError)
end
it 'can find invalid argument string that has letters' do
expect { Version.new('0.a') }.to raise_error(ArgumentError)
expect { Version.new('f.0') }.to raise_error(ArgumentError)
expect { Version.new('0.1.1f') }.to raise_error(ArgumentError)
end
it 'can find invalid argument string with negative numbers' do
expect { Version.new('0.0.-12') }.to raise_error(ArgumentError)
expect { Version.new('-1') }.to raise_error(ArgumentError)
end
it 'can find invalid argument string with missing numbers' do
expect { Version.new('0..3') }.to raise_error(ArgumentError)
expect { Version.new('.3') }.to raise_error(ArgumentError)
end
end
let(:vers) { Version.new }
let(:vers0) { Version.new('0') }
let(:vers1) { Version.new('1.0.0') }
let(:vers2) { Version.new('2.0.0') }
let(:vers0_1) { Version.new('0.1') }
let(:vers0_2) { Version.new('0.2') }
let(:vers0_1_123) { Version.new('0.1.123.0') }
let(:vers0_1_124) { Version.new('0.1.124.0') }
describe '#Operators <=>' do
describe 'Operator <' do
it 'can check true cases' do
expect(vers1).to be < vers2
expect(vers0_1).to be < vers0_2
expect(vers0_1_123).to be < vers0_1_124
expect(vers0_1).to be < vers0_1_123
end
it 'can check false cases' do
expect(vers2).to_not be < vers1
expect(vers0_2).to_not be < vers0_1
expect(vers0_1_124).to_not be < vers0_1_123
expect(vers0_1_124).to_not be < vers0_1_124
end
end
describe 'Operator >' do
it 'can check true cases' do
expect(vers2).to be > vers1
expect(vers0_2).to be > vers0_1
expect(vers0_1_124).to be > vers0_1_123
expect(vers0_1_123).to be > vers0_1
end
it 'can check false cases' do
expect(vers1).to_not be > vers2
expect(vers0_1).to_not be > vers0_1_124
expect(vers0_1_123).to_not be > vers0_1_124
expect(vers0_1_124).to_not be > vers0_1_124
end
end
describe 'Operator >=' do
it 'can check true cases' do
expect(vers0_1_123).to be >= vers0_1_123
expect(vers0_1_124).to be >= vers0_1_123
expect(vers0_1_123).to be >= vers0_1
end
it 'can check false cases' do
expect(vers0_1_123).to_not be >= vers0_1_124
expect(vers0_1).to_not be >= vers0_1_123
end
end
describe 'Operator <=' do
it 'can check true cases' do
expect(vers0_1_123).to be <= vers0_1_123
expect(vers0_1_123).to be <= vers0_1_124
expect(vers0_1).to be <= vers0_1_123
end
it 'can check false cases' do
expect(vers0_1_124).to_not be <= vers0_1_123
expect(vers0_1_123).to_not be <= vers0_1
end
end
describe 'Operator ==' do
it 'can check true cases' do
expect(vers).to be == vers0
expect(vers1).to be == vers1
expect(vers0_1).to be == vers0_1
expect(vers0_1_123).to be == vers0_1_123
end
it 'can check false cases' do
expect(vers1).to_not be == vers2
expect(vers2).to_not be == vers1
expect(vers0_1).to_not be == vers0_2
expect(vers0_2).to_not be == vers0_1
expect(vers0_1_123).to_not be == vers0_1_124
expect(vers0_1_124).to_not be == vers0_1_123
expect(vers1).to_not be == vers0_1
end
end
end
describe '#to_s' do
it 'can work without errors' do
expect { vers0.to_s }.not_to raise_error
end
it 'can parse zero version' do
expect(vers0.to_s).to eq('')
end
it 'can parse and canonize' do
expect(vers1.to_s).to eq('1')
end
it 'can parse with subversions and canonize' do
expect(vers0_1_123.to_s).to eq('0.1.123')
end
end
describe '#components' do
it 'can work without errors' do
expect { vers0_1.components(3) }.not_to raise_error
end
it 'does not allow version data modification' do
a = vers0_1_123.components
a[1] = 12
expect(vers0_1_123.components[1]).not_to eq(12)
end
it 'can get components with single version number' do
expect(vers1.components).to eq [1]
end
it 'can get components with subversions' do
expect(vers0_1.components).to eq [0, 1]
end
it 'can get components with multiple version digits' do
expect(vers0_1_123.components).to eq [0, 1, 123]
end
it 'can get N components with single version number' do
expect(vers1.components(1)).to eq [1]
end
it 'can get N components with subversions' do
expect(vers0_1.components(2)).to eq [0, 1]
end
it 'can get N components with multiple version digits' do
expect(vers0_1_123.components(3)).to eq [0, 1, 123]
end
it 'can get N components that are more' do
expect(vers0_1.components(3)).to eq [0, 0, 1]
end
end
describe 'Version::Range' do
describe '#initialize' do
it 'can initialize with Object arguments' do
expected = expect do
Version::Range.new(Version.new('0.1'), Version.new('2'))
end
expected.not_to raise_error
end
it 'can initialize with String arguments' do
expect { Version::Range.new('0.1', '1.2') }.not_to raise_error
end
it 'can initialize with mixed type arguments' do
expected = expect do
Version::Range.new(Version.new('0.1'), '1.2')
end
expected.not_to raise_error
end
it 'can find invalid argument empty string' do
expect { Version::Range.new(' ', ' ') }.to raise_error(ArgumentError)
end
it 'can find invalid argument string that has letters' do
expect { Version::Range.new('1', '0.f') }.to raise_error(ArgumentError)
expect { Version::Range.new('a.0', '1f') }.to raise_error(ArgumentError)
expect { Version::Range.new('f', '') }.to raise_error(ArgumentError)
end
it 'can find invalid argument string with negative numbers' do
expect { Version::Range.new('0', '-12') }.to raise_error(ArgumentError)
expect { Version::Range.new('', '0.-12') }.to raise_error(ArgumentError)
end
it 'can find invalid argument string with missing numbers' do
expect { Version::Range.new('', '0..3') }.to raise_error(ArgumentError)
expect { Version::Range.new('', '.3') }.to raise_error(ArgumentError)
end
end
let(:range01_to_2) do
Version::Range.new(Version.new('0.1'), Version.new('2'))
end
let(:range0_to_01) do
Version::Range.new(Version.new('0'), Version.new('0.1'))
end
describe '#include?' do
it 'can work without errors' do
expect { range01_to_2.include? Version.new('1') }.not_to raise_error
end
it 'can work with string as argument' do
expect((range01_to_2.include? '1.2')).to be true
end
it 'can find invalid argument empty string' do
expect { range01_to_2.include? ' ' }.to raise_error(ArgumentError)
end
it 'can find invalid argument string that has letters' do
expect { range01_to_2.include? '0.g' }.to raise_error(ArgumentError)
expect { range01_to_2.include? 'z.0' }.to raise_error(ArgumentError)
expect { range01_to_2.include? '0.1.1g' }.to raise_error(ArgumentError)
end
it 'can find invalid argument string with negative numbers' do
expect { range01_to_2.include? '0.-12' }.to raise_error(ArgumentError)
expect { range01_to_2.include? '-1' }.to raise_error(ArgumentError)
end
it 'can find invalid argument string with missing numbers' do
expect { range01_to_2.include? '.3' }.to raise_error(ArgumentError)
expect { range01_to_2.include? '0..3' }.to raise_error(ArgumentError)
end
context 'with object as argument' do
it 'can check supranges' do
expect((range01_to_2.include? Version.new('1'))).to be true
end
it 'can check if at start of ranges' do
expect((range01_to_2.include? Version.new('0'))).to be false
expect((range01_to_2.include? Version.new('0.1'))).to be true
expect((range01_to_2.include? Version.new('0.2'))).to be true
end
it 'can check if at end of ranges' do
expect((range01_to_2.include? Version.new('1.9'))).to be true
expect((range01_to_2.include? Version.new('2'))).to be false
expect((range01_to_2.include? Version.new('2.1'))).to be false
end
it 'can check deep subranges' do
expect((range01_to_2.include? Version.new('1.2.3.4'))).to be true
end
it 'can check ranges that start with zero' do
expect((range0_to_01.include? Version.new('0'))).to be true
expect((range0_to_01.include? Version.new('0.0.0.1'))).to be true
end
end
context 'with string as argument' do
it 'can check supranges' do
expect((range01_to_2.include? '1')).to be true
end
it 'can check if at start of ranges' do
expect((range01_to_2.include? '0')).to be false
expect((range01_to_2.include? '0.1')).to be true
expect((range01_to_2.include? '0.2')).to be true
end
it 'can check if at end of ranges' do
expect((range01_to_2.include? '1.9')).to be true
expect((range01_to_2.include? '2')).to be false
expect((range01_to_2.include? '2.1')).to be false
end
it 'can check deep subranges' do
expect((range01_to_2.include? '1.2.3.4')).to be true
end
it 'can check ranges that start with zero' do
expect((range0_to_01.include? '0')).to be true
expect((range0_to_01.include? '0.0.0.1')).to be true
end
end
end
describe '#to_a' do
it 'can work without errors' do
expect { range0_to_01.to_a }.not_to raise_error
end
it 'can give first elements of range' do
expect(range0_to_01.to_a[0]).to eq(Version.new)
expect(range0_to_01.to_a[1]).to eq(Version.new('0.0.1'))
end
it 'can give last elements of subrange' do
expect(range0_to_01.to_a[8]).to eq(Version.new('0.0.8'))
expect(range0_to_01.to_a[9]).to eq(Version.new('0.0.9'))
expect(range0_to_01.to_a[10]).to eq(nil)
end
it 'can give last elements of suprange' do
expect(range01_to_2.to_a[90]).to eq(Version.new('1'))
expect(range01_to_2.to_a[189]).to eq(Version.new('1.9.9'))
expect(range0_to_01.to_a[190]).to eq(nil)
end
it 'gives all elements' do
arr = range0_to_01.to_a.map(&:to_s)
expect(arr).to eq [
'', '0.0.1', '0.0.2', '0.0.3',
'0.0.4', '0.0.5', '0.0.6',
'0.0.7', '0.0.8', '0.0.9'
]
end
it 'works for maximum 3 component Versions' do
range1 = Version::Range.new(Version.new('0'), Version.new('0.0.1'))
four_component = range1.to_a.map(&:to_s)
expect(four_component).to eq([''])
range2 = Version::Range.new(Version.new('0'), Version.new('0.0.0.1'))
five_component = range2.to_a.map(&:to_s)
expect(five_component).to eq([''])
end
end
end
end

Лог от изпълнението

F

Failures:

  1) spec passes for the correct solution
     Failure/Error: expect(SOLUTION).to pass_tests
       expected this solution to pass the tests:
       
         class Version
           VALID_VERSION_REGEXP = /\A\z|\A[0-9]+(\.[0-9]+)*\z/
         
           include Comparable
         
           def initialize(version = '')
             unless VALID_VERSION_REGEXP.match(version.to_s)
               raise ArgumentError, "Invalid version string '#{version}'"
             end
         
             @components = version.to_s
               .split('.')
               .map(&:to_i)
               .reverse
               .drop_while(&:zero?)
               .reverse
           end
         
           def <=>(other)
             @components <=> Version.new(other).internal_components
           end
         
           def internal_components(positions = 0)
             padding_size = positions - @components.size
         
             if padding_size > 0
               @components + [0] * padding_size
             elsif positions != 0
               @components.take(positions)
             else
               @components.dup
             end
           end
         
           def components(positions = 0)
             padding_size = positions - @components.size
         
             if padding_size > 0
               @components + [0] * padding_size
             elsif positions != 0
               @components.take(positions)
             else
               @components.dup
             end
           end
         
           def to_s
             @components.join('.')
           end
         
           class Range
             include Enumerable
         
             def initialize(start_version, end_version)
               @start_version = Version.new(start_version)
               @end_version   = Version.new(end_version)
             end
         
             def include?(version)
               (@start_version <=> version) < 1 && (@end_version <=> version) == 1
             end
         
             def each
               current_version = @start_version
         
               while (current_version <=> @end_version) == -1
                 yield current_version
         
                 current_version = increment_version(current_version)
               end
             end
         
             private
         
             def increment_version(version)
               components = version.internal_components(3)
         
               components[2] += 1
         
               components.to_enum.with_index.reverse_each do |_, index|
                 component = components[index]
         
                 if component >= 10 && components[index - 1]
                   components[index]      = 0
                   components[index - 1] += 1
                 end
               end
         
               Version.new(components.join('.'))
             end
           end
         end
       
       
       RSpec log:
       
         .............................F.............................
         
         Failures:
         
           1) Version #components can get N components that are more
              Failure/Error: expect(vers0_1.components(3)).to eq [0, 0, 1]
                
                expected: [0, 0, 1]
                     got: [0, 1, 0]
                
                (compared using ==)
              # ./solution_spec.rb:157:in `block (3 levels) in <top (required)>'
         
         Finished in 0.05332 seconds
         59 examples, 1 failure
         
         Failed examples:
         
         rspec ./solution_spec.rb:156 # Version #components can get N components that are more
     # /tmp/d20161119-19072-k5in34/spec.rb:180:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.83407 seconds
1 example, 1 failure

Failed examples:

rspec /tmp/d20161119-19072-k5in34/spec.rb:179 # spec passes for the correct solution

История (1 версия и 0 коментара)

Иво обнови решението на 18.11.2016 13:55 (преди над 1 година)

+RSpec.describe 'Version' do
+ describe '#initialize' do
+ it 'can initialize with a string argument' do
+ expect { Version.new('1.2.3') }.not_to raise_error
+ expect { Version.new('') }.not_to raise_error
+ end
+ it 'can initialize with no arguments' do
+ expect { Version.new }.not_to raise_error
+ end
+ it 'can initialize with Object of type Version as argument' do
+ expect { Version.new(Version.new('1.2')) }.not_to raise_error
+ end
+ it 'can find invalid argument empty string' do
+ expect { Version.new(' ') }.to raise_error(ArgumentError)
+ end
+ it 'can find invalid argument string that has letters' do
+ expect { Version.new('0.a') }.to raise_error(ArgumentError)
+ expect { Version.new('f.0') }.to raise_error(ArgumentError)
+ expect { Version.new('0.1.1f') }.to raise_error(ArgumentError)
+ end
+ it 'can find invalid argument string with negative numbers' do
+ expect { Version.new('0.0.-12') }.to raise_error(ArgumentError)
+ expect { Version.new('-1') }.to raise_error(ArgumentError)
+ end
+ it 'can find invalid argument string with missing numbers' do
+ expect { Version.new('0..3') }.to raise_error(ArgumentError)
+ expect { Version.new('.3') }.to raise_error(ArgumentError)
+ end
+ end
+
+ let(:vers) { Version.new }
+ let(:vers0) { Version.new('0') }
+ let(:vers1) { Version.new('1.0.0') }
+ let(:vers2) { Version.new('2.0.0') }
+ let(:vers0_1) { Version.new('0.1') }
+ let(:vers0_2) { Version.new('0.2') }
+ let(:vers0_1_123) { Version.new('0.1.123.0') }
+ let(:vers0_1_124) { Version.new('0.1.124.0') }
+
+ describe '#Operators <=>' do
+ describe 'Operator <' do
+ it 'can check true cases' do
+ expect(vers1).to be < vers2
+ expect(vers0_1).to be < vers0_2
+ expect(vers0_1_123).to be < vers0_1_124
+ expect(vers0_1).to be < vers0_1_123
+ end
+ it 'can check false cases' do
+ expect(vers2).to_not be < vers1
+ expect(vers0_2).to_not be < vers0_1
+ expect(vers0_1_124).to_not be < vers0_1_123
+ expect(vers0_1_124).to_not be < vers0_1_124
+ end
+ end
+
+ describe 'Operator >' do
+ it 'can check true cases' do
+ expect(vers2).to be > vers1
+ expect(vers0_2).to be > vers0_1
+ expect(vers0_1_124).to be > vers0_1_123
+ expect(vers0_1_123).to be > vers0_1
+ end
+ it 'can check false cases' do
+ expect(vers1).to_not be > vers2
+ expect(vers0_1).to_not be > vers0_1_124
+ expect(vers0_1_123).to_not be > vers0_1_124
+ expect(vers0_1_124).to_not be > vers0_1_124
+ end
+ end
+
+ describe 'Operator >=' do
+ it 'can check true cases' do
+ expect(vers0_1_123).to be >= vers0_1_123
+ expect(vers0_1_124).to be >= vers0_1_123
+ expect(vers0_1_123).to be >= vers0_1
+ end
+ it 'can check false cases' do
+ expect(vers0_1_123).to_not be >= vers0_1_124
+ expect(vers0_1).to_not be >= vers0_1_123
+ end
+ end
+ describe 'Operator <=' do
+ it 'can check true cases' do
+ expect(vers0_1_123).to be <= vers0_1_123
+ expect(vers0_1_123).to be <= vers0_1_124
+ expect(vers0_1).to be <= vers0_1_123
+ end
+ it 'can check false cases' do
+ expect(vers0_1_124).to_not be <= vers0_1_123
+ expect(vers0_1_123).to_not be <= vers0_1
+ end
+ end
+
+ describe 'Operator ==' do
+ it 'can check true cases' do
+ expect(vers).to be == vers0
+ expect(vers1).to be == vers1
+ expect(vers0_1).to be == vers0_1
+ expect(vers0_1_123).to be == vers0_1_123
+ end
+ it 'can check false cases' do
+ expect(vers1).to_not be == vers2
+ expect(vers2).to_not be == vers1
+ expect(vers0_1).to_not be == vers0_2
+ expect(vers0_2).to_not be == vers0_1
+ expect(vers0_1_123).to_not be == vers0_1_124
+ expect(vers0_1_124).to_not be == vers0_1_123
+ expect(vers1).to_not be == vers0_1
+ end
+ end
+ end
+
+ describe '#to_s' do
+ it 'can work without errors' do
+ expect { vers0.to_s }.not_to raise_error
+ end
+ it 'can parse zero version' do
+ expect(vers0.to_s).to eq('')
+ end
+ it 'can parse and canonize' do
+ expect(vers1.to_s).to eq('1')
+ end
+ it 'can parse with subversions and canonize' do
+ expect(vers0_1_123.to_s).to eq('0.1.123')
+ end
+ end
+
+ describe '#components' do
+ it 'can work without errors' do
+ expect { vers0_1.components(3) }.not_to raise_error
+ end
+ it 'does not allow version data modification' do
+ a = vers0_1_123.components
+ a[1] = 12
+ expect(vers0_1_123.components[1]).not_to eq(12)
+ end
+ it 'can get components with single version number' do
+ expect(vers1.components).to eq [1]
+ end
+ it 'can get components with subversions' do
+ expect(vers0_1.components).to eq [0, 1]
+ end
+ it 'can get components with multiple version digits' do
+ expect(vers0_1_123.components).to eq [0, 1, 123]
+ end
+ it 'can get N components with single version number' do
+ expect(vers1.components(1)).to eq [1]
+ end
+ it 'can get N components with subversions' do
+ expect(vers0_1.components(2)).to eq [0, 1]
+ end
+
+ it 'can get N components with multiple version digits' do
+ expect(vers0_1_123.components(3)).to eq [0, 1, 123]
+ end
+ it 'can get N components that are more' do
+ expect(vers0_1.components(3)).to eq [0, 0, 1]
+ end
+ end
+
+ describe 'Version::Range' do
+ describe '#initialize' do
+ it 'can initialize with Object arguments' do
+ expected = expect do
+ Version::Range.new(Version.new('0.1'), Version.new('2'))
+ end
+ expected.not_to raise_error
+ end
+ it 'can initialize with String arguments' do
+ expect { Version::Range.new('0.1', '1.2') }.not_to raise_error
+ end
+ it 'can initialize with mixed type arguments' do
+ expected = expect do
+ Version::Range.new(Version.new('0.1'), '1.2')
+ end
+ expected.not_to raise_error
+ end
+ it 'can find invalid argument empty string' do
+ expect { Version::Range.new(' ', ' ') }.to raise_error(ArgumentError)
+ end
+ it 'can find invalid argument string that has letters' do
+ expect { Version::Range.new('1', '0.f') }.to raise_error(ArgumentError)
+ expect { Version::Range.new('a.0', '1f') }.to raise_error(ArgumentError)
+ expect { Version::Range.new('f', '') }.to raise_error(ArgumentError)
+ end
+ it 'can find invalid argument string with negative numbers' do
+ expect { Version::Range.new('0', '-12') }.to raise_error(ArgumentError)
+ expect { Version::Range.new('', '0.-12') }.to raise_error(ArgumentError)
+ end
+ it 'can find invalid argument string with missing numbers' do
+ expect { Version::Range.new('', '0..3') }.to raise_error(ArgumentError)
+ expect { Version::Range.new('', '.3') }.to raise_error(ArgumentError)
+ end
+ end
+
+ let(:range01_to_2) do
+ Version::Range.new(Version.new('0.1'), Version.new('2'))
+ end
+ let(:range0_to_01) do
+ Version::Range.new(Version.new('0'), Version.new('0.1'))
+ end
+
+ describe '#include?' do
+ it 'can work without errors' do
+ expect { range01_to_2.include? Version.new('1') }.not_to raise_error
+ end
+ it 'can work with string as argument' do
+ expect((range01_to_2.include? '1.2')).to be true
+ end
+ it 'can find invalid argument empty string' do
+ expect { range01_to_2.include? ' ' }.to raise_error(ArgumentError)
+ end
+ it 'can find invalid argument string that has letters' do
+ expect { range01_to_2.include? '0.g' }.to raise_error(ArgumentError)
+ expect { range01_to_2.include? 'z.0' }.to raise_error(ArgumentError)
+ expect { range01_to_2.include? '0.1.1g' }.to raise_error(ArgumentError)
+ end
+ it 'can find invalid argument string with negative numbers' do
+ expect { range01_to_2.include? '0.-12' }.to raise_error(ArgumentError)
+ expect { range01_to_2.include? '-1' }.to raise_error(ArgumentError)
+ end
+ it 'can find invalid argument string with missing numbers' do
+ expect { range01_to_2.include? '.3' }.to raise_error(ArgumentError)
+ expect { range01_to_2.include? '0..3' }.to raise_error(ArgumentError)
+ end
+ context 'with object as argument' do
+ it 'can check supranges' do
+ expect((range01_to_2.include? Version.new('1'))).to be true
+ end
+ it 'can check if at start of ranges' do
+ expect((range01_to_2.include? Version.new('0'))).to be false
+ expect((range01_to_2.include? Version.new('0.1'))).to be true
+ expect((range01_to_2.include? Version.new('0.2'))).to be true
+ end
+ it 'can check if at end of ranges' do
+ expect((range01_to_2.include? Version.new('1.9'))).to be true
+ expect((range01_to_2.include? Version.new('2'))).to be false
+ expect((range01_to_2.include? Version.new('2.1'))).to be false
+ end
+ it 'can check deep subranges' do
+ expect((range01_to_2.include? Version.new('1.2.3.4'))).to be true
+ end
+ it 'can check ranges that start with zero' do
+ expect((range0_to_01.include? Version.new('0'))).to be true
+ expect((range0_to_01.include? Version.new('0.0.0.1'))).to be true
+ end
+ end
+ context 'with string as argument' do
+ it 'can check supranges' do
+ expect((range01_to_2.include? '1')).to be true
+ end
+ it 'can check if at start of ranges' do
+ expect((range01_to_2.include? '0')).to be false
+ expect((range01_to_2.include? '0.1')).to be true
+ expect((range01_to_2.include? '0.2')).to be true
+ end
+ it 'can check if at end of ranges' do
+ expect((range01_to_2.include? '1.9')).to be true
+ expect((range01_to_2.include? '2')).to be false
+ expect((range01_to_2.include? '2.1')).to be false
+ end
+ it 'can check deep subranges' do
+ expect((range01_to_2.include? '1.2.3.4')).to be true
+ end
+ it 'can check ranges that start with zero' do
+ expect((range0_to_01.include? '0')).to be true
+ expect((range0_to_01.include? '0.0.0.1')).to be true
+ end
+ end
+ end
+
+ describe '#to_a' do
+ it 'can work without errors' do
+ expect { range0_to_01.to_a }.not_to raise_error
+ end
+ it 'can give first elements of range' do
+ expect(range0_to_01.to_a[0]).to eq(Version.new)
+ expect(range0_to_01.to_a[1]).to eq(Version.new('0.0.1'))
+ end
+ it 'can give last elements of subrange' do
+ expect(range0_to_01.to_a[8]).to eq(Version.new('0.0.8'))
+ expect(range0_to_01.to_a[9]).to eq(Version.new('0.0.9'))
+ expect(range0_to_01.to_a[10]).to eq(nil)
+ end
+ it 'can give last elements of suprange' do
+ expect(range01_to_2.to_a[90]).to eq(Version.new('1'))
+ expect(range01_to_2.to_a[189]).to eq(Version.new('1.9.9'))
+ expect(range0_to_01.to_a[190]).to eq(nil)
+ end
+ it 'gives all elements' do
+ arr = range0_to_01.to_a.map(&:to_s)
+ expect(arr).to eq [
+ '', '0.0.1', '0.0.2', '0.0.3',
+ '0.0.4', '0.0.5', '0.0.6',
+ '0.0.7', '0.0.8', '0.0.9'
+ ]
+ end
+ it 'works for maximum 3 component Versions' do
+ range1 = Version::Range.new(Version.new('0'), Version.new('0.0.1'))
+ four_component = range1.to_a.map(&:to_s)
+ expect(four_component).to eq([''])
+ range2 = Version::Range.new(Version.new('0'), Version.new('0.0.0.1'))
+ five_component = range2.to_a.map(&:to_s)
+ expect(five_component).to eq([''])
+ end
+ end
+ end
+end