Решение на Четвърта задача - Unit тестване от Елеонора Кайкова

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

Към профила на Елеонора Кайкова

Резултати

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

Код

RSpec.describe 'Version' do
describe 'Validation' do
it 'can convert to 0' do
expect(Version.new("")).to eq 0
expect(Version.new).to eq 0
end
it 'can raise ArgumentError for Invalid Input' do
expect { Version.new('1..3') }.to raise_error(
ArgumentError,
"Invalid version string '1..3'"
)
expect { Version.new('.3') }.to raise_error(
ArgumentError,
"Invalid version string '.3'"
)
expect { Version.new('3.') }.to raise_error(
ArgumentError,
"Invalid version string '3.'"
)
end
end
describe 'compare versions' do
it 'can check for <' do
expect(Version.new('1.2.3')).to be < Version.new('1.3.1')
expect(Version.new('1.2.3')).to be < Version.new('1.3')
expect(Version.new('1.3.1')).not_to be < Version.new('1.3')
end
it 'can check for >' do
expect(Version.new('1.2.3')).not_to be > Version.new('1.3.1')
expect(Version.new('1.2.3')).not_to be > Version.new('1.3')
expect(Version.new('1.3.1')).to be > Version.new('1.3')
end
it 'can check for <=' do
expect(Version.new('1.2.3')).to be <= Version.new('1.3.1')
expect(Version.new('1.2.3')).to be <= Version.new('1.3')
expect(Version.new('1.3.1')).not_to be <= Version.new('1.3')
expect(Version.new('1.3')).to be <= Version.new('1.3.0')
expect(Version.new('1.22')).not_to be <= Version.new('1.2.2')
end
it 'can check for >=' do
expect(Version.new('1.2.3')).not_to be >= Version.new('1.3.1')
expect(Version.new('1.2.3')).not_to be >= Version.new('1.3')
expect(Version.new('1.3.1')).to be >= Version.new('1.3')
expect(Version.new('1.3')).to be >= Version.new('1.3.0')
expect(Version.new('1.22')).to be >= Version.new('1.2.2')
end
it 'can check for ==' do
expect(Version.new('1.3.1')).not_to eq Version.new('1.3')
expect(Version.new('1.3.0')).to eq Version.new('1.3')
expect(Version.new('1.3')).to eq Version.new('1.3.0.0')
expect(Version.new('1.22')).not_to eq Version.new('1.2.2')
expect(Version.new('0.1')).not_to eq Version.new('1')
end
it 'can check for <=>' do
expect(Version.new('1.3.1') <=> Version.new('1.3')).to eq 1
expect(Version.new('1.3.0') <=> Version.new('1.3')).to eq 0
expect(Version.new('1.3') <=> Version.new('1.3.0.0')).to eq 0
# expect(Version.new('1.3') <=> Version.new('1.3')).to eq 0
expect(Version.new('1.22') <=> Version.new('1.2.2')).to eq 1
expect(Version.new('1.2') <=> Version.new('1.2.2')).to eq -1
end
end
describe '#to_s' do
it 'can convert to string' do
expect(Version.new('1.2.3').to_s).to eq '1.2.3'
end
it 'can remove the zeroes' do
expect(Version.new('1.1.0.0').to_s).to eq '1.1'
expect(Version.new('1.1.0.1.0').to_s).to eq '1.1.0.1'
# expect(Version.new('0').to_s).to eq ''
# expect(Version.new.to_s).to eq ''
end
end
describe '#components' do
it 'can convert to an array simple stirngs' do
expect(Version.new('1.3.5').components).to eq [1, 3, 5]
expect(Version.new('1.3.0.5').components).to eq [1, 3, 0, 5]
expect(Version.new('1').components).to eq [1]
expect(Version.new('1.22.2').components).to eq [1, 22, 2]
end
it 'can convert and add zeroes' do
expect(Version.new('1.3.5').components(4)).to match_array [1, 3, 5, 0]
expect(Version.new('1.3.5').components(5)).to match_array [1, 3, 5, 0, 0]
end
it 'can convert exactly N components' do
expect(Version.new('1.3.5').components(1)).to match_array [1]
expect(Version.new('1.3.5').components(2)).to match_array [1, 3]
expect(Version.new('1.3.5').components(3)).to match_array [1, 3, 5]
end
it 'does not change the version' do
a = Version.new('1.3.5')
b = a.components << 4
expect(b).not_to be a.components
end
end
describe '#Range' do
describe 'Range#include?' do
it 'can check for versions with versions' do
range = Version::Range.new(Version.new('1'), Version.new('2'))
expect(range).to include(Version.new('1.5'))
expect(range).not_to include(Version.new('2.5'))
range = Version::Range.new(Version.new('1'), Version.new('1.6'))
expect(range).to include(Version.new('1.5'))
expect(range).not_to include(Version.new('1.6'))
end
it 'can check for strings with strings' do
expect(Version::Range.new('1', '2')).to include('1.5')
expect(Version::Range.new('1', '2')).not_to include('2.5')
expect(Version::Range.new('1', '1.6')).to include('1.5')
expect(Version::Range.new('1', '1.5')).not_to include('1.5')
end
it 'can check for strings with versions' do
expect(Version::Range.new('1', '2')).to include(Version.new('1.5'))
expect(Version::Range.new('1', '2')).not_to include(Version.new('2.5'))
expect(Version::Range.new('1', '1.6')).to include(Version.new('1.5'))
expect(Version::Range.new('1', '1.5')).not_to include Version.new('1.5')
end
it 'can check for versions with strings' do
range = Version::Range.new(Version.new('1'), Version.new('2'))
expect(range).to include('1.5')
expect(range).not_to include('2.5')
range = Version::Range.new(Version.new('1'), Version.new('1.6'))
expect(range).to include('1.5')
expect(range).not_to include('1.6')
end
end
describe 'Range#to_a' do
it 'can generate range' do
expect(Version::Range.new('1.1', '1.1').to_a).to match_array []
range = Version::Range.new(Version.new('1.1.0'), Version.new('1.1.2'))
expect(range.to_a)
.to match_array [Version.new('1.1'), Version.new('1.1.1')]
expect(Version::Range.new(Version.new('1.1'), Version.new('1.2')).to_a)
.to match_array [
Version.new('1.1'), Version.new('1.1.1'),
Version.new('1.1.2'), Version.new('1.1.3'), Version.new('1.1.4'),
Version.new('1.1.5'), Version.new('1.1.6'), Version.new('1.1.7'),
Version.new('1.1.8'), Version.new('1.1.9')
]
expect(Version::Range.new('1', '1.2'))
.to match_array [
Version.new('1'), Version.new('1.0.1'),
Version.new('1.0.2'), Version.new('1.0.3'), Version.new('1.0.4'),
Version.new('1.0.5'), Version.new('1.0.6'), Version.new('1.0.7'),
Version.new('1.0.8'), Version.new('1.0.9'), Version.new('1.1'),
Version.new('1.1.1'), Version.new('1.1.2'), Version.new('1.1.3'),
Version.new('1.1.4'), Version.new('1.1.5'), Version.new('1.1.6'),
Version.new('1.1.7'), Version.new('1.1.8'), Version.new('1.1.9')
]
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 #Range Range#to_a can generate range
              Failure/Error: expect(Version::Range.new('1', '1.2'))
                expected an array, actual collection was #<Version::Range:0x007f89c31d7eb0 @start_version=#<Version:0x007f89c31d7e88 @components=[1]>, @end_version=#<Version:0x007f89c31d7c08 @components=[1, 2]>>
              # ./solution_spec.rb:169:in `block (4 levels) in <top (required)>'
         
         Finished in 0.01717 seconds
         19 examples, 1 failure
         
         Failed examples:
         
         rspec ./solution_spec.rb:154 # Version #Range Range#to_a can generate range
     # /tmp/d20161119-19072-a4ul0m/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.76506 seconds
