Решение на Четвърта задача - Unit тестване от Малина Демирова

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

Към профила на Малина Демирова

Резултати

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

Код

RSpec.describe Version do
describe '#version' do
it 'can look for valid versions' do
input = '1.2.1'
expect(Version.new(input).components.to_s).to eq '[1, 2, 1]'
end
it 'can look for valid versions with zeros' do
input = '1.2.0'
expect(Version.new(input).components.to_s).to eq '[1, 2]'
end
it 'can look for wrong versions .3' do
output = "Invalid version string \'.3\'"
expect { Version.new('.3') }.to raise_error(ArgumentError, output)
end
it 'can look for wrong versions 0..3' do
output = "Invalid version string \'0..3\'"
expect { Version.new('0..3') }.to raise_error(ArgumentError, output)
end
end
describe '#comparing' do
it 'can compare correctly using <' do
expect(Version.new('1.2.3') < Version.new('1.3.1')).to eq true
end
it 'can compare correctly using <' do
expect(Version.new('4.2.3') < Version.new('3.3.1')).to eq false
end
it 'can compare correctly using >' do
expect(Version.new('1.2.3') > Version.new('1.2.0')).to eq true
end
it 'can compare correctly using >' do
expect(Version.new('7.2.0') > Version.new('8.2.0')).to eq false
end
it 'can compare correctly using ==' do
expect(Version.new('1.2.3') == Version.new('1.0.3')).to eq false
end
it 'can compare correctly using >=' do
expect(Version.new('1.2.3') >= Version.new('1.0.3')).to eq true
end
end
describe '#converting' do
it 'can convert from 1.2.3' do
expect(Version.new('1.2.3').components.to_s).to eq '[1, 2, 3]'
end
it 'can convert from 1.2.0' do
expect(Version.new('1.2.0').components.to_s).to eq '[1, 2]'
end
it 'can convert from 1.0.0' do
expect(Version.new('1.0.0').components.to_s).to eq '[1]'
end
it 'can convert from 4.0.3' do
expect(Version.new('4.0.3').components.to_s).to eq '[4, 0, 3]'
end
end
describe '#components' do
it 'can return correctly 2 of 2 components' do
expect(Version.new('4.5').components.to_s).to eq '[4, 5]'
end
it 'can return correctly 3 of 4 components' do
expect(Version.new('4.0.3.0').components.to_s).to eq '[4, 0, 3]'
end
end
describe Version::Range do
describe 'Range#include?' do
it 'can include correctly numbers' do
first = Version.new('1')
second = Version.new('2')
third = Version.new('1.5')
expect((Version::Range.new(first, second).include? third)).to eq true
end
it 'can include correctly numbers' do
first = Version.new('1')
second = Version.new('1.2.3')
third = Version.new('1.1.2')
expect((Version::Range.new(first, second).include? third)).to eq true
end
it 'can include correctly numbers' do
first = Version.new('2.3.4')
second = Version.new('2')
third = Version.new('1.5')
expect((Version::Range.new(first, second).include? third)).to eq false
end
it 'can include correctly numbers' do
first = Version.new('2')
second = Version.new('3.4.4')
third = Version.new('3.4.0')
expect((Version::Range.new(first, second).include? third)).to eq true
end
end
describe 'Range#to_a' do
it 'can return correctly all numbers between 1.1.0 and 1.2.2' do
first = Version.new('1.1.0')
second = Version.new('1.2.2')
output = [
'1.1', '1.1.1', '1.1.2', '1.1.3', '1.1.4', '1.1.5', '1.1.6',
'1.1.7', '1.1.8', '1.1.9', '1.2', '1.2.1'
]
expect(Version::Range.new(first, second).to_a).to eq output
end
it 'can return correctly all numbers between 1.4.5 and 1.5.5' do
first = Version.new('1.4.5')
second = Version.new('1.5.5')
output = [
'1.4.5', '1.4.6', '1.4.7', '1.4.8', '1.4.9', '1.5', '1.5.1',
'1.5.2', '1.5.3', '1.5.4'
]
expect(Version::Range.new(first, second).to_a).to eq output
end
it 'can return correctly all numbers between 1.1.0 and 1.1' do
first = Version.new('1.1.0')
second = Version.new('1.1')
output = []
expect(Version::Range.new(first, second).to_a).to eq output
end
it 'can return correctly all numbers between 1.1 and 1.2' do
first = Version.new('1.1')
second = Version.new('1.2')
output = [
'1.1', '1.1.1', '1.1.2', '1.1.3', '1.1.4', '1.1.5', '1.1.6',
'1.1.7', '1.1.8', '1.1.9'
]
expect(Version::Range.new(first, second).to_a).to eq output
end
end
end
end

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

