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

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

Към профила на Лазар Дилов

Резултати

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

Код

RSpec.describe Version do
describe '#<=>' do
context 'when first is bigger' do
it 'compares higher version with lower' do
expect(Version.new("3.2.2") <=> '1.2.3').to eq 1
expect(Version.new("3.2.2") <=> '3.2.1').to eq 1
expect(Version.new("3.2.2") <=> '3.1.3').to eq 1
end
it 'compares versions with different lengths' do
expect(Version.new("3.2.2") <=> '3.2').to eq 1
expect(Version.new("3.2.2") <=> '2.5.9.9').to eq 1
expect(Version.new("3.2.2") <=> '2').to eq 1
end
it 'compares versions containing zero' do
expect(Version.new("3.2.2") <=> '0.2.2').to eq 1
expect(Version.new("3.2.2") <=> '3.0.2').to eq 1
expect(Version.new("3.2.2") <=> '3.2.0').to eq 1
expect(Version.new("0.2.2") <=> '0.0.2').to eq 1
expect(Version.new("0.2.2") <=> '0.1.5').to eq 1
end
end
context 'when first is lower' do
it 'compares lower version with higher' do
expect(Version.new("1.2.3") <=> '1.2.4').to eq -1
expect(Version.new("1.2.3") <=> '1.3.2').to eq -1
expect(Version.new("1.2.3") <=> '2.3.4').to eq -1
expect(Version.new("1.2.3") <=> '2.1.1').to eq -1
end
it 'compares versions with different lengths' do
version = Version.new("2.3")
expect(version <=> '2.3.4').to eq -1
expect(version <=> '3.1.1').to eq -1
expect(version <=> '3').to eq -1
end
it 'compares versions containing zero' do
expect(Version.new("2.3.4") <=> '3.0.0').to eq -1
expect(Version.new("2.3.4") <=> '2.4.0').to eq -1
expect(Version.new("0.3.4") <=> '1.0.0').to eq -1
expect(Version.new("0.3.4") <=> '0.4.0').to eq -1
end
end
context 'when they are equal' do
it 'compares versions with different lengths' do
expect(Version.new("3.2.2") <=> '3.2.2.0').to eq 0
end
it 'comparing equal versions' do
expect(Version.new("3.2.2") <=> '3.2.2').to eq 0
end
it 'compares versions containing zero' do
expect(Version.new("3.0.2") <=> '3.0.2').to eq 0
expect(Version.new("0.0.2") <=> '0.0.2').to eq 0
end
end
end
describe '#components' do
context 'when padding > 0' do
version = Version.new("1.2.3.4")
it 'checks with positive argument' do
expect(version.components(6)).to match_array [1, 2, 3, 4, 0, 0]
end
it 'checks with argument = 0' do
expect(version.components(0)).to match_array [1, 2, 3, 4]
end
end
context 'when padding = 0' do
version = Version.new("1.2.3.4")
it 'checks with argument' do
expect(version.components(4)).to match_array [1, 2, 3, 4]
end
end
context 'when padding < 0' do
version = Version.new("1.2.3.4")
it 'checks without argument' do
expect(version.components).to match_array [1, 2, 3, 4]
end
it 'checks with argument < 0' do
expect(version.components(-2)).to match_array
[
3, 4
]
end
it 'checks with argument > 0' do
expect(version.components(2)).to match_array [1, 2]
end
end
context 'when version contains zero' do
it 'check with zeros in the end' do
version = Version.new("1.2.0.0")
expect(version.components).to match_array [1, 2]
end
it 'checks with zeros in the beginning' do
version = Version.new("0.0.1.2")
expect(version.components).to match_array [1, 2]
end
end
end
describe '#to_s' do
it 'check with simple versions' do
expect(Version.new("2.3").to_s).to eq '2.3'
end
it 'check with more complex versions' do
expect(Version.new("2.0.3").to_s).to eq '2.0.3'
expect(Version.new("0.0.3").to_s).to eq '0.0.3'
end
end
describe '#<' do
it 'checks if version1 < version2' do
expect(Version.new("2.3") < Version.new("2.4")).to be true
expect(Version.new("0.2.3") < Version.new("0.2.4")).to be true
expect(Version.new("1.0.0") < Version.new("1")).to be false
end
end
describe '#>' do
it 'checks if version1 > version2' do
expect(Version.new("2.4") > Version.new("2.3")).to be true
expect(Version.new("0.2.4") > Version.new("0.2.3")).to be true
expect(Version.new("1.0.0") > Version.new("1")).to be false
end
end
describe '#==' do
it 'checks if version1 == version2' do
expect(Version.new("1.0.0") == Version.new("1")).to be false
expect(Version.new("0.1") == Version.new("1")).to be false
end
end
describe '#<=' do
it 'checks if version1 <= version2' do
expect(Version.new("2.3") < Version.new("2.4")).to be true
expect(Version.new("0.2.3") < Version.new("0.2.4")).to be true
expect(Version.new("1.0.0") < Version.new("1")).to be false
end
end
describe '#>=' do
it 'checks if version1 > version2' do
expect(Version.new("2.4") > Version.new("2.3")).to be true
expect(Version.new("0.2.4") > Version.new("0.2.3")).to be true
expect(Version.new("1.0.0") > Version.new("1")).to be false
end
end
describe Range do
describe "#include?" do
it "checks simple versions" do
range = Version::Range.new(Version.new('1'), Version.new('2'))
expect((range.include? Version.new('1.5'))).to be true
expect((range.include? Version.new('1'))).to be true
expect((range.include? Version.new('1.0'))).to be true
range = Version::Range.new(Version.new('0'), Version.new('1'))
expect((range.include? Version.new('0.5'))).to be true
expect((range.include? Version.new('0.0.0.1'))).to be true
end
end
describe "#to_a" do
it "cheks with simple versions" do
range = Version::Range.new(Version.new('0.1'), Version.new('0.2'))
expect(range.to_a).to match_array [
'0.1', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5',
'0.1.6', '0.1.7', '0.1.8', '0.1.9'
]
# Това не знам дали е вярно - дали 0.1.0 трябва да е в тази област
expect(range.to_a).to match_array [
'0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5',
'0.1.6', '0.1.7', '0.1.8', '0.1.9'
]
range = Version::Range.new(Version.new('0.1'), Version.new('0.1'))
expect(range.to_a).to match_array []
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..F....F...F
         
         Failures:
         
           1) Version#components when padding < 0 checks with argument < 0
              Failure/Error: expect(version.components(-2)).to match_array
              ArgumentError:
                attempt to take negative size
              # ./solution.rb:41:in `take'
              # ./solution.rb:41:in `components'
              # ./solution_spec.rb:77:in `block (4 levels) in <top (required)>'
         
           2) Version#components when version contains zero checks with zeros in the beginning
              Failure/Error: expect(version.components).to match_array [1, 2]
                expected collection contained:  [1, 2]
                actual collection contained:    [0, 0, 1, 2]
                the extra elements were:        [0, 0]
              # ./solution_spec.rb:93:in `block (4 levels) in <top (required)>'
         
           3) Version#== checks if version1 == version2
              Failure/Error: expect(Version.new("1.0.0") == Version.new("1")).to be false
                
                expected #<FalseClass:0> => false
                     got #<TrueClass:20> => true
                
                Compared using equal?, which compares object identity,
                but expected and actual are not the same object. Use
                `expect(actual).to eq(expected)` if you don't care about
                object identity in this example.
              # ./solution_spec.rb:122:in `block (3 levels) in <top (required)>'
         
           4) Version Range #to_a cheks with simple versions
              Failure/Error: expect(range.to_a).to match_array [
                expected collection contained:  ["0.1", "0.1.1", "0.1.2", "0.1.3", "0.1.4", "0.1.5", "0.1.6", "0.1.7", "0.1.8", "0.1.9"]
                actual collection contained:    [#<Version:0x007fae59e15438 @components=[0, 1]>, #<Version:0x007fae59e12238 @components=[0, 1, 1]>, #<Version:0x007fae59e11310 @components=[0, 1, 2]>, #<Version:0x007fae59e10528 @components=[0, 1, 3]>, #<Version:0x007fae59e0b5a0 @components=[0, 1, 4]>, #<Version:0x007fae59e0a4c0 @components=[0, 1, 5]>, #<Version:0x007fae59e075b8 @components=[0, 1, 6]>, #<Version:0x007fae59e06ac8 @components=[0, 1, 7]>, #<Version:0x007fae59e04f98 @components=[0, 1, 8]>, #<Version:0x007fae59dfff70 @components=[0, 1, 9]>]
                the missing elements were:      ["0.1", "0.1.1", "0.1.2", "0.1.3", "0.1.4", "0.1.5", "0.1.6", "0.1.7", "0.1.8", "0.1.9"]
              # ./solution_spec.rb:155:in `block (4 levels) in <top (required)>'
         
         Finished in 0.01222 seconds
         26 examples, 4 failures
         
         Failed examples:
         
         rspec ./solution_spec.rb:76 # Version#components when padding < 0 checks with argument < 0
         rspec ./solution_spec.rb:91 # Version#components when version contains zero checks with zeros in the beginning
         rspec ./solution_spec.rb:121 # Version#== checks if version1 == version2
         rspec ./solution_spec.rb:153 # Version Range #to_a cheks with simple versions
     # /tmp/d20161119-19072-8oeoz6/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.74656 seconds
1 example, 1 failure

Failed examples:

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

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

Лазар обнови решението на 16.11.2016 09:36 (преди над 1 година)

+RSpec.describe Version do
+ describe '#<=>' do
+ context 'when first is bigger' do
+ it 'compares higher version with lower' do
+ version = Version.new("3.2.2")
+ expect(version <=> '1.2.3').to eq 1
+ expect(version <=> '3.2.1').to eq 1
+ expect(version <=> '4.2.2').to eq 1
+ expect(version <=> '3.1.3').to eq 1
+ end
+ it 'compares versions with different lengths' do
+ version = Version.new("3.2.2")
+ expect(version <=> '3.2').to eq 1
+ expect(version <=> '2.5.9.9').to eq 1
+ expect(version <=> '2').to eq 1
+ end
+ it 'compares versions containing zero' do
+ version = Version.new("3.2.2")
+ expect(version <=> '0.2.2').to eq 1
+ expect(version <=> '3.0.2').to eq 1
+ expect(version <=> '3.2.0').to eq 1
+ version = Version.new("0.2.2")
+ expect(version <=> '0.0.2').to eq 1
+ expect(version <=> '0.1.5').to eq 1
+ end
+ end
+ context 'when first is lower' do
+ it 'compares lower version with higher' do
+ version = Version.new("1.2.3")
+ expect(version <=> '1.2.4').to eq -1
+ expect(version <=> '1.3.2').to eq -1
+ expect(version <=> '2.3.4').to eq -1
+ expect(version <=> '2.1.1').to eq -1
+ end
+ it 'compares versions with different lengths' do
+ version = Version.new("2.3")
+ expect(version <=> '2.3.4').to eq -1
+ expect(version <=> '3.1.1').to eq -1
+ expect(version <=> '3').to eq -1
+ end
+ it 'compares versions containing zero' do
+ version = Version.new("2.3.4")
+ expect(version <=> '3.0.0').to eq -1
+ expect(version <=> '2.4.0').to eq -1
+ version = Version.new("0.3.4")
+ expect(version <=> '1.0.0').to eq -1
+ expect(version <=> '0.4.0').to eq -1
+ end
+ end
+ context 'when they are equal' do
+ it 'compares versions with different lengths' do
+ version = Version.new("3.2.2")
+ expect(version <=> '3.2.2.0').to eq 0
+ end
+ it 'comparing equal versions' do
+ version = Version.new("3.2.2")
+ expect(version <=> '3.2.2').to eq 0
+ end
+ it 'compares versions containing zero' do
+ version = Version.new("3.0.2")
+ expect(version <=> '3.0.2').to eq 0
+ version = Version.new("0.0.2")
+ expect(version <=> '0.0.2').to eq 0
+ end
+ end
+ end
+ describe '#components' do
+ context 'when padding > 0' do
+ version = Version.new("1.2.3.4")
+ it 'checks with positive argument' do
+ expect(version.components(6)).to match_array
+ [
+ 11, 2, 3, 4, 0, 0
+ ]
+ end
+ it 'checks with argument = 0' do
+ expect(version.components(0)).to match_array
+ [
+ 1, 2, 3, 4
+ ]
+ end
+ end
+ context 'when padding = 0' do
+ version = Version.new("1.2.3.4")
+ it 'checks with argument' do
+ expect(version.components(4)).to match_array
+ [
+ 1, 2, 3, 4
+ ]
+ end
+ end
+ context 'when padding < 0' do
+ version = Version.new("1.2.3.4")
+ it 'checks without argument' do
+ expect(version.components).to match_array
+ [
+ 1, 2, 3, 4
+ ]
+ end
+ it 'checks with argument < 0' do
+ expect(version.components(-2)).to match_array
+ [
+ 3, 4
+ ]
+ end
+ it 'checks with argument > 0' do
+ expect(version.components(2)).to match_array
+ [
+ 1, 2
+ ]
+ end
+ end
+ context 'when version contains zero' do
+ it 'check with zeros in the end' do
+ version = Version.new("1.2.0.0")
+ expect(version.components).to match_array
+ [
+ 1, 2
+ ]
+ end
+ it 'checks with zeros in the beginning' do
+ version = Version.new("0.0.1.2")
+ expect(version.components).to match_array
+ [
+ 1, 2
+ ]
+ end
+ end
+ end
+ describe '#<' do
+ it 'checks if version1 < version2' do
+ version1 = Version.new("2.3")
+ version2 = Version.new("2.4")
+ expect(version1 < version2).to be true
+ version1 = Version.new("0.2.3")
+ version2 = Version.new("0.2.4")
+ expect(version1 < version2).to be true
+ version1 = Version.new("1.0.0")
+ version2 = Version.new("1")
+ expect(version1 < version2).to be false
+ end
+ end
+ describe '#>' do
+ it 'checks if version1 > version2' do
+ version1 = Version.new("2.4")
+ version2 = Version.new("2.3")
+ expect(version1 > version2).to be true
+ version1 = Version.new("0.2.4")
+ version2 = Version.new("0.2.3")
+ expect(version1 > version2).to be true
+ version1 = Version.new("1.0.0")
+ version2 = Version.new("1")
+ expect(version1 > version2).to be false
+ end
+ end
+ describe '#==' do
+ it 'checks if version1 == version2' do
+ version1 = Version.new("2.4")
+ version2 = Version.new("2.4")
+ expect(version1 == version2).to be true
+ version1 = Version.new("0.2.4")
+ version2 = Version.new("0.2.4")
+ expect(version1 == version2).to be true
+ version1 = Version.new("1.0.0")
+ version2 = Version.new("1")
+ expect(version1 == version2).to be false
+ version1 = Version.new("0.1")
+ version2 = Version.new("1")
+ expect(version1 == version2).to be false
+ end
+ end
+ describe '#<=' do
+ it 'checks if version1 <= version2' do
+ version1 = Version.new("2.3")
+ version2 = Version.new("2.4")
+ expect(version1 < version2).to be true
+ version1 = Version.new("0.2.3")
+ version2 = Version.new("0.2.4")
+ expect(version1 < version2).to be true
+ version1 = Version.new("1.0.0")
+ version2 = Version.new("1")
+ expect(version1 < version2).to be false
+ version1 = Version.new("0.2.4")
+ version2 = Version.new("0.2.4")
+ expect(version1 <= version2).to be true
+ version1 = Version.new("2.4")
+ version2 = Version.new("2.4")
+ expect(version1 <= version2).to be true
+ end
+ end
+ describe '#>=' do
+ it 'checks if version1 > version2' do
+ version1 = Version.new("2.4")
+ version2 = Version.new("2.3")
+ expect(version1 > version2).to be true
+ version1 = Version.new("0.2.4")
+ version2 = Version.new("0.2.3")
+ expect(version1 > version2).to be true
+ version1 = Version.new("1.0.0")
+ version2 = Version.new("1")
+ expect(version1 > version2).to be false
+ version1 = Version.new("0.2.4")
+ version2 = Version.new("0.2.4")
+ expect(version1 >= version2).to be true
+ version1 = Version.new("2.4")
+ version2 = Version.new("2.4")
+ expect(version1 >= version2).to be true
+ end
+ end
+ describe Range do
+ describe "#include?" do
+ it "checks simple versions" do
+ range = Version::Range.new(Version.new('1'), Version.new('2'))
+ version = Version.new('1.5')
+ expect((range.include? version)).to be true
+ version = Version.new('1')
+ expect((range.include? version)).to be true
+ version = Version.new('1.0')
+ expect((range.include? version)).to be true
+ range = Version::Range.new(Version.new('0'), Version.new('1'))
+ expect((range.include? Version.new('0.5'))).to be true
+ expect((range.include? Version.new('0.0.0.1'))).to be true
+ end
+ end
+ describe "#to_a" do
+ it "cheks with simple versions" do
+ range = Version::Range.new(Version.new('0.1'), Version.new('0.2'))
+ expect(range.to_a).to match_array
+ [
+ '0.1', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6',
+ '0.1.7', '0.1.8', '0.1.9'
+ ]
+
+ # Това не знам дали е вярно - дали 0.1.0 трябва да е в тази област
+ expect(range.to_a).to match_array
+ [
+ '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6',
+ '0.1.7', '0.1.8', '0.1.9'
+ ]
+ end
+ end
+ end
+end

Лазар обнови решението на 16.11.2016 12:07 (преди над 1 година)

RSpec.describe Version do
describe '#<=>' do
context 'when first is bigger' do
it 'compares higher version with lower' do
version = Version.new("3.2.2")
expect(version <=> '1.2.3').to eq 1
expect(version <=> '3.2.1').to eq 1
- expect(version <=> '4.2.2').to eq 1
expect(version <=> '3.1.3').to eq 1
end
it 'compares versions with different lengths' do
version = Version.new("3.2.2")
expect(version <=> '3.2').to eq 1
expect(version <=> '2.5.9.9').to eq 1
expect(version <=> '2').to eq 1
end
it 'compares versions containing zero' do
version = Version.new("3.2.2")
expect(version <=> '0.2.2').to eq 1
expect(version <=> '3.0.2').to eq 1
expect(version <=> '3.2.0').to eq 1
version = Version.new("0.2.2")
expect(version <=> '0.0.2').to eq 1
expect(version <=> '0.1.5').to eq 1
end
end
context 'when first is lower' do
it 'compares lower version with higher' do
version = Version.new("1.2.3")
expect(version <=> '1.2.4').to eq -1
expect(version <=> '1.3.2').to eq -1
expect(version <=> '2.3.4').to eq -1
expect(version <=> '2.1.1').to eq -1
end
it 'compares versions with different lengths' do
version = Version.new("2.3")
expect(version <=> '2.3.4').to eq -1
expect(version <=> '3.1.1').to eq -1
expect(version <=> '3').to eq -1
end
it 'compares versions containing zero' do
version = Version.new("2.3.4")
expect(version <=> '3.0.0').to eq -1
expect(version <=> '2.4.0').to eq -1
version = Version.new("0.3.4")
expect(version <=> '1.0.0').to eq -1
expect(version <=> '0.4.0').to eq -1
end
end
context 'when they are equal' do
it 'compares versions with different lengths' do
version = Version.new("3.2.2")
expect(version <=> '3.2.2.0').to eq 0
end
it 'comparing equal versions' do
version = Version.new("3.2.2")
expect(version <=> '3.2.2').to eq 0
end
it 'compares versions containing zero' do
version = Version.new("3.0.2")
expect(version <=> '3.0.2').to eq 0
version = Version.new("0.0.2")
expect(version <=> '0.0.2').to eq 0
end
end
end
describe '#components' do
context 'when padding > 0' do
version = Version.new("1.2.3.4")
it 'checks with positive argument' do
- expect(version.components(6)).to match_array
- [
- 11, 2, 3, 4, 0, 0
- ]
+ expect(version.components(6)).to match_array [1, 2, 3, 4, 0, 0]
end
it 'checks with argument = 0' do
- expect(version.components(0)).to match_array
- [
- 1, 2, 3, 4
- ]
+ expect(version.components(0)).to match_array [1, 2, 3, 4]
end
end
context 'when padding = 0' do
version = Version.new("1.2.3.4")
it 'checks with argument' do
- expect(version.components(4)).to match_array
- [
- 1, 2, 3, 4
- ]
+ expect(version.components(4)).to match_array [1, 2, 3, 4]
end
end
context 'when padding < 0' do
version = Version.new("1.2.3.4")
it 'checks without argument' do
- expect(version.components).to match_array
- [
- 1, 2, 3, 4
- ]
+ expect(version.components).to match_array [1, 2, 3, 4]
end
it 'checks with argument < 0' do
expect(version.components(-2)).to match_array
[
3, 4
]
end
it 'checks with argument > 0' do
- expect(version.components(2)).to match_array
- [
- 1, 2
- ]
+ expect(version.components(2)).to match_array [1, 2]
end
end
context 'when version contains zero' do
it 'check with zeros in the end' do
version = Version.new("1.2.0.0")
- expect(version.components).to match_array
- [
- 1, 2
- ]
+ expect(version.components).to match_array [1, 2]
end
it 'checks with zeros in the beginning' do
version = Version.new("0.0.1.2")
- expect(version.components).to match_array
- [
- 1, 2
- ]
+ expect(version.components).to match_array [1, 2]
end
end
end
describe '#<' do
it 'checks if version1 < version2' do
version1 = Version.new("2.3")
version2 = Version.new("2.4")
expect(version1 < version2).to be true
version1 = Version.new("0.2.3")
version2 = Version.new("0.2.4")
expect(version1 < version2).to be true
version1 = Version.new("1.0.0")
version2 = Version.new("1")
expect(version1 < version2).to be false
end
end
describe '#>' do
it 'checks if version1 > version2' do
version1 = Version.new("2.4")
version2 = Version.new("2.3")
expect(version1 > version2).to be true
version1 = Version.new("0.2.4")
version2 = Version.new("0.2.3")
expect(version1 > version2).to be true
version1 = Version.new("1.0.0")
version2 = Version.new("1")
expect(version1 > version2).to be false
end
end
describe '#==' do
it 'checks if version1 == version2' do
version1 = Version.new("2.4")
version2 = Version.new("2.4")
expect(version1 == version2).to be true
version1 = Version.new("0.2.4")
version2 = Version.new("0.2.4")
expect(version1 == version2).to be true
version1 = Version.new("1.0.0")
version2 = Version.new("1")
expect(version1 == version2).to be false
version1 = Version.new("0.1")
version2 = Version.new("1")
expect(version1 == version2).to be false
end
end
describe '#<=' do
it 'checks if version1 <= version2' do
version1 = Version.new("2.3")
version2 = Version.new("2.4")
expect(version1 < version2).to be true
version1 = Version.new("0.2.3")
version2 = Version.new("0.2.4")
expect(version1 < version2).to be true
version1 = Version.new("1.0.0")
version2 = Version.new("1")
expect(version1 < version2).to be false
version1 = Version.new("0.2.4")
version2 = Version.new("0.2.4")
expect(version1 <= version2).to be true
version1 = Version.new("2.4")
version2 = Version.new("2.4")
expect(version1 <= version2).to be true
end
end
describe '#>=' do
it 'checks if version1 > version2' do
version1 = Version.new("2.4")
version2 = Version.new("2.3")
expect(version1 > version2).to be true
version1 = Version.new("0.2.4")
version2 = Version.new("0.2.3")
expect(version1 > version2).to be true
version1 = Version.new("1.0.0")
version2 = Version.new("1")
expect(version1 > version2).to be false
version1 = Version.new("0.2.4")
version2 = Version.new("0.2.4")
expect(version1 >= version2).to be true
version1 = Version.new("2.4")
version2 = Version.new("2.4")
expect(version1 >= version2).to be true
end
end
describe Range do
describe "#include?" do
it "checks simple versions" do
range = Version::Range.new(Version.new('1'), Version.new('2'))
version = Version.new('1.5')
expect((range.include? version)).to be true
version = Version.new('1')
expect((range.include? version)).to be true
version = Version.new('1.0')
expect((range.include? version)).to be true
range = Version::Range.new(Version.new('0'), Version.new('1'))
expect((range.include? Version.new('0.5'))).to be true
expect((range.include? Version.new('0.0.0.1'))).to be true
end
end
describe "#to_a" do
it "cheks with simple versions" do
range = Version::Range.new(Version.new('0.1'), Version.new('0.2'))
- expect(range.to_a).to match_array
- [
- '0.1', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6',
- '0.1.7', '0.1.8', '0.1.9'
- ]
+ expect(range.to_a).to match_array [
+ '0.1', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5',
+ '0.1.6', '0.1.7', '0.1.8', '0.1.9'
+ ]
# Това не знам дали е вярно - дали 0.1.0 трябва да е в тази област
- expect(range.to_a).to match_array
- [
- '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6',
- '0.1.7', '0.1.8', '0.1.9'
- ]
+
+ expect(range.to_a).to match_array [
+ '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5',
+ '0.1.6', '0.1.7', '0.1.8', '0.1.9'
+ ]
+ range = Version::Range.new(Version.new('0.1'), Version.new('0.1'))
+ expect(range.to_a).to match_array []
end
end
end
end

Лазар обнови решението на 16.11.2016 12:13 (преди над 1 година)

RSpec.describe Version do
describe '#<=>' do
context 'when first is bigger' do
it 'compares higher version with lower' do
version = Version.new("3.2.2")
expect(version <=> '1.2.3').to eq 1
expect(version <=> '3.2.1').to eq 1
expect(version <=> '3.1.3').to eq 1
end
it 'compares versions with different lengths' do
version = Version.new("3.2.2")
expect(version <=> '3.2').to eq 1
expect(version <=> '2.5.9.9').to eq 1
expect(version <=> '2').to eq 1
end
it 'compares versions containing zero' do
version = Version.new("3.2.2")
expect(version <=> '0.2.2').to eq 1
expect(version <=> '3.0.2').to eq 1
expect(version <=> '3.2.0').to eq 1
version = Version.new("0.2.2")
expect(version <=> '0.0.2').to eq 1
expect(version <=> '0.1.5').to eq 1
end
end
context 'when first is lower' do
it 'compares lower version with higher' do
version = Version.new("1.2.3")
expect(version <=> '1.2.4').to eq -1
expect(version <=> '1.3.2').to eq -1
expect(version <=> '2.3.4').to eq -1
expect(version <=> '2.1.1').to eq -1
end
it 'compares versions with different lengths' do
version = Version.new("2.3")
expect(version <=> '2.3.4').to eq -1
expect(version <=> '3.1.1').to eq -1
expect(version <=> '3').to eq -1
end
it 'compares versions containing zero' do
version = Version.new("2.3.4")
expect(version <=> '3.0.0').to eq -1
expect(version <=> '2.4.0').to eq -1
version = Version.new("0.3.4")
expect(version <=> '1.0.0').to eq -1
expect(version <=> '0.4.0').to eq -1
end
end
context 'when they are equal' do
it 'compares versions with different lengths' do
version = Version.new("3.2.2")
expect(version <=> '3.2.2.0').to eq 0
end
it 'comparing equal versions' do
version = Version.new("3.2.2")
expect(version <=> '3.2.2').to eq 0
end
it 'compares versions containing zero' do
version = Version.new("3.0.2")
expect(version <=> '3.0.2').to eq 0
version = Version.new("0.0.2")
expect(version <=> '0.0.2').to eq 0
end
end
end
describe '#components' do
context 'when padding > 0' do
version = Version.new("1.2.3.4")
it 'checks with positive argument' do
expect(version.components(6)).to match_array [1, 2, 3, 4, 0, 0]
end
it 'checks with argument = 0' do
expect(version.components(0)).to match_array [1, 2, 3, 4]
end
end
context 'when padding = 0' do
version = Version.new("1.2.3.4")
it 'checks with argument' do
expect(version.components(4)).to match_array [1, 2, 3, 4]
end
end
context 'when padding < 0' do
version = Version.new("1.2.3.4")
it 'checks without argument' do
expect(version.components).to match_array [1, 2, 3, 4]
end
it 'checks with argument < 0' do
expect(version.components(-2)).to match_array
[
3, 4
]
end
it 'checks with argument > 0' do
expect(version.components(2)).to match_array [1, 2]
end
end
context 'when version contains zero' do
it 'check with zeros in the end' do
version = Version.new("1.2.0.0")
expect(version.components).to match_array [1, 2]
end
it 'checks with zeros in the beginning' do
version = Version.new("0.0.1.2")
expect(version.components).to match_array [1, 2]
end
end
end
describe '#<' do
it 'checks if version1 < version2' do
version1 = Version.new("2.3")
version2 = Version.new("2.4")
expect(version1 < version2).to be true
version1 = Version.new("0.2.3")
version2 = Version.new("0.2.4")
expect(version1 < version2).to be true
version1 = Version.new("1.0.0")
version2 = Version.new("1")
expect(version1 < version2).to be false
end
end
describe '#>' do
it 'checks if version1 > version2' do
version1 = Version.new("2.4")
version2 = Version.new("2.3")
expect(version1 > version2).to be true
version1 = Version.new("0.2.4")
version2 = Version.new("0.2.3")
expect(version1 > version2).to be true
version1 = Version.new("1.0.0")
version2 = Version.new("1")
expect(version1 > version2).to be false
end
end
describe '#==' do
it 'checks if version1 == version2' do
version1 = Version.new("2.4")
version2 = Version.new("2.4")
expect(version1 == version2).to be true
version1 = Version.new("0.2.4")
version2 = Version.new("0.2.4")
expect(version1 == version2).to be true
version1 = Version.new("1.0.0")
version2 = Version.new("1")
expect(version1 == version2).to be false
version1 = Version.new("0.1")
version2 = Version.new("1")
expect(version1 == version2).to be false
end
end
describe '#<=' do
it 'checks if version1 <= version2' do
version1 = Version.new("2.3")
version2 = Version.new("2.4")
expect(version1 < version2).to be true
version1 = Version.new("0.2.3")
version2 = Version.new("0.2.4")
expect(version1 < version2).to be true
version1 = Version.new("1.0.0")
version2 = Version.new("1")
expect(version1 < version2).to be false
version1 = Version.new("0.2.4")
version2 = Version.new("0.2.4")
expect(version1 <= version2).to be true
version1 = Version.new("2.4")
version2 = Version.new("2.4")
expect(version1 <= version2).to be true
end
end
describe '#>=' do
it 'checks if version1 > version2' do
version1 = Version.new("2.4")
version2 = Version.new("2.3")
expect(version1 > version2).to be true
version1 = Version.new("0.2.4")
version2 = Version.new("0.2.3")
expect(version1 > version2).to be true
version1 = Version.new("1.0.0")
version2 = Version.new("1")
expect(version1 > version2).to be false
version1 = Version.new("0.2.4")
version2 = Version.new("0.2.4")
expect(version1 >= version2).to be true
version1 = Version.new("2.4")
version2 = Version.new("2.4")
expect(version1 >= version2).to be true
end
end
describe Range do
describe "#include?" do
it "checks simple versions" do
range = Version::Range.new(Version.new('1'), Version.new('2'))
version = Version.new('1.5')
expect((range.include? version)).to be true
version = Version.new('1')
expect((range.include? version)).to be true
version = Version.new('1.0')
expect((range.include? version)).to be true
range = Version::Range.new(Version.new('0'), Version.new('1'))
expect((range.include? Version.new('0.5'))).to be true
expect((range.include? Version.new('0.0.0.1'))).to be true
end
end
describe "#to_a" do
it "cheks with simple versions" do
range = Version::Range.new(Version.new('0.1'), Version.new('0.2'))
expect(range.to_a).to match_array [
'0.1', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5',
'0.1.6', '0.1.7', '0.1.8', '0.1.9'
]
# Това не знам дали е вярно - дали 0.1.0 трябва да е в тази област
expect(range.to_a).to match_array [
'0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5',
'0.1.6', '0.1.7', '0.1.8', '0.1.9'
]
range = Version::Range.new(Version.new('0.1'), Version.new('0.1'))
- expect(range.to_a).to match_array []
+ expect(range.to_a).to match_array ['0.1']
end
end
end
end

Лазар обнови решението на 16.11.2016 12:16 (преди над 1 година)

RSpec.describe Version do
describe '#<=>' do
context 'when first is bigger' do
it 'compares higher version with lower' do
version = Version.new("3.2.2")
expect(version <=> '1.2.3').to eq 1
expect(version <=> '3.2.1').to eq 1
expect(version <=> '3.1.3').to eq 1
end
it 'compares versions with different lengths' do
version = Version.new("3.2.2")
expect(version <=> '3.2').to eq 1
expect(version <=> '2.5.9.9').to eq 1
expect(version <=> '2').to eq 1
end
it 'compares versions containing zero' do
version = Version.new("3.2.2")
expect(version <=> '0.2.2').to eq 1
expect(version <=> '3.0.2').to eq 1
expect(version <=> '3.2.0').to eq 1
version = Version.new("0.2.2")
expect(version <=> '0.0.2').to eq 1
expect(version <=> '0.1.5').to eq 1
end
end
context 'when first is lower' do
it 'compares lower version with higher' do
version = Version.new("1.2.3")
expect(version <=> '1.2.4').to eq -1
expect(version <=> '1.3.2').to eq -1
expect(version <=> '2.3.4').to eq -1
expect(version <=> '2.1.1').to eq -1
end
it 'compares versions with different lengths' do
version = Version.new("2.3")
expect(version <=> '2.3.4').to eq -1
expect(version <=> '3.1.1').to eq -1
expect(version <=> '3').to eq -1
end
it 'compares versions containing zero' do
version = Version.new("2.3.4")
expect(version <=> '3.0.0').to eq -1
expect(version <=> '2.4.0').to eq -1
version = Version.new("0.3.4")
expect(version <=> '1.0.0').to eq -1
expect(version <=> '0.4.0').to eq -1
end
end
context 'when they are equal' do
it 'compares versions with different lengths' do
version = Version.new("3.2.2")
expect(version <=> '3.2.2.0').to eq 0
end
it 'comparing equal versions' do
version = Version.new("3.2.2")
expect(version <=> '3.2.2').to eq 0
end
it 'compares versions containing zero' do
version = Version.new("3.0.2")
expect(version <=> '3.0.2').to eq 0
version = Version.new("0.0.2")
expect(version <=> '0.0.2').to eq 0
end
end
end
describe '#components' do
context 'when padding > 0' do
version = Version.new("1.2.3.4")
it 'checks with positive argument' do
expect(version.components(6)).to match_array [1, 2, 3, 4, 0, 0]
end
it 'checks with argument = 0' do
expect(version.components(0)).to match_array [1, 2, 3, 4]
end
end
context 'when padding = 0' do
version = Version.new("1.2.3.4")
it 'checks with argument' do
expect(version.components(4)).to match_array [1, 2, 3, 4]
end
end
context 'when padding < 0' do
version = Version.new("1.2.3.4")
it 'checks without argument' do
expect(version.components).to match_array [1, 2, 3, 4]
end
it 'checks with argument < 0' do
expect(version.components(-2)).to match_array
[
3, 4
]
end
it 'checks with argument > 0' do
expect(version.components(2)).to match_array [1, 2]
end
end
context 'when version contains zero' do
it 'check with zeros in the end' do
version = Version.new("1.2.0.0")
expect(version.components).to match_array [1, 2]
end
it 'checks with zeros in the beginning' do
version = Version.new("0.0.1.2")
expect(version.components).to match_array [1, 2]
end
end
end
describe '#<' do
it 'checks if version1 < version2' do
version1 = Version.new("2.3")
version2 = Version.new("2.4")
expect(version1 < version2).to be true
version1 = Version.new("0.2.3")
version2 = Version.new("0.2.4")
expect(version1 < version2).to be true
version1 = Version.new("1.0.0")
version2 = Version.new("1")
expect(version1 < version2).to be false
end
end
describe '#>' do
it 'checks if version1 > version2' do
version1 = Version.new("2.4")
version2 = Version.new("2.3")
expect(version1 > version2).to be true
version1 = Version.new("0.2.4")
version2 = Version.new("0.2.3")
expect(version1 > version2).to be true
version1 = Version.new("1.0.0")
version2 = Version.new("1")
expect(version1 > version2).to be false
end
end
describe '#==' do
it 'checks if version1 == version2' do
version1 = Version.new("2.4")
version2 = Version.new("2.4")
expect(version1 == version2).to be true
version1 = Version.new("0.2.4")
version2 = Version.new("0.2.4")
expect(version1 == version2).to be true
version1 = Version.new("1.0.0")
version2 = Version.new("1")
expect(version1 == version2).to be false
version1 = Version.new("0.1")
version2 = Version.new("1")
expect(version1 == version2).to be false
end
end
describe '#<=' do
it 'checks if version1 <= version2' do
version1 = Version.new("2.3")
version2 = Version.new("2.4")
expect(version1 < version2).to be true
version1 = Version.new("0.2.3")
version2 = Version.new("0.2.4")
expect(version1 < version2).to be true
version1 = Version.new("1.0.0")
version2 = Version.new("1")
expect(version1 < version2).to be false
version1 = Version.new("0.2.4")
version2 = Version.new("0.2.4")
expect(version1 <= version2).to be true
version1 = Version.new("2.4")
version2 = Version.new("2.4")
expect(version1 <= version2).to be true
end
end
describe '#>=' do
it 'checks if version1 > version2' do
version1 = Version.new("2.4")
version2 = Version.new("2.3")
expect(version1 > version2).to be true
version1 = Version.new("0.2.4")
version2 = Version.new("0.2.3")
expect(version1 > version2).to be true
version1 = Version.new("1.0.0")
version2 = Version.new("1")
expect(version1 > version2).to be false
version1 = Version.new("0.2.4")
version2 = Version.new("0.2.4")
expect(version1 >= version2).to be true
version1 = Version.new("2.4")
version2 = Version.new("2.4")
expect(version1 >= version2).to be true
end
end
describe Range do
describe "#include?" do
it "checks simple versions" do
range = Version::Range.new(Version.new('1'), Version.new('2'))
version = Version.new('1.5')
expect((range.include? version)).to be true
version = Version.new('1')
expect((range.include? version)).to be true
version = Version.new('1.0')
expect((range.include? version)).to be true
range = Version::Range.new(Version.new('0'), Version.new('1'))
expect((range.include? Version.new('0.5'))).to be true
expect((range.include? Version.new('0.0.0.1'))).to be true
end
end
describe "#to_a" do
it "cheks with simple versions" do
range = Version::Range.new(Version.new('0.1'), Version.new('0.2'))
expect(range.to_a).to match_array [
'0.1', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5',
'0.1.6', '0.1.7', '0.1.8', '0.1.9'
]
# Това не знам дали е вярно - дали 0.1.0 трябва да е в тази област
expect(range.to_a).to match_array [
'0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5',
'0.1.6', '0.1.7', '0.1.8', '0.1.9'
]
range = Version::Range.new(Version.new('0.1'), Version.new('0.1'))
- expect(range.to_a).to match_array ['0.1']
+ expect(range.to_a).to match_array []
end
end
end
end

Лазар обнови решението на 16.11.2016 12:48 (преди над 1 година)

RSpec.describe Version do
describe '#<=>' do
context 'when first is bigger' do
it 'compares higher version with lower' do
- version = Version.new("3.2.2")
- expect(version <=> '1.2.3').to eq 1
- expect(version <=> '3.2.1').to eq 1
- expect(version <=> '3.1.3').to eq 1
+ expect(Version.new("3.2.2") <=> '1.2.3').to eq 1
+ expect(Version.new("3.2.2") <=> '3.2.1').to eq 1
+ expect(Version.new("3.2.2") <=> '3.1.3').to eq 1
end
it 'compares versions with different lengths' do
- version = Version.new("3.2.2")
- expect(version <=> '3.2').to eq 1
- expect(version <=> '2.5.9.9').to eq 1
- expect(version <=> '2').to eq 1
+ expect(Version.new("3.2.2") <=> '3.2').to eq 1
+ expect(Version.new("3.2.2") <=> '2.5.9.9').to eq 1
+ expect(Version.new("3.2.2") <=> '2').to eq 1
end
it 'compares versions containing zero' do
- version = Version.new("3.2.2")
- expect(version <=> '0.2.2').to eq 1
- expect(version <=> '3.0.2').to eq 1
- expect(version <=> '3.2.0').to eq 1
- version = Version.new("0.2.2")
- expect(version <=> '0.0.2').to eq 1
- expect(version <=> '0.1.5').to eq 1
+ expect(Version.new("3.2.2") <=> '0.2.2').to eq 1
+ expect(Version.new("3.2.2") <=> '3.0.2').to eq 1
+ expect(Version.new("3.2.2") <=> '3.2.0').to eq 1
+ expect(Version.new("0.2.2") <=> '0.0.2').to eq 1
+ expect(Version.new("0.2.2") <=> '0.1.5').to eq 1
end
end
context 'when first is lower' do
it 'compares lower version with higher' do
- version = Version.new("1.2.3")
- expect(version <=> '1.2.4').to eq -1
- expect(version <=> '1.3.2').to eq -1
- expect(version <=> '2.3.4').to eq -1
- expect(version <=> '2.1.1').to eq -1
+ expect(Version.new("1.2.3") <=> '1.2.4').to eq -1
+ expect(Version.new("1.2.3") <=> '1.3.2').to eq -1
+ expect(Version.new("1.2.3") <=> '2.3.4').to eq -1
+ expect(Version.new("1.2.3") <=> '2.1.1').to eq -1
end
it 'compares versions with different lengths' do
version = Version.new("2.3")
expect(version <=> '2.3.4').to eq -1
expect(version <=> '3.1.1').to eq -1
expect(version <=> '3').to eq -1
end
it 'compares versions containing zero' do
- version = Version.new("2.3.4")
- expect(version <=> '3.0.0').to eq -1
- expect(version <=> '2.4.0').to eq -1
- version = Version.new("0.3.4")
- expect(version <=> '1.0.0').to eq -1
- expect(version <=> '0.4.0').to eq -1
+ expect(Version.new("2.3.4") <=> '3.0.0').to eq -1
+ expect(Version.new("2.3.4") <=> '2.4.0').to eq -1
+ expect(Version.new("0.3.4") <=> '1.0.0').to eq -1
+ expect(Version.new("0.3.4") <=> '0.4.0').to eq -1
end
end
context 'when they are equal' do
it 'compares versions with different lengths' do
- version = Version.new("3.2.2")
- expect(version <=> '3.2.2.0').to eq 0
+ expect(Version.new("3.2.2") <=> '3.2.2.0').to eq 0
end
it 'comparing equal versions' do
- version = Version.new("3.2.2")
- expect(version <=> '3.2.2').to eq 0
+ expect(Version.new("3.2.2") <=> '3.2.2').to eq 0
end
it 'compares versions containing zero' do
- version = Version.new("3.0.2")
- expect(version <=> '3.0.2').to eq 0
- version = Version.new("0.0.2")
- expect(version <=> '0.0.2').to eq 0
+ expect(Version.new("3.0.2") <=> '3.0.2').to eq 0
+ expect(Version.new("0.0.2") <=> '0.0.2').to eq 0
end
end
end
describe '#components' do
context 'when padding > 0' do
version = Version.new("1.2.3.4")
it 'checks with positive argument' do
expect(version.components(6)).to match_array [1, 2, 3, 4, 0, 0]
end
it 'checks with argument = 0' do
expect(version.components(0)).to match_array [1, 2, 3, 4]
end
end
context 'when padding = 0' do
version = Version.new("1.2.3.4")
it 'checks with argument' do
expect(version.components(4)).to match_array [1, 2, 3, 4]
end
end
context 'when padding < 0' do
version = Version.new("1.2.3.4")
it 'checks without argument' do
expect(version.components).to match_array [1, 2, 3, 4]
end
it 'checks with argument < 0' do
expect(version.components(-2)).to match_array
[
3, 4
]
end
it 'checks with argument > 0' do
expect(version.components(2)).to match_array [1, 2]
end
end
context 'when version contains zero' do
it 'check with zeros in the end' do
version = Version.new("1.2.0.0")
expect(version.components).to match_array [1, 2]
end
it 'checks with zeros in the beginning' do
version = Version.new("0.0.1.2")
expect(version.components).to match_array [1, 2]
end
end
end
describe '#<' do
it 'checks if version1 < version2' do
- version1 = Version.new("2.3")
- version2 = Version.new("2.4")
- expect(version1 < version2).to be true
- version1 = Version.new("0.2.3")
- version2 = Version.new("0.2.4")
- expect(version1 < version2).to be true
- version1 = Version.new("1.0.0")
- version2 = Version.new("1")
- expect(version1 < version2).to be false
+ expect(Version.new("2.3") < Version.new("2.4")).to be true
+ expect(Version.new("0.2.3") < Version.new("0.2.4")).to be true
+ expect(Version.new("1.0.0") < Version.new("1")).to be false
end
end
describe '#>' do
it 'checks if version1 > version2' do
- version1 = Version.new("2.4")
- version2 = Version.new("2.3")
- expect(version1 > version2).to be true
- version1 = Version.new("0.2.4")
- version2 = Version.new("0.2.3")
- expect(version1 > version2).to be true
- version1 = Version.new("1.0.0")
- version2 = Version.new("1")
- expect(version1 > version2).to be false
+ expect(Version.new("2.4") > Version.new("2.3")).to be true
+ expect(Version.new("0.2.4") > Version.new("0.2.3")).to be true
+ expect(Version.new("1.0.0") > Version.new("1")).to be false
end
end
describe '#==' do
it 'checks if version1 == version2' do
- version1 = Version.new("2.4")
- version2 = Version.new("2.4")
- expect(version1 == version2).to be true
- version1 = Version.new("0.2.4")
- version2 = Version.new("0.2.4")
- expect(version1 == version2).to be true
- version1 = Version.new("1.0.0")
- version2 = Version.new("1")
- expect(version1 == version2).to be false
- version1 = Version.new("0.1")
- version2 = Version.new("1")
- expect(version1 == version2).to be false
+ expect(Version.new("1.0.0") == Version.new("1")).to be false
+ expect(Version.new("0.1") == Version.new("1")).to be false
end
end
describe '#<=' do
it 'checks if version1 <= version2' do
- version1 = Version.new("2.3")
- version2 = Version.new("2.4")
- expect(version1 < version2).to be true
- version1 = Version.new("0.2.3")
- version2 = Version.new("0.2.4")
- expect(version1 < version2).to be true
- version1 = Version.new("1.0.0")
- version2 = Version.new("1")
- expect(version1 < version2).to be false
- version1 = Version.new("0.2.4")
- version2 = Version.new("0.2.4")
- expect(version1 <= version2).to be true
- version1 = Version.new("2.4")
- version2 = Version.new("2.4")
- expect(version1 <= version2).to be true
+ expect(Version.new("2.3") < Version.new("2.4")).to be true
+ expect(Version.new("0.2.3") < Version.new("0.2.4")).to be true
+ expect(Version.new("1.0.0") < Version.new("1")).to be false
end
end
describe '#>=' do
it 'checks if version1 > version2' do
- version1 = Version.new("2.4")
- version2 = Version.new("2.3")
- expect(version1 > version2).to be true
- version1 = Version.new("0.2.4")
- version2 = Version.new("0.2.3")
- expect(version1 > version2).to be true
- version1 = Version.new("1.0.0")
- version2 = Version.new("1")
- expect(version1 > version2).to be false
- version1 = Version.new("0.2.4")
- version2 = Version.new("0.2.4")
- expect(version1 >= version2).to be true
- version1 = Version.new("2.4")
- version2 = Version.new("2.4")
- expect(version1 >= version2).to be true
+ expect(Version.new("2.4") > Version.new("2.3")).to be true
+ expect(Version.new("0.2.4") > Version.new("0.2.3")).to be true
+ expect(Version.new("1.0.0") > Version.new("1")).to be false
end
end
describe Range do
describe "#include?" do
it "checks simple versions" do
range = Version::Range.new(Version.new('1'), Version.new('2'))
- version = Version.new('1.5')
- expect((range.include? version)).to be true
- version = Version.new('1')
- expect((range.include? version)).to be true
- version = Version.new('1.0')
- expect((range.include? version)).to be true
+ expect((range.include? Version.new('1.5'))).to be true
+ expect((range.include? Version.new('1'))).to be true
+ expect((range.include? Version.new('1.0'))).to be true
range = Version::Range.new(Version.new('0'), Version.new('1'))
expect((range.include? Version.new('0.5'))).to be true
expect((range.include? Version.new('0.0.0.1'))).to be true
end
end
describe "#to_a" do
it "cheks with simple versions" do
range = Version::Range.new(Version.new('0.1'), Version.new('0.2'))
expect(range.to_a).to match_array [
'0.1', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5',
'0.1.6', '0.1.7', '0.1.8', '0.1.9'
]
# Това не знам дали е вярно - дали 0.1.0 трябва да е в тази област
expect(range.to_a).to match_array [
'0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5',
'0.1.6', '0.1.7', '0.1.8', '0.1.9'
]
range = Version::Range.new(Version.new('0.1'), Version.new('0.1'))
expect(range.to_a).to match_array []
end
end
end
end

Лазар обнови решението на 17.11.2016 09:31 (преди над 1 година)

RSpec.describe Version do
describe '#<=>' do
context 'when first is bigger' do
it 'compares higher version with lower' do
expect(Version.new("3.2.2") <=> '1.2.3').to eq 1
expect(Version.new("3.2.2") <=> '3.2.1').to eq 1
expect(Version.new("3.2.2") <=> '3.1.3').to eq 1
end
it 'compares versions with different lengths' do
expect(Version.new("3.2.2") <=> '3.2').to eq 1
expect(Version.new("3.2.2") <=> '2.5.9.9').to eq 1
expect(Version.new("3.2.2") <=> '2').to eq 1
end
it 'compares versions containing zero' do
expect(Version.new("3.2.2") <=> '0.2.2').to eq 1
expect(Version.new("3.2.2") <=> '3.0.2').to eq 1
expect(Version.new("3.2.2") <=> '3.2.0').to eq 1
expect(Version.new("0.2.2") <=> '0.0.2').to eq 1
expect(Version.new("0.2.2") <=> '0.1.5').to eq 1
end
end
context 'when first is lower' do
it 'compares lower version with higher' do
expect(Version.new("1.2.3") <=> '1.2.4').to eq -1
expect(Version.new("1.2.3") <=> '1.3.2').to eq -1
expect(Version.new("1.2.3") <=> '2.3.4').to eq -1
expect(Version.new("1.2.3") <=> '2.1.1').to eq -1
end
it 'compares versions with different lengths' do
version = Version.new("2.3")
expect(version <=> '2.3.4').to eq -1
expect(version <=> '3.1.1').to eq -1
expect(version <=> '3').to eq -1
end
it 'compares versions containing zero' do
expect(Version.new("2.3.4") <=> '3.0.0').to eq -1
expect(Version.new("2.3.4") <=> '2.4.0').to eq -1
expect(Version.new("0.3.4") <=> '1.0.0').to eq -1
expect(Version.new("0.3.4") <=> '0.4.0').to eq -1
end
end
context 'when they are equal' do
it 'compares versions with different lengths' do
expect(Version.new("3.2.2") <=> '3.2.2.0').to eq 0
end
it 'comparing equal versions' do
expect(Version.new("3.2.2") <=> '3.2.2').to eq 0
end
it 'compares versions containing zero' do
expect(Version.new("3.0.2") <=> '3.0.2').to eq 0
expect(Version.new("0.0.2") <=> '0.0.2').to eq 0
end
end
end
describe '#components' do
context 'when padding > 0' do
version = Version.new("1.2.3.4")
it 'checks with positive argument' do
expect(version.components(6)).to match_array [1, 2, 3, 4, 0, 0]
end
it 'checks with argument = 0' do
expect(version.components(0)).to match_array [1, 2, 3, 4]
end
end
context 'when padding = 0' do
version = Version.new("1.2.3.4")
it 'checks with argument' do
expect(version.components(4)).to match_array [1, 2, 3, 4]
end
end
context 'when padding < 0' do
version = Version.new("1.2.3.4")
it 'checks without argument' do
expect(version.components).to match_array [1, 2, 3, 4]
end
it 'checks with argument < 0' do
expect(version.components(-2)).to match_array
[
3, 4
]
end
it 'checks with argument > 0' do
expect(version.components(2)).to match_array [1, 2]
end
end
context 'when version contains zero' do
it 'check with zeros in the end' do
version = Version.new("1.2.0.0")
expect(version.components).to match_array [1, 2]
end
it 'checks with zeros in the beginning' do
version = Version.new("0.0.1.2")
expect(version.components).to match_array [1, 2]
end
end
end
+ describe '#to_s' do
+ it 'check with simple versions' do
+ expect(Version.new("2.3").to_s).to eq '2.3'
+ end
+ it 'check with more complex versions' do
+ expect(Version.new("2.0.3").to_s).to eq '2.0.3'
+ expect(Version.new("0.0.3").to_s).to eq '0.0.3'
+ end
+ end
describe '#<' do
it 'checks if version1 < version2' do
expect(Version.new("2.3") < Version.new("2.4")).to be true
expect(Version.new("0.2.3") < Version.new("0.2.4")).to be true
expect(Version.new("1.0.0") < Version.new("1")).to be false
end
end
describe '#>' do
it 'checks if version1 > version2' do
expect(Version.new("2.4") > Version.new("2.3")).to be true
expect(Version.new("0.2.4") > Version.new("0.2.3")).to be true
expect(Version.new("1.0.0") > Version.new("1")).to be false
end
end
describe '#==' do
it 'checks if version1 == version2' do
expect(Version.new("1.0.0") == Version.new("1")).to be false
expect(Version.new("0.1") == Version.new("1")).to be false
end
end
describe '#<=' do
it 'checks if version1 <= version2' do
expect(Version.new("2.3") < Version.new("2.4")).to be true
expect(Version.new("0.2.3") < Version.new("0.2.4")).to be true
expect(Version.new("1.0.0") < Version.new("1")).to be false
end
end
describe '#>=' do
it 'checks if version1 > version2' do
expect(Version.new("2.4") > Version.new("2.3")).to be true
expect(Version.new("0.2.4") > Version.new("0.2.3")).to be true
expect(Version.new("1.0.0") > Version.new("1")).to be false
end
end
describe Range do
describe "#include?" do
it "checks simple versions" do
range = Version::Range.new(Version.new('1'), Version.new('2'))
expect((range.include? Version.new('1.5'))).to be true
expect((range.include? Version.new('1'))).to be true
expect((range.include? Version.new('1.0'))).to be true
range = Version::Range.new(Version.new('0'), Version.new('1'))
expect((range.include? Version.new('0.5'))).to be true
expect((range.include? Version.new('0.0.0.1'))).to be true
end
end
describe "#to_a" do
it "cheks with simple versions" do
range = Version::Range.new(Version.new('0.1'), Version.new('0.2'))
expect(range.to_a).to match_array [
'0.1', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5',
'0.1.6', '0.1.7', '0.1.8', '0.1.9'
]
# Това не знам дали е вярно - дали 0.1.0 трябва да е в тази област
expect(range.to_a).to match_array [
'0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5',
'0.1.6', '0.1.7', '0.1.8', '0.1.9'
]
range = Version::Range.new(Version.new('0.1'), Version.new('0.1'))
expect(range.to_a).to match_array []
end
end
end
end