1 example, 1 failure

Failed examples:

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

История (2 версии и 6 коментара)

Елеонора обнови решението на 17.11.2016 18:10 (преди над 7 години)

+RSpec.describe 'Version' do
+ describe 'Valid_Version' do
+ it 'can convert to 0' do
+ expect(Version.new("")).to eq 0
+ expect(Version.new).to eq 0
+ end
+
+ it 'can raise ArgumentError for Invalid Input' do
+ expect { Version.new('1..3') }
+ .to raise_error ArgumentError, "Invalid version string '1..3'"
+ expect { Version.new('.3') }
+ .to raise_error ArgumentError, "Invalid version string '.3'"
+ expect { Version.new('3.') }
+ .to raise_error ArgumentError, "Invalid version string '3.'"
+ end
+
+ it 'can create version' do
+ expect(Version.new('1.22.3')).to eq '1.22.3'
+ expect(Version.new('1.2.0')).to eq '1.2.0'
+ end
+ end
+
+ describe 'compare versions' do
+ it 'can check for <' do
+ expect(Version.new('1.2.3')).to be < Version.new('1.3.1')
+ expect(Version.new('1.2.3')).to be < Version.new('1.3')
+ expect(Version.new('1.3.1')).not_to be < Version.new('1.3')
+ end
+
+ it 'can check for >' do
+ expect(Version.new('1.2.3')).not_to be > Version.new('1.3.1')
+ expect(Version.new('1.2.3')).not_to be > Version.new('1.3')
+ expect(Version.new('1.3.1')).to be > Version.new('1.3')
+ end
+
+ it 'can check for <=' do
+ expect(Version.new('1.2.3')).to be <= Version.new('1.3.1')
+ expect(Version.new('1.2.3')).to be <= Version.new('1.3')
+ expect(Version.new('1.3.1')).not_to be <= Version.new('1.3')
+ expect(Version.new('1.3')).to be <= Version.new('1.3.0')
+ expect(Version.new('1.22')).not_to be <= Version.new('1.2.2')
+ end
+
+ it 'can check for >=' do
+ expect(Version.new('1.2.3')).not_to be >= Version.new('1.3.1')
+ expect(Version.new('1.2.3')).not_to be >= Version.new('1.3')
+ expect(Version.new('1.3.1')).to be >= Version.new('1.3')
+ expect(Version.new('1.3')).to be >= Version.new('1.3.0')
+ expect(Version.new('1.22')).to be >= Version.new('1.2.2')
+ end
+
+ it 'can check for ==' do
+ expect(Version.new('1.3.1')).not_to eq Version.new('1.3')
+ expect(Version.new('1.3.0')).to eq Version.new('1.3')
+ expect(Version.new('1.3')).to eq Version.new('1.3.0.0')
+ expect(Version.new('1.22')).not_to eq Version.new('1.2.2')
+ expect(Version.new('0.1')).not_to eq Version.new('1')
+ end
+
+ it 'can check for <=>' do
+ expect(Version.new('1.3.1') <=> Version.new('1.3')).to eq 1
+ expect(Version.new('1.3.0') <=> Version.new('1.3')).to eq 0
+ expect(Version.new('1.3') <=> Version.new('1.3.0.0')).to eq 0
+ # expect(Version.new('1.3') <=> Version.new('1.3')).to eq 0
+ expect(Version.new('1.22') <=> Version.new('1.2.2')).to eq 1
+ expect(Version.new('1.2') <=> Version.new('1.2.2')).to eq -1
+ end
+ end
+
+ describe '#to_s' do
+ it 'can convert to string' do
+ expect(Version.new('1.2.3').to_s).to eq '1.2.3'
+ end
+
+ it 'can remove the zeroes' do
+ expect(Version.new('1.1.0.0').to_s).to eq '1.1'
+ expect(Version.new('1.1.0.1.0').to_s).to eq '1.1.0.1'
+ # expect(Version.new('0').to_s).to eq ''
+ # expect(Version.new.to_s).to eq ''
+ end
+ end
+
+ describe '#components' do
+ it 'can convert to an array simple stirngs' do
+ expect(Version.new('1.3.5').components).to match_array [1, 3, 5]
+ expect(Version.new('1.3.0.5').components).to match_array [1, 3, 5, 0]
+ expect(Version.new('1').components).to match_array [1]
+ expect(Version.new('1.22.2').components).to match_array [1, 2, 22]
+ end
+
+ it 'can convert and add zeroes' do
+ expect(Version.new('1.3.5').components(4)).to match_array [1, 3, 5, 0]
+ expect(Version.new('1.3.5').components(5)).to match_array [1, 3, 5, 0, 0]
+ end
+
+ it 'can convert exactly N components' do
+ expect(Version.new('1.3.5').components(1)).to match_array [1]
+ expect(Version.new('1.3.5').components(2)).to match_array [1, 3]
+ expect(Version.new('1.3.5').components(3)).to match_array [1, 3, 5]
+ end
+
+ it 'does not change the version' do
+ a = Version.new('1.3.5')
+
+ expect(a).not_to be a.components(3)