...FFFF.FFF.F..F...

Failures:

  1) 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-1qb84n5/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)>'

  2) 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-1qb84n5/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)>'

  3) 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-1qb84n5/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)>'

  4) 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-1qb84n5/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)>'

  5) spec Version tests #components with less 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
               @components + [0] * padding_size
             elsif positions != 0
               [42, 42, 42, 42, 42]
             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-1qb84n5/spec.rb:420: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-1qb84n5/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-1qb84n5/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 strings
     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 = start_version
               @end_version   = 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-1qb84n5/spec.rb:479: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)>'

  9) spec Version::Range tests include? with versions greater than the start one
     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
             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-1qb84n5/spec.rb:512: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, 9 failures

Failed examples:

rspec /tmp/d20161119-19072-1qb84n5/spec.rb:279 # spec Version checks that initialize can be given an empty string
rspec /tmp/d20161119-19072-1qb84n5/spec.rb:298 # spec Version checks that initialize can be given no arguments
rspec /tmp/d20161119-19072-1qb84n5/spec.rb:317 # spec Version checks for comparison operators positively
rspec /tmp/d20161119-19072-1qb84n5/spec.rb:353 # spec Version checks for comparison operators negatively
rspec /tmp/d20161119-19072-1qb84n5/spec.rb:405 # spec Version tests #components with less components than present
rspec /tmp/d20161119-19072-1qb84n5/spec.rb:423 # spec Version tests #components with more components than present
rspec /tmp/d20161119-19072-1qb84n5/spec.rb:441 # spec Version tests that #components cannot be used to modify the version
rspec /tmp/d20161119-19072-1qb84n5/spec.rb:471 # spec Version::Range tests constructing ranges with strings
rspec /tmp/d20161119-19072-1qb84n5/spec.rb:505 # spec Version::Range tests include? with versions greater than the start one

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

Малина обнови решението на 18.11.2016 00:04 (преди над 1 година)

+RSpec.describe Version do
+ describe '#version' do
+ it 'can look for valid versions' do
+ input = '1.2.1'
+ expect(Version.new(input).components.to_s).to eq '[1, 2, 1]'
+ end
+
+ it 'can look for valid versions with zeros' do
+ input = '1.2.0'
+ expect(Version.new(input).components.to_s).to eq '[1, 2]'
+ end
+
+ it 'can look for wrong versions' do
+ expect(ArgumentError)
+ end
+ end
+
+ describe '#comparing' do
+ it 'can compare correctly using <' do
+ expect(Version.new('1.2.3') < Version.new('1.3.1')).to eq true
+ end
+
+ it 'can compare correctly using <' do
+ expect(Version.new('4.2.3') < Version.new('3.3.1')).to eq false
+ end
+
+ it 'can compare correctly using >' do
+ expect(Version.new('1.2.3') > Version.new('1.2.0')).to eq true
+ end
+
+ it 'can compare correctly using >' do
+ expect(Version.new('7.2.0') > Version.new('8.2.0')).to eq false
+ end
+
+ it 'can compare correctly using ==' do
+ expect(Version.new('1.2.3') == Version.new('1.0.3')).to eq false
+ end
+
+ it 'can compare correctly using >=' do
+ expect(Version.new('1.2.3') >= Version.new('1.0.3')).to eq true
+ end
+ end
+
+ describe '#converting' do
+ it 'can convert from 1.2.3' do
+ expect(Version.new('1.2.3').components.to_s).to eq '[1, 2, 3]'
+ end
+
+ it 'can convert from 1.2.0' do
+ expect(Version.new('1.2.0').components.to_s).to eq '[1, 2]'
+ end
+
+ it 'can convert from 1.0.0' do
+ expect(Version.new('1.0.0').components.to_s).to eq '[1]'
+ end
+
+ it 'can convert from 4.0.3' do
+ expect(Version.new('4.0.3').components.to_s).to eq '[4, 0, 3]'
+ end
+ end
+
+ describe '#components' do
+ it 'can return correctly 2 of 2 components' do
+ expect(Version.new('4.5').components.to_s).to eq '[4, 5]'
+ end
+
+ it 'can return correctly 3 of 4 components' do
+ expect(Version.new('4.0.3.0').components.to_s).to eq '[4, 0, 3]'
+ end
+ end
+end

