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

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

Към профила на Виктор Клисуров

Резултати

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

Код

RSpec.describe 'Version' do
describe '#initialization' do
it 'raise_error' do
expect { Version.new('32..d') }.to raise_error(ArgumentError)
end
it 'should not raise error' do
expect { Version.new('3.1.2') }.to_not raise_error
end
end
describe '#<=>' do
it "v1<v2 is true when v1<v2" do
v1 = Version.new('2.3.2')
v2 = Version.new('3.2.2')
expect(v1 < v2).to be true
end
it "v1<v2 is false when v1>=v2" do
v1 = Version.new('3.3.2')
v2 = Version.new('2.2.2')
expect(v1 < v2).to be false
end
it "v1>v2 is true when v1>v2" do
v1 = Version.new('3.3.2')
v2 = Version.new('2.2.2')
expect(v1 > v2).to be true
end
it "v1>v2 is false when v1<=v2" do
v1 = Version.new('2.3.2')
v2 = Version.new('3.2.2')
expect(v1 > v2).to be false
end
it "v1 == v2 is true when v1 == v2" do
v1 = Version.new('2.3.2')
v2 = Version.new('2.3.2')
expect(v1 == v2).to be true
end
it "v1 == v2 is false when v1 != v2" do
v1 = Version.new('2.3.2')
v2 = Version.new('3.2.2')
expect(v1 == v2).to be false
end
it "v1!=v2 is true when v1!=v2" do
v1 = Version.new('3.3.2')
v2 = Version.new('2.2.2')
expect(v1 != v2).to be true
end
it "v1!=v2 is false when v1 == v2" do
v1 = Version.new('2.3.2')
v2 = Version.new('2.3.2')
expect(v1 != v2).to be false
end
end
describe '#to_s' do
it 'return good string' do
expect(Version.new('4.5.2').to_s).to eq '4.5.2'
end
end
describe '#components' do
it "return good array when called without argument" do
expect(Version.new('4.5.7').components).to eq [4, 5, 7]
end
it "return good array when called without argument and
last component is 0" do
expect(Version.new('0.4.0').components).to eq [0, 4]
end
it "return good array when called with argument" do
expect(Version.new('2.4.1').components(2)).to eq [2, 4]
end
it 'return good array when called with argument 1 and
second component is 0' do
expect(Version.new('4.0.0').components(1)).to eq [4]
end
end
end
RSpec.describe "Version::Range" do
describe '#include?' do
before do
@range = Version::Range.new('1.3.2', '4.2.3')
end
it 'return true with good argument' do
expect(@range.include?('3.3.2')).to be true
end
it 'return false with argument < start_version' do
expect(@range.include?('0.2.3')).to be false
end
it 'return false with argument > end_version' do
expect(@range.include?('5.2.3')).to be false
end
it 'return true when argument == start_version' do
expect(@range.include?('1.3.2')).to be true
end
it 'return false when argument == end_version' do
expect(@range.include?(Version.new('4.2.3'))).to be false
end
end
describe '#to_a' do
it 'return good array' do
expect(Version::Range.new('1.9.7', '2.0.1').to_a)
.to eq ['1.9.7', '1.9.8', '1.9.9', '2']
end
it 'return empty array when start_version>end_version' do
expect(Version::Range.new('2.9.7', '2.0.1').to_a).to eq []
end
end
end

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

.F.FFFF..FF..F.....