Този тест никога няма да фейлне. Сравняваш версия с масив и очакваш да са различни. Да, очевидно - винаги ще са различни.

Махни .dup от имплементацията на components и помисли как може чрез него да се промени вътрешното състояние на версията.

+ end
+ end
+
+ describe '#Range' do
+ it 'can create range from both version and string' do
+ range = Version::Range.new('1', Version.new('1.6'))
+ range_2 = Version::Range.new(Version.new('1'), Version.new('1.6'))
+ range_3 = Version::Range.new('1', '1.6')
+
+ expect(range).to match_array range_2
+ expect(range).to match_array range_3
+ expect(range_2).to match_array range_3
+ end
+
+ describe 'Range#include?' do
+ it 'can check for versions with versions' do
+ range = Version::Range.new(Version.new('1'), Version.new('2'))
+
+ expect(range).to include(Version.new('1.5'))
+ expect(range).not_to include(Version.new('2.5'))
+
+ range = Version::Range.new(Version.new('1'), Version.new('1.6'))
+ expect(range).to include(Version.new('1.5'))
+ expect(range).not_to include(Version.new('1.6'))
+ end
+
+ it 'can check for strings with strings' do
+ expect(Version::Range.new('1', '2')).to include('1.5')
+ expect(Version::Range.new('1', '2')).not_to include('2.5')
+ expect(Version::Range.new('1', '1.6')).to include('1.5')
+ expect(Version::Range.new('1', '1.5')).not_to include('1.5')
+ end
+
+ it 'can check for strings with versions' do
+ expect(Version::Range.new('1', '2')).to include(Version.new('1.5'))
+ expect(Version::Range.new('1', '2')).not_to include(Version.new('2.5'))
+ expect(Version::Range.new('1', '1.6')).to include(Version.new('1.5'))
+ expect(Version::Range.new('1', '1.5')).not_to include Version.new('1.5')
+ end
+
+ it 'can check for versions with strings' do
+ range = Version::Range.new(Version.new('1'), Version.new('2'))
+
+ expect(range).to include('1.5')
+ expect(range).not_to include('2.5')
+
+ range = Version::Range.new(Version.new('1'), Version.new('1.6'))
+
+ expect(range).to include('1.5')
+ expect(range).not_to include('1.6')
+ end
+ end
+
+ describe 'Range#to_a' do
+ it 'can generate range' do
+ expect(Version::Range.new('1.1', '1.1').to_a).to match_array []
+
+ range = Version::Range.new(Version.new('1.1.0'), Version.new('1.1.2'))
+ expect(range.to_a)
+ .to match_array [Version.new('1.1'), Version.new('1.1.1')]
+
+ expect(Version::Range.new(Version.new('1.1'), Version.new('1.2')).to_a)
+ .to match_array [
+ Version.new('1.1'), Version.new('1.1.1'),
+ Version.new('1.1.2'), Version.new('1.1.3'), Version.new('1.1.4'),
+ Version.new('1.1.5'), Version.new('1.1.6'), Version.new('1.1.7'),
+ Version.new('1.1.8'), Version.new('1.1.9')
+ ]
+
+ expect(Version::Range.new('1', '1.2'))
+ .to match_array [
+ Version.new('1'), Version.new('1.0.1'),
+ Version.new('1.0.2'), Version.new('1.0.3'), Version.new('1.0.4'),
+ Version.new('1.0.5'), Version.new('1.0.6'), Version.new('1.0.7'),
+ Version.new('1.0.8'), Version.new('1.0.9'), Version.new('1.1'),
+ Version.new('1.1.1'), Version.new('1.1.2'), Version.new('1.1.3'),
+ Version.new('1.1.4'), Version.new('1.1.5'), Version.new('1.1.6'),
+ Version.new('1.1.7'), Version.new('1.1.8'), Version.new('1.1.9')
+ ]
+ end
+ end
+ end
+end