Малина обнови решението на 18.11.2016 22:00 (преди над 1 година)

RSpec.describe Version do
describe '#version' do
it 'can look for valid versions' do
input = '1.2.1'
expect(Version.new(input).components.to_s).to eq '[1, 2, 1]'
end
it 'can look for valid versions with zeros' do
input = '1.2.0'
expect(Version.new(input).components.to_s).to eq '[1, 2]'
end
- it 'can look for wrong versions' do
- expect(ArgumentError)
+ it 'can look for wrong versions .3' do
+ output = "Invalid version string \'.3\'"
+ expect { Version.new('.3') }.to raise_error(ArgumentError, output)
+ end
+
+ it 'can look for wrong versions 0..3' do
+ output = "Invalid version string \'0..3\'"
+ expect { Version.new('0..3') }.to raise_error(ArgumentError, output)
end
end
describe '#comparing' do
it 'can compare correctly using <' do
expect(Version.new('1.2.3') < Version.new('1.3.1')).to eq true
end
it 'can compare correctly using <' do
expect(Version.new('4.2.3') < Version.new('3.3.1')).to eq false
end
it 'can compare correctly using >' do
expect(Version.new('1.2.3') > Version.new('1.2.0')).to eq true
end
it 'can compare correctly using >' do
expect(Version.new('7.2.0') > Version.new('8.2.0')).to eq false
end
it 'can compare correctly using ==' do
expect(Version.new('1.2.3') == Version.new('1.0.3')).to eq false
end
it 'can compare correctly using >=' do
expect(Version.new('1.2.3') >= Version.new('1.0.3')).to eq true
end
end
describe '#converting' do
it 'can convert from 1.2.3' do
expect(Version.new('1.2.3').components.to_s).to eq '[1, 2, 3]'
end
it 'can convert from 1.2.0' do
expect(Version.new('1.2.0').components.to_s).to eq '[1, 2]'
end
it 'can convert from 1.0.0' do
expect(Version.new('1.0.0').components.to_s).to eq '[1]'
end
it 'can convert from 4.0.3' do
expect(Version.new('4.0.3').components.to_s).to eq '[4, 0, 3]'
end
end
describe '#components' do
it 'can return correctly 2 of 2 components' do
expect(Version.new('4.5').components.to_s).to eq '[4, 5]'
end
it 'can return correctly 3 of 4 components' do
expect(Version.new('4.0.3.0').components.to_s).to eq '[4, 0, 3]'
end
end
end

Малина обнови решението на 18.11.2016 22:34 (преди над 1 година)