Failures:

  1) spec Version checks for ArgumentError with the correct message
     Failure/Error: expect(@solution).to_not pass_tests
       expected this solution to not 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"
             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
     # /tmp/d20161119-19072-1fm5qa2/spec.rb:257:in `block (3 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)>'

  2) spec Version checks that initialize can be given an empty string
     Failure/Error: expect(@solution).to_not pass_tests
       expected this solution to not pass the tests:
       
         class Version
           VALID_VERSION_REGEXP = /\A\z|\A[0-9]+(\.[0-9]+)*\z/
         
           include Comparable
         
           def initialize(version = '')
             unless /\A[0-9]+(\.[0-9]+)*\z/.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
     # /tmp/d20161119-19072-1fm5qa2/spec.rb:295:in `block (3 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)>'

  3) spec Version checks that initialize can be given no arguments
     Failure/Error: expect(@solution).to_not pass_tests
       expected this solution to not 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
     # /tmp/d20161119-19072-1fm5qa2/spec.rb:314:in `block (3 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)>'

  4) spec Version checks for comparison operators positively
     Failure/Error: expect(@solution).to_not pass_tests
       expected this solution to not pass the tests:
       
         class Version
         def <=(other)
           false
         end
           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
     # /tmp/d20161119-19072-1fm5qa2/spec.rb:341:in `block (3 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)>'

  5) spec Version checks for comparison operators negatively
     Failure/Error: expect(@solution).to_not pass_tests
       expected this solution to not pass the tests:
       
         class Version
         def <=(other)
           true
         end
           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
     # /tmp/d20161119-19072-1fm5qa2/spec.rb:377:in `block (3 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)>'

  6) spec Version tests #components with more components than present
     Failure/Error: expect(@solution).to_not pass_tests
       expected this solution to not 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
               [42, 42, 42, 42, 42]
             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
     # /tmp/d20161119-19072-1fm5qa2/spec.rb:438:in `block (3 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)>'

  7) spec Version tests that #components cannot be used to modify the version
     Failure/Error: expect(@solution).to_not pass_tests
       expected this solution to not 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
             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
     # /tmp/d20161119-19072-1fm5qa2/spec.rb:456:in `block (3 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)>'

  8) spec Version::Range tests constructing ranges with versions
     Failure/Error: expect(@solution).to_not pass_tests
       expected this solution to not 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)
               raise 'error' if start_version.is_a?(Version) || end_version.is_a?(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
     # /tmp/d20161119-19072-1fm5qa2/spec.rb:492:in `block (3 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 17.04 seconds
19 examples, 8 failures

Failed examples:

rspec /tmp/d20161119-19072-1fm5qa2/spec.rb:241 # spec Version checks for ArgumentError with the correct message
rspec /tmp/d20161119-19072-1fm5qa2/spec.rb:279 # spec Version checks that initialize can be given an empty string
rspec /tmp/d20161119-19072-1fm5qa2/spec.rb:298 # spec Version checks that initialize can be given no arguments
rspec /tmp/d20161119-19072-1fm5qa2/spec.rb:317 # spec Version checks for comparison operators positively
rspec /tmp/d20161119-19072-1fm5qa2/spec.rb:353 # spec Version checks for comparison operators negatively
rspec /tmp/d20161119-19072-1fm5qa2/spec.rb:423 # spec Version tests #components with more components than present
rspec /tmp/d20161119-19072-1fm5qa2/spec.rb:441 # spec Version tests that #components cannot be used to modify the version
rspec /tmp/d20161119-19072-1fm5qa2/spec.rb:482 # spec Version::Range tests constructing ranges with versions

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

Виктор обнови решението на 18.11.2016 20:32 (преди над 7 години)

+RSpec.describe 'Version' do
+ describe '#initialization' do
+ it 'raise_error' do
+ expect { Version.new('32..d') }.to raise_error(ArgumentError)
+ end
+ it 'should not raise error' do
+ expect { Version.new('3.1.2') }.to_not raise_error
+ end
+ end
+ describe '#<=>' do
+ it "v1<v2 is true when v1<v2" do
+ v1 = Version.new('2.3.2')
+ v2 = Version.new('3.2.2')
+ expect(v1 < v2).to be true
+ end
+ it "v1<v2 is false when v1>=v2" do
+ v1 = Version.new('3.3.2')
+ v2 = Version.new('2.2.2')
+ expect(v1 < v2).to be false
+ end
+ it "v1>v2 is true when v1>v2" do
+ v1 = Version.new('3.3.2')
+ v2 = Version.new('2.2.2')
+ expect(v1 > v2).to be true
+ end
+ it "v1>v2 is false when v1<=v2" do
+ v1 = Version.new('2.3.2')
+ v2 = Version.new('3.2.2')
+ expect(v1 > v2).to be false
+ end
+
+ it "v1 == v2 is true when v1 == v2" do
+ v1 = Version.new('2.3.2')
+ v2 = Version.new('2.3.2')
+ expect(v1 == v2).to be true
+ end
+ it "v1 == v2 is false when v1 != v2" do
+ v1 = Version.new('2.3.2')
+ v2 = Version.new('3.2.2')
+ expect(v1 == v2).to be false
+ end
+ it "v1!=v2 is true when v1!=v2" do
+ v1 = Version.new('3.3.2')
+ v2 = Version.new('2.2.2')
+ expect(v1 != v2).to be true
+ end
+ it "v1!=v2 is false when v1 == v2" do
+ v1 = Version.new('2.3.2')
+ v2 = Version.new('2.3.2')
+ expect(v1 != v2).to be false
+ end
+ end
+
+ describe '#to_s' do
+ it 'return good string' do
+ expect(Version.new('4.5.2').to_s).to eq '4.5.2'
+ end
+ end
+
+ describe '#components' do
+ it "return good array when called without argument" do
+ expect(Version.new('4.5.7').components).to eq [4, 5, 7]
+ end
+ it "return good array when called without argument and
+ last component is 0" do
+ expect(Version.new('0.4.0').components).to eq [0, 4]
+ end
+ it "return good array when called with argument" do
+ expect(Version.new('2.4.1').components(2)).to eq [2, 4]
+ end
+ it 'return good array when called with argument 1 and
+ second component is 0' do
+ expect(Version.new('4.0.0').components(1)).to eq [4]
+ end
+ end
+end
+
+RSpec.describe "Version::Range" do
+ describe '#include?' do
+ before do
+ @range = Version::Range.new('1.3.2', '4.2.3')
+ end
+ it 'return true with good argument' do
+ expect(@range.include?('3.3.2')).to be true
+ end
+ it 'return false with argument < start_version' do
+ expect(@range.include?('0.2.3')).to be false
+ end
+ it 'return false with argument > end_version' do
+ expect(@range.include?('5.2.3')).to be false
+ end
+ it 'return true when argument == start_version' do
+ expect(@range.include?('1.3.2')).to be true
+ end
+ it 'return false when argument == end_version' do
+ expect(@range.include?(Version.new('4.2.3'))).to be false
+ end
+ end
+ describe '#to_a' do
+ it 'return good array' do
+ expect(Version::Range.new('1.9.7', '2.0.1').to_a)
+ .to eq ['1.9.7', '1.9.8', '1.9.9', '2']
+ end
+ it 'return empty array when start_version>end_version' do
+ expect(Version::Range.new('2.9.7', '2.0.1').to_a).to eq []
+ end
+ end
+end