Елеонора обнови решението на 18.11.2016 18:51 (преди над 7 години)

RSpec.describe 'Version' do
- describe 'Valid_Version' do
+ describe 'Validation' do
it 'can convert to 0' do
expect(Version.new("")).to eq 0
expect(Version.new).to eq 0
end
it 'can raise ArgumentError for Invalid Input' do
- expect { Version.new('1..3') }
- .to raise_error ArgumentError, "Invalid version string '1..3'"
- expect { Version.new('.3') }
- .to raise_error ArgumentError, "Invalid version string '.3'"
- expect { Version.new('3.') }
- .to raise_error ArgumentError, "Invalid version string '3.'"
- end
+ expect { Version.new('1..3') }.to raise_error(
+ ArgumentError,
+ "Invalid version string '1..3'"
+ )
- it 'can create version' do
- expect(Version.new('1.22.3')).to eq '1.22.3'
- expect(Version.new('1.2.0')).to eq '1.2.0'
+ expect { Version.new('.3') }.to raise_error(
+ ArgumentError,
+ "Invalid version string '.3'"
+ )
+
+ expect { Version.new('3.') }.to raise_error(
+ ArgumentError,
+ "Invalid version string '3.'"
+ )
end
end
describe 'compare versions' do
it 'can check for <' do
expect(Version.new('1.2.3')).to be < Version.new('1.3.1')
expect(Version.new('1.2.3')).to be < Version.new('1.3')
expect(Version.new('1.3.1')).not_to be < Version.new('1.3')
end
it 'can check for >' do
expect(Version.new('1.2.3')).not_to be > Version.new('1.3.1')
expect(Version.new('1.2.3')).not_to be > Version.new('1.3')
expect(Version.new('1.3.1')).to be > Version.new('1.3')
end
it 'can check for <=' do
expect(Version.new('1.2.3')).to be <= Version.new('1.3.1')
expect(Version.new('1.2.3')).to be <= Version.new('1.3')
expect(Version.new('1.3.1')).not_to be <= Version.new('1.3')
expect(Version.new('1.3')).to be <= Version.new('1.3.0')
expect(Version.new('1.22')).not_to be <= Version.new('1.2.2')
end
it 'can check for >=' do
expect(Version.new('1.2.3')).not_to be >= Version.new('1.3.1')
expect(Version.new('1.2.3')).not_to be >= Version.new('1.3')
expect(Version.new('1.3.1')).to be >= Version.new('1.3')
expect(Version.new('1.3')).to be >= Version.new('1.3.0')
expect(Version.new('1.22')).to be >= Version.new('1.2.2')
end
it 'can check for ==' do
expect(Version.new('1.3.1')).not_to eq Version.new('1.3')
expect(Version.new('1.3.0')).to eq Version.new('1.3')
expect(Version.new('1.3')).to eq Version.new('1.3.0.0')
expect(Version.new('1.22')).not_to eq Version.new('1.2.2')
expect(Version.new('0.1')).not_to eq Version.new('1')
end
it 'can check for <=>' do
expect(Version.new('1.3.1') <=> Version.new('1.3')).to eq 1
expect(Version.new('1.3.0') <=> Version.new('1.3')).to eq 0
expect(Version.new('1.3') <=> Version.new('1.3.0.0')).to eq 0
# expect(Version.new('1.3') <=> Version.new('1.3')).to eq 0
expect(Version.new('1.22') <=> Version.new('1.2.2')).to eq 1
expect(Version.new('1.2') <=> Version.new('1.2.2')).to eq -1
end
end
describe '#to_s' do
it 'can convert to string' do
expect(Version.new('1.2.3').to_s).to eq '1.2.3'
end
it 'can remove the zeroes' do
expect(Version.new('1.1.0.0').to_s).to eq '1.1'
expect(Version.new('1.1.0.1.0').to_s).to eq '1.1.0.1'
# expect(Version.new('0').to_s).to eq ''
# expect(Version.new.to_s).to eq ''
end
end
describe '#components' do
it 'can convert to an array simple stirngs' do
- expect(Version.new('1.3.5').components).to match_array [1, 3, 5]
- expect(Version.new('1.3.0.5').components).to match_array [1, 3, 5, 0]
- expect(Version.new('1').components).to match_array [1]
- expect(Version.new('1.22.2').components).to match_array [1, 2, 22]
+ expect(Version.new('1.3.5').components).to eq [1, 3, 5]
+ expect(Version.new('1.3.0.5').components).to eq [1, 3, 0, 5]
+ expect(Version.new('1').components).to eq [1]
+ expect(Version.new('1.22.2').components).to eq [1, 22, 2]
end
it 'can convert and add zeroes' do
expect(Version.new('1.3.5').components(4)).to match_array [1, 3, 5, 0]
expect(Version.new('1.3.5').components(5)).to match_array [1, 3, 5, 0, 0]
end
it 'can convert exactly N components' do
expect(Version.new('1.3.5').components(1)).to match_array [1]
expect(Version.new('1.3.5').components(2)).to match_array [1, 3]
expect(Version.new('1.3.5').components(3)).to match_array [1, 3, 5]
end
it 'does not change the version' do
a = Version.new('1.3.5')
+ b = a.components << 4
- expect(a).not_to be a.components(3)
+ expect(b).not_to be a.components
end
end
describe '#Range' do
- it 'can create range from both version and string' do
- range = Version::Range.new('1', Version.new('1.6'))
- range_2 = Version::Range.new(Version.new('1'), Version.new('1.6'))
- range_3 = Version::Range.new('1', '1.6')
-
- expect(range).to match_array range_2
- expect(range).to match_array range_3
- expect(range_2).to match_array range_3
- end
-
describe 'Range#include?' do
it 'can check for versions with versions' do
range = Version::Range.new(Version.new('1'), Version.new('2'))
expect(range).to include(Version.new('1.5'))
expect(range).not_to include(Version.new('2.5'))
range = Version::Range.new(Version.new('1'), Version.new('1.6'))
expect(range).to include(Version.new('1.5'))
expect(range).not_to include(Version.new('1.6'))
end
it 'can check for strings with strings' do
expect(Version::Range.new('1', '2')).to include('1.5')
expect(Version::Range.new('1', '2')).not_to include('2.5')
expect(Version::Range.new('1', '1.6')).to include('1.5')
expect(Version::Range.new('1', '1.5')).not_to include('1.5')
end
it 'can check for strings with versions' do
expect(Version::Range.new('1', '2')).to include(Version.new('1.5'))
expect(Version::Range.new('1', '2')).not_to include(Version.new('2.5'))
expect(Version::Range.new('1', '1.6')).to include(Version.new('1.5'))
expect(Version::Range.new('1', '1.5')).not_to include Version.new('1.5')
end
it 'can check for versions with strings' do
range = Version::Range.new(Version.new('1'), Version.new('2'))
expect(range).to include('1.5')
expect(range).not_to include('2.5')
range = Version::Range.new(Version.new('1'), Version.new('1.6'))
expect(range).to include('1.5')
expect(range).not_to include('1.6')
end
end
describe 'Range#to_a' do
it 'can generate range' do
expect(Version::Range.new('1.1', '1.1').to_a).to match_array []
range = Version::Range.new(Version.new('1.1.0'), Version.new('1.1.2'))
expect(range.to_a)
.to match_array [Version.new('1.1'), Version.new('1.1.1')]
expect(Version::Range.new(Version.new('1.1'), Version.new('1.2')).to_a)
.to match_array [
Version.new('1.1'), Version.new('1.1.1'),
Version.new('1.1.2'), Version.new('1.1.3'), Version.new('1.1.4'),
Version.new('1.1.5'), Version.new('1.1.6'), Version.new('1.1.7'),
Version.new('1.1.8'), Version.new('1.1.9')
]
expect(Version::Range.new('1', '1.2'))
.to match_array [
Version.new('1'), Version.new('1.0.1'),
Version.new('1.0.2'), Version.new('1.0.3'), Version.new('1.0.4'),
Version.new('1.0.5'), Version.new('1.0.6'), Version.new('1.0.7'),
Version.new('1.0.8'), Version.new('1.0.9'), Version.new('1.1'),
Version.new('1.1.1'), Version.new('1.1.2'), Version.new('1.1.3'),
Version.new('1.1.4'), Version.new('1.1.5'), Version.new('1.1.6'),
Version.new('1.1.7'), Version.new('1.1.8'), Version.new('1.1.9')
]
end
end
end
end