RSpec.describe Version do
describe '#version' do
it 'can look for valid versions' do
input = '1.2.1'
expect(Version.new(input).components.to_s).to eq '[1, 2, 1]'
end
it 'can look for valid versions with zeros' do
input = '1.2.0'
expect(Version.new(input).components.to_s).to eq '[1, 2]'
end
it 'can look for wrong versions .3' do
output = "Invalid version string \'.3\'"
expect { Version.new('.3') }.to raise_error(ArgumentError, output)
end
it 'can look for wrong versions 0..3' do
output = "Invalid version string \'0..3\'"
expect { Version.new('0..3') }.to raise_error(ArgumentError, output)
end
end
describe '#comparing' do
it 'can compare correctly using <' do
expect(Version.new('1.2.3') < Version.new('1.3.1')).to eq true
end
it 'can compare correctly using <' do
expect(Version.new('4.2.3') < Version.new('3.3.1')).to eq false
end
it 'can compare correctly using >' do
expect(Version.new('1.2.3') > Version.new('1.2.0')).to eq true
end
it 'can compare correctly using >' do
expect(Version.new('7.2.0') > Version.new('8.2.0')).to eq false
end
it 'can compare correctly using ==' do
expect(Version.new('1.2.3') == Version.new('1.0.3')).to eq false
end
it 'can compare correctly using >=' do
expect(Version.new('1.2.3') >= Version.new('1.0.3')).to eq true
end
end
describe '#converting' do
it 'can convert from 1.2.3' do
expect(Version.new('1.2.3').components.to_s).to eq '[1, 2, 3]'
end
it 'can convert from 1.2.0' do
expect(Version.new('1.2.0').components.to_s).to eq '[1, 2]'
end
it 'can convert from 1.0.0' do
expect(Version.new('1.0.0').components.to_s).to eq '[1]'
end
it 'can convert from 4.0.3' do
expect(Version.new('4.0.3').components.to_s).to eq '[4, 0, 3]'
end
end
describe '#components' do
it 'can return correctly 2 of 2 components' do
expect(Version.new('4.5').components.to_s).to eq '[4, 5]'
end
it 'can return correctly 3 of 4 components' do
expect(Version.new('4.0.3.0').components.to_s).to eq '[4, 0, 3]'
end
end
+
+ describe Version::Range do
+ describe 'Range#include?' do
+ it 'can include correctly numbers' do
+ first = Version.new('1')
+ second = Version.new('2')
+ third = Version.new('1.5')
+ expect((Version::Range.new(first, second).include? third)).to eq true
+ end
+
+ it 'can include correctly numbers' do
+ first = Version.new('1')
+ second = Version.new('1.2.3')
+ third = Version.new('1.1.2')
+ expect((Version::Range.new(first, second).include? third)).to eq true
+ end
+
+ it 'can include correctly numbers' do
+ first = Version.new('2.3.4')
+ second = Version.new('2')
+ third = Version.new('1.5')
+ expect((Version::Range.new(first, second).include? third)).to eq false
+ end
+
+ it 'can include correctly numbers' do
+ first = Version.new('2')
+ second = Version.new('3.4.4')
+ third = Version.new('3.4.0')
+ expect((Version::Range.new(first, second).include? third)).to eq true
+ end
+ end
+
+ describe 'Range#to_a' do
+ it 'can return correctly all numbers between 1.1.0 and 1.2.2' do
+ first = Version.new('1.1.0')
+ second = Version.new('1.2.2')
+ output = [
+ '1.1', '1.1.1', '1.1.2', '1.1.3', '1.1.4', '1.1.5', '1.1.6',
+ '1.1.7', '1.1.8', '1.1.9', '1.2', '1.2.1'
+ ]
+ expect(Version::Range.new(first, second).to_a).to eq output
+ end
+
+ it 'can return correctly all numbers between 1.4.5 and 1.5.5' do
+ first = Version.new('1.4.5')
+ second = Version.new('1.5.5')
+ output = [
+ '1.4.5', '1.4.6', '1.4.7', '1.4.8', '1.4.9', '1.5', '1.5.1',
+ '1.5.2', '1.5.3', '1.5.4'
+ ]
+ expect(Version::Range.new(first, second).to_a).to eq output
+ end
+
+ it 'can return correctly all numbers between 1.1.0 and 1.1' do
+ first = Version.new('1.1.0')
+ second = Version.new('1.1')
+ output = []
+ expect(Version::Range.new(first, second).to_a).to eq output
+ end
+
+ it 'can return correctly all numbers between 1.1 and 1.2' do
+ first = Version.new('1.1')
+ second = Version.new('1.2')
+ output = [
+ '1.1', '1.1.1', '1.1.2', '1.1.3', '1.1.4', '1.1.5', '1.1.6',
+ '1.1.7', '1.1.8', '1.1.9'
+ ]
+ expect(Version::Range.new(first, second).to_a).to eq output
+ end
+ end
+ end
end