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

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

Към профила на Христо Христов

Резултати

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

Код

RSpec.describe 'Version' do
describe 'Input check' do
it 'accepts proper input' do
expect(Version.new('1.2.3')).to eq('1.2.3')
end
it 'accepts proper doubledigit input' do
expect(Version.new('1.25.3')).to eq('1.25.3')
end
it 'doesnt kill unnecessary 0s' do
expect(Version.new("1.0.1.0.1.0")).to eq("1.0.1.0.1")
end
it 'doesnt kill unnecessary 0s' do
expect(Version.new("1.0.1.0.1")).to eq("1.0.1.0.1")
end
it 'recognises an error' do
expect { Version.new('1..3') } .to raise_error(ArgumentError)
end
it 'tells you when you have tried a completely invalid input' do
expect { Version.new('1.1.a') } .to raise_error(ArgumentError)
expect { Version.new('a') } .to raise_error(ArgumentError)
expect { Version.new('1,1,1') } .to raise_error(ArgumentError)
end
it 'tells you when you have tried a negative number' do
expect { Version.new('-1.1.1') } .to raise_error(ArgumentError)
expect { Version.new('1.1.-0') } .to raise_error(ArgumentError)
end
it 'tells you when you try something funny' do
expect(Version.new('1') == Version.new('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'))
.to eq(true)
end
it 'tells you when you try something funny with 1 at the end' do
expect(Version.new('1') == Version.new('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1'))
.to eq(false)
end
end
describe 'Boolean checks' do
it 'knows the example test' do
expect(Version.new('1.2.3')).to be < Version.new('1.3.1')
end
it 'knows >' do
expect(Version.new("1.1.1")).to be > Version.new("1.1.0")
end
it 'knows ==' do
expect(Version.new("1.1.0")).to be == Version.new("1.1")
end
it 'knows <' do
expect(Version.new("1.1.0")).to be < Version.new("1.1.1")
end
it 'knows >=' do
expect(Version.new("1.1.1")).to be >= Version.new("1.1.0")
end
it 'knows >=' do
expect(Version.new("1.1.0")).to be >= Version.new("1.1")
end
it 'knows <=' do
expect(Version.new("1.1.0")).to be <= Version.new("1.1.1")
end
it 'knows <=' do
expect(Version.new("1.1")).to be <= Version.new("1.1.0")
end
# oy vey
it 'knows false >' do
expect(Version.new("1.1.0")).to_not be > Version.new("1.1.1")
end
it 'knows false >' do
expect(Version.new("1.1")).to_not be > Version.new("1.1.0")
end
it 'knows false ==' do
expect(Version.new("1.1.0")).to_not be == Version.new("1.1.1")
end
it 'knows false <' do
expect(Version.new("1.1.1")).to_not be < Version.new("1.1.0")
end
it 'knows false <' do
expect(Version.new("1.1")).to_not be < Version.new("1.1.0")
end
it 'knows false >=' do
expect(Version.new("1.1.0")).to_not be >= Version.new("1.1.1")
end
it 'knows false <=' do
expect(Version.new("1.1.1")).to_not be <= Version.new("1.1.0")
end
# oy gevalt
it 'knows >' do
expect(Version.new("1.2.1")).to be > Version.new("1.1.1")
end
it 'knows ==' do
expect(Version.new("1.2.0")).to be == Version.new("1.2")
end
it 'knows <' do
expect(Version.new("1.1.1")).to be < Version.new("1.2.1")
end
it 'knows <' do
expect(Version.new("1.1.1")).to be < Version.new("1.3")
end
it 'knows >=' do
expect(Version.new("1.2.1")).to be >= Version.new("1.1.1")
end
it 'knows >=' do
expect(Version.new("1.2")).to be >= Version.new("1.2.0")
end
it 'knows <=' do
expect(Version.new("1.1.1")).to be <= Version.new("1.2.1")
end
it 'knows <=' do
expect(Version.new("1.2")).to be <= Version.new("1.2.0")
end
# oy vey
it 'knows false >' do
expect(Version.new("1.1.1")).to_not be > Version.new("1.2.1")
end
it 'knows false >' do
expect(Version.new("1.2.0")).to_not be > Version.new("1.2")
end
it 'knows false ==' do
expect(Version.new("1.2.1")).to_not be == Version.new("1.2.2")
end
it 'knows false <' do
expect(Version.new("1.2.1")).to_not be < Version.new("1.1.1")
end
it 'knows false <' do
expect(Version.new("1.2.0")).to_not be < Version.new("1.2")
end
it 'knows false >=' do
expect(Version.new("1.1.1")).to_not be >= Version.new("1.2.1")
end
it 'knows false <=' do
expect(Version.new("1.2.1")).to_not be <= Version.new("1.1.1")
end
# the goyim know
it 'knows <=>' do
expect(Version.new("1.2.1") <=> Version.new("1.1.1")).to eq(1)
end
it 'knows <=>' do
expect(Version.new("1.2.0") <=> Version.new("1.2")).to eq(0)
end
it 'knows <=>' do
expect(Version.new("1.1.1") <=> Version.new("1.2.1")).to eq(-1)
end
# < > = should be ready
it 'knows 0.1 != 1' do
expect(Version.new("1") != Version.new("0.1")).to eq(true)
end
it 'knows 0/nothing is smaller than anything' do
expect(Version.new("0")).to be < Version.new("0.1")
expect(Version.new("")).to be < Version.new("0.1")
end
it 'knows 1.1.0 == 1.1' do
expect(Version.new("1.1.0") == Version.new("1.1")).to eq(true)
end
end
describe '#to_s' do
it 'returns regular array' do
expect(Version.new("1.2.3.4").to_s).to eq("1.2.3.4")
end
it 'returns array with a zero at end' do
expect(Version.new("1.2.3.0").to_s).to eq("1.2.3")
end
it 'returns an array with a 0 within' do
expect(Version.new("1.0.3.1").to_s).to eq("1.0.3.1")
end
it 'returns an array with a 0 in the beginning' do
expect(Version.new("0.0.3.1").to_s).to eq("0.0.3.1")
end
it 'returns an array with 10 in the ending' do
expect(Version.new("1.0.3.10").to_s).to eq("1.0.3.10")
end
end
describe '#components' do
it 'returns a regular array' do
expect(Version.new("1.2.3.4").components).to eq([1, 2, 3, 4])
end
it 'returns array with a zero at end' do
a = Version.new("1.2.3.0")
expect(a.components).to eq([1, 2, 3])
end
it 'returns an array with a 0 within' do
a = Version.new("1.0.3.1")
expect(a.components).to eq([1, 0, 3, 1])
end
it 'returns proper components(3)' do
a = Version.new("1.2.3.4")
expect(a.components(3)).to eq([1, 2, 3])
expect { a.components(3) } .to_not change { a }
end
it 'knows what to do with a larger N' do
a = Version.new("1.2.3")
expect(a.components(8)).to eq([1, 2, 3, 0, 0, 0, 0, 0])
expect { a.components(8) } .to_not change { a }
end
it 'knows what to do with a smaller N' do
a = Version.new("1.2.3.4.5.6")
expect(a.components(2)).to eq([1, 2])
expect { a.components(8) } .to_not change { a }
end
it 'knows what to do with cheesy stuff' do
a = Version.new("1.2.3.0")
expect(a.components(4)).to eq([1, 2, 3, 0])
expect { a.components(4) } .to_not change { a }
end
it 'knows what to do with cheesy stuff and a larger N' do
a = Version.new("1.2.3.0")
expect(a.components(8)).to eq([1, 2, 3, 0, 0, 0, 0, 0])
expect { a.components(8) } .to_not change { a }
end
it 'knows what to do with a smaller N and cheesy stuff' do
a = Version.new("1.0.3.4.5.6")
expect(a.components(2)).to eq([1, 0])
expect { a.components(8) } .to_not change { a }
end
end
describe 'Range' do
describe '#include?' do
it 'runs the example' do
expect(
(Version::Range.new(Version.new('1'), Version.new('2'))
.include? Version.new('1.5'))
).to eq(true)
end
it 'knows when there is an error' do
expect(
(Version::Range.new(Version.new('1'), Version.new('2'))
.include? Version.new('20'))
).to eq(false)
end
it 'knows 2 is not within (1;2)' do
expect(
(Version::Range.new(Version.new('1'), Version.new('2'))
.include? Version.new('2'))
).to eq(false)
end
it 'throws ArgumentError' do
expect { Version::Range.new('1', '5').include? 'a.2' }
.to raise_error(ArgumentError)
expect { Version::Range.new('a', '5').include? '1.2' }
.to raise_error(ArgumentError)
expect { Version::Range.new('1', 'b').include? '1.2' }
.to raise_error(ArgumentError)
end
it 'knows string ranges' do
expect(Version::Range.new('1', '5').include?('2.2')).to eq(true)
expect(
(Version::Range.new('1', '5')
.include? Version.new('2.2'))
).to eq(true)
expect(
(Version::Range.new(Version.new('1'), Version.new('5'))
.include? '2.2')
).to eq(true)
end
end
describe '#to_a' do
it 'can make example arrays' do
expect(
Version::Range.new(Version.new('1.1.0'), Version.new('1.2.2'))
.to_a
).to eq(
[
'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'
]
)
end
it 'can make small arrays' do
expect(
Version::Range.new(Version.new('1.1.0'), Version.new('1.1.1'))
.to_a
).to eq(['1.1.0'])
end
it 'knows what to do with a bad array' do
expect(
Version::Range.new(Version.new('1.1.1'), Version.new('1.1.1'))
.to_a
).to eq([])
end
it 'knows what to do with another bad array' do
expect(
Version::Range.new(Version.new('2.1.1'), Version.new('1.1.1'))
.to_a
).to eq([])
end
end
end
end

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

.F..F.....F.....F..

Failures:

  1) spec Version checks for ArgumentError with the correct message
     Failure/Error: expect(@solution).to_not pass_tests
       expected this solution to not pass the tests:
       
         class Version
           VALID_VERSION_REGEXP = /\A\z|\A[0-9]+(\.[0-9]+)*\z/
         
           include Comparable
         
           def initialize(version = '')
             unless VALID_VERSION_REGEXP.match(version.to_s)
               raise ArgumentError, "Invalid version string"
             end
           
             @components = version.to_s
               .split('.')
               .map(&:to_i)
               .reverse
               .drop_while(&:zero?)
               .reverse
           end
         
           def <=>(other)
             @components <=> Version.new(other).internal_components
           end
         
           def internal_components(positions = 0)
             padding_size = positions - @components.size
         
             if padding_size > 0
               @components + [0] * padding_size
             elsif positions != 0
               @components.take(positions)
             else
               @components.dup
             end
           end
         
           def components(positions = 0)
             padding_size = positions - @components.size
         
             if padding_size > 0
               @components + [0] * padding_size
             elsif positions != 0
               @components.take(positions)
             else
               @components.dup
             end
           end
         
           def to_s
             @components.join('.')
           end
         
           class Range
             include Enumerable
         
             def initialize(start_version, end_version)
               @start_version = Version.new(start_version)
               @end_version   = Version.new(end_version)
             end
         
             def include?(version)
               (@start_version <=> version) < 1 && (@end_version <=> version) == 1
             end
         
             def each
               current_version = @start_version
         
               while (current_version <=> @end_version) == -1
                 yield current_version
         
                 current_version = increment_version(current_version)
               end
             end
         
             private
         
             def increment_version(version)
               components = version.internal_components(3)
         
               components[2] += 1
         
               components.to_enum.with_index.reverse_each do |_, index|
                 component = components[index]
         
                 if component >= 10 && components[index - 1]
                   components[index]      = 0
                   components[index - 1] += 1
                 end
               end
         
               Version.new(components.join('.'))
             end
           end
         end
     # /tmp/d20161119-19072-161xioc/spec.rb:257:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) spec Version checks that initialize can be given 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-161xioc/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 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-161xioc/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)>'

  4) spec Version::Range tests include? with versions lower 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)
               @end_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-161xioc/spec.rb:522: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 20.06 seconds
19 examples, 4 failures

Failed examples:

rspec /tmp/d20161119-19072-161xioc/spec.rb:241 # spec Version checks for ArgumentError with the correct message
rspec /tmp/d20161119-19072-161xioc/spec.rb:298 # spec Version checks that initialize can be given no arguments
rspec /tmp/d20161119-19072-161xioc/spec.rb:441 # spec Version tests that #components cannot be used to modify the version
rspec /tmp/d20161119-19072-161xioc/spec.rb:515 # spec Version::Range tests include? with versions lower than the start one

История (5 версии и 19 коментара)

Христо обнови решението на 13.11.2016 17:01 (преди почти 2 години)

+RSpec.describe 'Version' do
+ it 'accepts proper input' do
+ expect(Version.new('1.2.3')).to eq('1.2.3')
+ end
+
+ it 'doesnt kill unnecessary 0s' do
+ expect(Version.new("1.0.1.0.1.0")).to eq("1.0.1.0.1")
+ end
+
+ it 'doesnt kill unnecessary 0s' do
+ expect(Version.new("1.0.1.0.1")).to eq("1.0.1.0.1")
+ end
+
+ it 'recognises an error' do
+ expect { Version.new('0..3') } .to raise_error(ArgumentError)
+ end
+
+ it 'tells you when you have tried a completely invalid input' do
+ expect { Version.new('1.1.a') } .to raise_error(ArgumentError)
+ end
+
+ it 'tells you when you have tried a completely invalid input' do
+ expect { Version.new('a') } .to raise_error(ArgumentError)
+ end
+
+ it 'tells you when you have tried a completely invalid input' do
+ expect { Version.new('1,1,1') } .to raise_error(ArgumentError)
+ end
+
+ it 'tells you when you have tried a negative number' do
+ expect { Version.new('-1.1.1') } .to raise_error(ArgumentError)
+ end
+
+ it 'tells you when you have tried a negative number' do
+ expect { Version.new('1.1.-0') } .to raise_error(ArgumentError)
+ end
+
+ it 'tells you when you try something funny' do
+ expect(Version.new('1') == Version.new('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'))
+ .to eq(true)
+ end
+
+ it 'tells you when you try something funny' do
+ expect(Version.new('1') == Version.new('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1'))
+ .to eq(false)
+ end
+
+ # input check ends here
+ it 'knows the example test' do
+ expect(Version.new('1.2.3') < Version.new('1.3.1')).to eq(true)
+ end
+
+ it 'knows >' do
+ expect(Version.new("1.1.1") > Version.new("1.1.0")).to eq(true)
+ end
+
+ it 'knows ==' do
+ expect(Version.new("1.1.0") == Version.new("1.1")).to eq(true)
+ end
+
+ it 'knows <' do
+ expect(Version.new("1.1.0") < Version.new("1.1.1")).to eq(true)
+ end
+
+ it 'knows >=' do
+ expect(Version.new("1.1.1") >= Version.new("1.1.0")).to eq(true)
+ end
+
+ it 'knows >=' do
+ expect(Version.new("1.1.0") >= Version.new("1.1")).to eq(true)
+ end
+
+ it 'knows <=' do
+ expect(Version.new("1.1.0") <= Version.new("1.1.1")).to eq(true)
+ end
+
+ it 'knows <=' do
+ expect(Version.new("1.1") <= Version.new("1.1.0")).to eq(true)
+ end
+
+ # oy vey
+
+ it 'knows false >' do
+ expect(Version.new("1.1.0") > Version.new("1.1.1")).to eq(false)
+ end
+
+ it 'knows false >' do
+ expect(Version.new("1.1") > Version.new("1.1.0")).to eq(false)
+ end
+
+ it 'knows false ==' do
+ expect(Version.new("1.1.0") == Version.new("1.1.1")).to eq(false)
+ end
+
+ it 'knows false <' do
+ expect(Version.new("1.1.1") < Version.new("1.1.0")).to eq(false)
+ end
+
+ it 'knows false <' do
+ expect(Version.new("1.1") < Version.new("1.1.0")).to eq(false)
+ end
+
+ it 'knows false >=' do
+ expect(Version.new("1.1.0") >= Version.new("1.1.1")).to eq(false)
+ end
+
+ it 'knows false <=' do
+ expect(Version.new("1.1.1") <= Version.new("1.1.0")).to eq(false)
+ end
+
+ # oy gevalt
+
+ it 'knows >' do
+ expect(Version.new("1.2.1") > Version.new("1.1.1")).to eq(true)
+ end
+
+ it 'knows ==' do
+ expect(Version.new("1.2.0") == Version.new("1.2")).to eq(true)
+ end
+
+ it 'knows <' do
+ expect(Version.new("1.1.1") < Version.new("1.2.1")).to eq(true)
+ end
+
+ it 'knows >=' do
+ expect(Version.new("1.2.1") >= Version.new("1.1.1")).to eq(true)
+ end
+
+ it 'knows >=' do
+ expect(Version.new("1.2") >= Version.new("1.2.0")).to eq(true)
+ end
+
+ it 'knows <=' do
+ expect(Version.new("1.1.1") <= Version.new("1.2.1")).to eq(true)
+ end
+
+ it 'knows <=' do
+ expect(Version.new("1.2") <= Version.new("1.2.0")).to eq(true)
+ end
+
+ # oy vey
+
+ it 'knows false >' do
+ expect(Version.new("1.1.1") > Version.new("1.2.1")).to eq(false)
+ end
+
+ it 'knows false >' do
+ expect(Version.new("1.2.0") > Version.new("1.2")).to eq(false)
+ end
+
+ it 'knows false ==' do
+ expect(Version.new("1.2.1") == Version.new("1.2.2")).to eq(false)
+ end
+
+ it 'knows false <' do
+ expect(Version.new("1.2.1") < Version.new("1.1.1")).to eq(false)
+ end
+
+ it 'knows false <' do
+ expect(Version.new("1.2.0") < Version.new("1.2")).to eq(false)
+ end
+
+ it 'knows false >=' do
+ expect(Version.new("1.1.1") >= Version.new("1.2.1")).to eq(false)
+ end
+
+ it 'knows false <=' do
+ expect(Version.new("1.2.1") <= Version.new("1.1.1")).to eq(false)
+ end
+
+ # the goyim know
+
+ it 'knows <=>' do
+ expect(Version.new("1.2.1") <=> Version.new("1.1.1")).to eq(1)
+ end
+
+ it 'knows <=>' do
+ expect(Version.new("1.2.0") <=> Version.new("1.2")).to eq(0)
+ end
+
+ it 'knows <=>' do
+ expect(Version.new("1.1.1") <=> Version.new("1.2.1")).to eq(-1)
+ end
+
+ # < > = should be ready
+
+ it 'knows 0.1 != 1' do
+ expect(Version.new("1") != Version.new("0.1")).to eq(true)
+ end
+
+ it 'knows 0/nothing is smaller than anything' do
+ expect(Version.new("") < Version.new("0.1")).to eq(true)
+ end
+
+ it 'knows 1.1.0 == 1.1' do
+ expect(Version.new("1.1.0") == Version.new("1.1")).to eq(true)
+ end
+ # to string
+
+ it 'returns regular array' do
+ expect(Version.new("1.2.3.4").to_s).to eq("1.2.3.4")
+ end
+
+ it 'returns array with a zero at end' do
+ expect(Version.new("1.2.3.0").to_s).to eq("1.2.3")
+ end
+
+ it 'returns an array with a 0 within' do
+ expect(Version.new("1.0.3.1").to_s).to eq("1.0.3.1")
+ end
+
+ it 'returns an array with a 0 in the beginning' do
+ expect(Version.new("0.0.3.1").to_s).to eq("0.0.3.1")
+ end
+
+ # components
+
+ it 'returns a regular array' do
+ expect(Version.new("1.2.3.4").components).to eq([1, 2, 3, 4])
+ end
+
+ it 'returns array with a zero at end' do
+ a = Version.new("1.2.3.0")
+ expect(a.components).to eq([1, 2, 3])
+ end
+
+ it 'returns an array with a 0 within' do
+ a = Version.new("1.0.3.1")
+ expect(a.components).to eq([1, 0, 3, 1])
+ end
+
+ it 'returns proper components(3)' do
+ a = Version.new("1.2.3.4")
+ expect(a.components(3)).to eq([1, 2, 3])
+ expect { a.components(3) } .to_not change { a }
+ end
+
+ it 'knows what to do with a larger N' do
+ a = Version.new("1.2.3")
+ expect(a.components(8)).to eq([1, 2, 3, 0, 0, 0, 0, 0])
+ expect { a.components(8) } .to_not change { a }
+ end
+
+ it 'knows what to do with cheesy stuff' do
+ a = Version.new("1.2.3.0")
+ expect(a.components(4)).to eq([1, 2, 3, 0])
+ expect { a.components(4) } .to_not change { a }
+ end
+
+ it 'knows what to do with cheesy stuff and a larger N' do
+ a = Version.new("1.2.3.0")
+ expect(a.components(8)).to eq([1, 2, 3, 0, 0, 0, 0, 0])
+ expect { a.components(8) } .to_not change { a }
+ end
+
+ describe 'Range' do
+ it 'runs the example' do
+ expect(
+ (Version::Range.new(Version.new('1'), Version.new('2'))
+ .include? Version.new('1.5'))
+ ).to eq(true)
+ end
+
+ it 'knows when there is an error' do
+ expect(
+ (Version::Range.new(Version.new('1'), Version.new('2'))
+ .include? Version.new('20'))
+ ).to eq(false)
+ end
+
+ it 'knows 2 is not within (1;2)' do
+ expect(
+ (Version::Range.new(Version.new('1'), Version.new('2'))
+ .include? Version.new('2'))
+ ).to eq(false)
+ end
+
+ it 'throws ArgumentError' do
+ expect { Version::Range.new('1', '5').include? 'a.2' }
+ .to raise_error(ArgumentError)
+ end
+
+ it 'throws ArgumentError 2' do
+ expect { Version::Range.new('a', '5').include? '1.2' }
+ .to raise_error(ArgumentError)
+ end
+
+ it 'throws ArgumentError 3' do
+ expect { Version::Range.new('1', 'b').include? '1.2' }
+ .to raise_error(ArgumentError)
+ end
+
+ it 'knows string ranges' do
+ expect((Version::Range.new('1', '5').include? '2.2')).to eq(true)
+ end
+
+ it 'knows string ranges 2' do
+ expect(
+ (Version::Range.new('1', '5')
+ .include? Version.new('2.2'))
+ ).to eq(true)
+ end
+
+ it 'knows string ranges 3' do
+ expect(
+ (Version::Range.new(Version.new('1'), Version.new('5'))
+ .include? '2.2')
+ ).to eq(true)
+ end
+
+ # include
+
+ it 'can make example arrays' do
+ expect(
+ Version::Range.new(Version.new('1.1.0'), Version.new('1.2.2'))
+ .to_a
+ ).to eq(
+ [
+ '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'
+ ]
+ )
+ end
+
+ it 'can make small arrays' do
+ expect(
+ Version::Range.new(Version.new('1.1.0'), Version.new('1.1.1'))
+ .to_a
+ ).to eq(['1.1.0'])
+ end
+
+ it 'knows what to do with a bad array' do
+ expect(
+ Version::Range.new(Version.new('1.1.1'), Version.new('1.1.1'))
+ .to_a
+ ).to eq([])
+ end
+
+ it 'knows what to do with another bad array' do
+ expect(
+ Version::Range.new(Version.new('2.1.1'), Version.new('1.1.1'))
+ .to_a
+ ).to eq([])
+ end
+ end
+end

Дължината не трябва да те притеснява. Можеш да обединиш няколко теста, ако проверяват една и съща логика. Например, всичките, които тестват <=, или дори всички, които тестват неравенства. Не е задължително да имаш само един expect в it, стига да не тестват различна логика. Аз бих обединил, например <, >, <= и >= в един или два it-а.

На какво ниво ще ги обединиш зависи от теб - въпрос на избор е.

Христо обнови решението на 17.11.2016 20:08 (преди почти 2 години)

RSpec.describe 'Version' do
it 'accepts proper input' do
expect(Version.new('1.2.3')).to eq('1.2.3')
end
+ it 'accepts proper doubledigit input' do
+ expect(Version.new('1.25.3')).to eq('1.25.3')
+ end
+
it 'doesnt kill unnecessary 0s' do
expect(Version.new("1.0.1.0.1.0")).to eq("1.0.1.0.1")
end
it 'doesnt kill unnecessary 0s' do
expect(Version.new("1.0.1.0.1")).to eq("1.0.1.0.1")
end
it 'recognises an error' do
- expect { Version.new('0..3') } .to raise_error(ArgumentError)
+ expect { Version.new('1..3') } .to raise_error(ArgumentError)
end
it 'tells you when you have tried a completely invalid input' do
expect { Version.new('1.1.a') } .to raise_error(ArgumentError)
end
it 'tells you when you have tried a completely invalid input' do
expect { Version.new('a') } .to raise_error(ArgumentError)
end
it 'tells you when you have tried a completely invalid input' do
expect { Version.new('1,1,1') } .to raise_error(ArgumentError)
end
it 'tells you when you have tried a negative number' do
expect { Version.new('-1.1.1') } .to raise_error(ArgumentError)
end
it 'tells you when you have tried a negative number' do
expect { Version.new('1.1.-0') } .to raise_error(ArgumentError)
end
it 'tells you when you try something funny' do
expect(Version.new('1') == Version.new('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'))
.to eq(true)
end
it 'tells you when you try something funny' do
expect(Version.new('1') == Version.new('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1'))
.to eq(false)
end
# input check ends here
it 'knows the example test' do
expect(Version.new('1.2.3') < Version.new('1.3.1')).to eq(true)
end
it 'knows >' do
expect(Version.new("1.1.1") > Version.new("1.1.0")).to eq(true)
end
it 'knows ==' do
expect(Version.new("1.1.0") == Version.new("1.1")).to eq(true)
end
it 'knows <' do
expect(Version.new("1.1.0") < Version.new("1.1.1")).to eq(true)
end
it 'knows >=' do
expect(Version.new("1.1.1") >= Version.new("1.1.0")).to eq(true)
end
it 'knows >=' do
expect(Version.new("1.1.0") >= Version.new("1.1")).to eq(true)
end
it 'knows <=' do
expect(Version.new("1.1.0") <= Version.new("1.1.1")).to eq(true)
end
it 'knows <=' do
expect(Version.new("1.1") <= Version.new("1.1.0")).to eq(true)
end
# oy vey
it 'knows false >' do
expect(Version.new("1.1.0") > Version.new("1.1.1")).to eq(false)
end
it 'knows false >' do
expect(Version.new("1.1") > Version.new("1.1.0")).to eq(false)
end
it 'knows false ==' do
expect(Version.new("1.1.0") == Version.new("1.1.1")).to eq(false)
end
it 'knows false <' do
expect(Version.new("1.1.1") < Version.new("1.1.0")).to eq(false)
end
it 'knows false <' do
expect(Version.new("1.1") < Version.new("1.1.0")).to eq(false)
end
it 'knows false >=' do
expect(Version.new("1.1.0") >= Version.new("1.1.1")).to eq(false)
end
it 'knows false <=' do
expect(Version.new("1.1.1") <= Version.new("1.1.0")).to eq(false)
end
# oy gevalt
it 'knows >' do
expect(Version.new("1.2.1") > Version.new("1.1.1")).to eq(true)
end
it 'knows ==' do
expect(Version.new("1.2.0") == Version.new("1.2")).to eq(true)
end
it 'knows <' do
expect(Version.new("1.1.1") < Version.new("1.2.1")).to eq(true)
end
+ it 'knows <' do
+ expect(Version.new("1.1.1") < Version.new("1.3")).to eq(true)
+ end
+
it 'knows >=' do
expect(Version.new("1.2.1") >= Version.new("1.1.1")).to eq(true)
end
it 'knows >=' do
expect(Version.new("1.2") >= Version.new("1.2.0")).to eq(true)
end
it 'knows <=' do
expect(Version.new("1.1.1") <= Version.new("1.2.1")).to eq(true)
end
it 'knows <=' do
expect(Version.new("1.2") <= Version.new("1.2.0")).to eq(true)
end
# oy vey
it 'knows false >' do
expect(Version.new("1.1.1") > Version.new("1.2.1")).to eq(false)
end
it 'knows false >' do
expect(Version.new("1.2.0") > Version.new("1.2")).to eq(false)
end
it 'knows false ==' do
expect(Version.new("1.2.1") == Version.new("1.2.2")).to eq(false)
end
it 'knows false <' do
expect(Version.new("1.2.1") < Version.new("1.1.1")).to eq(false)
end
it 'knows false <' do
expect(Version.new("1.2.0") < Version.new("1.2")).to eq(false)
end
it 'knows false >=' do
expect(Version.new("1.1.1") >= Version.new("1.2.1")).to eq(false)
end
it 'knows false <=' do
expect(Version.new("1.2.1") <= Version.new("1.1.1")).to eq(false)
end
# the goyim know
it 'knows <=>' do
expect(Version.new("1.2.1") <=> Version.new("1.1.1")).to eq(1)
end
it 'knows <=>' do
expect(Version.new("1.2.0") <=> Version.new("1.2")).to eq(0)
end
it 'knows <=>' do
expect(Version.new("1.1.1") <=> Version.new("1.2.1")).to eq(-1)
end
# < > = should be ready
it 'knows 0.1 != 1' do
expect(Version.new("1") != Version.new("0.1")).to eq(true)
end
it 'knows 0/nothing is smaller than anything' do
+ expect(Version.new("0") < Version.new("0.1")).to eq(true)
expect(Version.new("") < Version.new("0.1")).to eq(true)
end
it 'knows 1.1.0 == 1.1' do
expect(Version.new("1.1.0") == Version.new("1.1")).to eq(true)
end
+
+ #
# to string
+ #
it 'returns regular array' do
expect(Version.new("1.2.3.4").to_s).to eq("1.2.3.4")
end
it 'returns array with a zero at end' do
expect(Version.new("1.2.3.0").to_s).to eq("1.2.3")
end
it 'returns an array with a 0 within' do
expect(Version.new("1.0.3.1").to_s).to eq("1.0.3.1")
end
it 'returns an array with a 0 in the beginning' do
expect(Version.new("0.0.3.1").to_s).to eq("0.0.3.1")
end
+ it 'returns an array with 10 in the ending' do
+ expect(Version.new("1.0.3.10").to_s).to eq("1.0.3.10")
+ end
+
+ #
# components
+ #
it 'returns a regular array' do
expect(Version.new("1.2.3.4").components).to eq([1, 2, 3, 4])
end
it 'returns array with a zero at end' do
a = Version.new("1.2.3.0")
expect(a.components).to eq([1, 2, 3])
end
it 'returns an array with a 0 within' do
a = Version.new("1.0.3.1")
expect(a.components).to eq([1, 0, 3, 1])
end
it 'returns proper components(3)' do
a = Version.new("1.2.3.4")
expect(a.components(3)).to eq([1, 2, 3])
expect { a.components(3) } .to_not change { a }
end
it 'knows what to do with a larger N' do
a = Version.new("1.2.3")
expect(a.components(8)).to eq([1, 2, 3, 0, 0, 0, 0, 0])
expect { a.components(8) } .to_not change { a }
end
it 'knows what to do with cheesy stuff' do
a = Version.new("1.2.3.0")
expect(a.components(4)).to eq([1, 2, 3, 0])
expect { a.components(4) } .to_not change { a }
end
it 'knows what to do with cheesy stuff and a larger N' do
a = Version.new("1.2.3.0")
expect(a.components(8)).to eq([1, 2, 3, 0, 0, 0, 0, 0])
expect { a.components(8) } .to_not change { a }
end
describe 'Range' do
it 'runs the example' do
expect(
(Version::Range.new(Version.new('1'), Version.new('2'))
.include? Version.new('1.5'))
).to eq(true)
end
it 'knows when there is an error' do
expect(
(Version::Range.new(Version.new('1'), Version.new('2'))
.include? Version.new('20'))
).to eq(false)
end
it 'knows 2 is not within (1;2)' do
expect(
(Version::Range.new(Version.new('1'), Version.new('2'))
.include? Version.new('2'))
).to eq(false)
end
it 'throws ArgumentError' do
expect { Version::Range.new('1', '5').include? 'a.2' }
.to raise_error(ArgumentError)
end
it 'throws ArgumentError 2' do
expect { Version::Range.new('a', '5').include? '1.2' }
.to raise_error(ArgumentError)
end
it 'throws ArgumentError 3' do
expect { Version::Range.new('1', 'b').include? '1.2' }
.to raise_error(ArgumentError)
end
it 'knows string ranges' do
expect((Version::Range.new('1', '5').include? '2.2')).to eq(true)
end
it 'knows string ranges 2' do
expect(
(Version::Range.new('1', '5')
.include? Version.new('2.2'))
).to eq(true)
end
it 'knows string ranges 3' do
expect(
(Version::Range.new(Version.new('1'), Version.new('5'))
.include? '2.2')
).to eq(true)
end
# include
it 'can make example arrays' do
expect(
Version::Range.new(Version.new('1.1.0'), Version.new('1.2.2'))
.to_a
).to eq(
[
'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'
]
)
end
it 'can make small arrays' do
expect(
Version::Range.new(Version.new('1.1.0'), Version.new('1.1.1'))
.to_a
).to eq(['1.1.0'])
end
it 'knows what to do with a bad array' do
expect(
Version::Range.new(Version.new('1.1.1'), Version.new('1.1.1'))
.to_a
).to eq([])
end
it 'knows what to do with another bad array' do
expect(
Version::Range.new(Version.new('2.1.1'), Version.new('1.1.1'))
.to_a
).to eq([])
end
end
end

a = Version.new("1.2.3") a.components(0)

В условието е споменато да се върнат първите N елемента в този случай. Това означава ли, че трябва да се върне празен масив или нещо друго( имплементацията ви връща [1,2,3], което според мен не отговаря на условието )?

Христо обнови решението на 17.11.2016 21:47 (преди почти 2 години)

RSpec.describe 'Version' do
- it 'accepts proper input' do
- expect(Version.new('1.2.3')).to eq('1.2.3')
- end
-
- it 'accepts proper doubledigit input' do
- expect(Version.new('1.25.3')).to eq('1.25.3')
- end
-
- it 'doesnt kill unnecessary 0s' do
- expect(Version.new("1.0.1.0.1.0")).to eq("1.0.1.0.1")
- end
-
- it 'doesnt kill unnecessary 0s' do
- expect(Version.new("1.0.1.0.1")).to eq("1.0.1.0.1")
- end
-
- it 'recognises an error' do
- expect { Version.new('1..3') } .to raise_error(ArgumentError)
- end
-
- it 'tells you when you have tried a completely invalid input' do
- expect { Version.new('1.1.a') } .to raise_error(ArgumentError)
- end
+ describe 'Input check' do
+ it 'accepts proper input' do
+ expect(Version.new('1.2.3')).to eq('1.2.3')
+ end
- it 'tells you when you have tried a completely invalid input' do
- expect { Version.new('a') } .to raise_error(ArgumentError)
+ it 'accepts proper doubledigit input' do
+ expect(Version.new('1.25.3')).to eq('1.25.3')
+ end
+
+ it 'doesnt kill unnecessary 0s' do
+ expect(Version.new("1.0.1.0.1.0")).to eq("1.0.1.0.1")
+ end
+
+ it 'doesnt kill unnecessary 0s' do
+ expect(Version.new("1.0.1.0.1")).to eq("1.0.1.0.1")
+ end
+
+ it 'recognises an error' do
+ expect { Version.new('1..3') } .to raise_error(ArgumentError)
+ end
+
+ it 'tells you when you have tried a completely invalid input' do
+ expect { Version.new('1.1.a') } .to raise_error(ArgumentError)
+ end
+
+ it 'tells you when you have tried a completely invalid input' do
+ expect { Version.new('a') } .to raise_error(ArgumentError)
+ end
+
+ it 'tells you when you have tried a completely invalid input' do
+ expect { Version.new('1,1,1') } .to raise_error(ArgumentError)
+ end
+
+ it 'tells you when you have tried a negative number' do
+ expect { Version.new('-1.1.1') } .to raise_error(ArgumentError)
+ end
+
+ it 'tells you when you have tried a negative number' do
+ expect { Version.new('1.1.-0') } .to raise_error(ArgumentError)
+ end
+
+ it 'tells you when you try something funny' do
+ expect(Version.new('1') == Version.new('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'))
+ .to eq(true)
+ end
+
+ it 'tells you when you try something funny' do
+ expect(Version.new('1') == Version.new('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1'))
+ .to eq(false)
+ end
end
- it 'tells you when you have tried a completely invalid input' do
- expect { Version.new('1,1,1') } .to raise_error(ArgumentError)
- end
-
- it 'tells you when you have tried a negative number' do
- expect { Version.new('-1.1.1') } .to raise_error(ArgumentError)
- end
-
- it 'tells you when you have tried a negative number' do
- expect { Version.new('1.1.-0') } .to raise_error(ArgumentError)
- end
-
- it 'tells you when you try something funny' do
- expect(Version.new('1') == Version.new('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'))
- .to eq(true)
- end
-
- it 'tells you when you try something funny' do
- expect(Version.new('1') == Version.new('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1'))
- .to eq(false)
- end
-
# input check ends here
- it 'knows the example test' do
- expect(Version.new('1.2.3') < Version.new('1.3.1')).to eq(true)
- end
- it 'knows >' do
- expect(Version.new("1.1.1") > Version.new("1.1.0")).to eq(true)
- end
+ describe 'Boolean checks' do
+ it 'knows the example test' do
+ expect(Version.new('1.2.3') < Version.new('1.3.1')).to eq(true)
+ end
- it 'knows ==' do
- expect(Version.new("1.1.0") == Version.new("1.1")).to eq(true)
- end
-
- it 'knows <' do
- expect(Version.new("1.1.0") < Version.new("1.1.1")).to eq(true)
- end
-
- it 'knows >=' do
- expect(Version.new("1.1.1") >= Version.new("1.1.0")).to eq(true)
- end
+ it 'knows >' do
+ expect(Version.new("1.1.1") > Version.new("1.1.0")).to eq(true)
+ end
+
+ it 'knows ==' do
+ expect(Version.new("1.1.0") == Version.new("1.1")).to eq(true)
+ end
- it 'knows >=' do
- expect(Version.new("1.1.0") >= Version.new("1.1")).to eq(true)
- end
-
- it 'knows <=' do
- expect(Version.new("1.1.0") <= Version.new("1.1.1")).to eq(true)
- end
-
- it 'knows <=' do
- expect(Version.new("1.1") <= Version.new("1.1.0")).to eq(true)
- end
-
- # oy vey
-
- it 'knows false >' do
- expect(Version.new("1.1.0") > Version.new("1.1.1")).to eq(false)
- end
-
- it 'knows false >' do
- expect(Version.new("1.1") > Version.new("1.1.0")).to eq(false)
- end
+ it 'knows <' do
+ expect(Version.new("1.1.0") < Version.new("1.1.1")).to eq(true)
+ end
- it 'knows false ==' do
- expect(Version.new("1.1.0") == Version.new("1.1.1")).to eq(false)
- end
-
- it 'knows false <' do
- expect(Version.new("1.1.1") < Version.new("1.1.0")).to eq(false)
- end
-
- it 'knows false <' do
- expect(Version.new("1.1") < Version.new("1.1.0")).to eq(false)
- end
-
- it 'knows false >=' do
- expect(Version.new("1.1.0") >= Version.new("1.1.1")).to eq(false)
- end
-
- it 'knows false <=' do
- expect(Version.new("1.1.1") <= Version.new("1.1.0")).to eq(false)
- end
-
- # oy gevalt
+ it 'knows >=' do
+ expect(Version.new("1.1.1") >= Version.new("1.1.0")).to eq(true)
+ end
+
+ it 'knows >=' do
+ expect(Version.new("1.1.0") >= Version.new("1.1")).to eq(true)
+ end
- it 'knows >' do
- expect(Version.new("1.2.1") > Version.new("1.1.1")).to eq(true)
- end
+ it 'knows <=' do
+ expect(Version.new("1.1.0") <= Version.new("1.1.1")).to eq(true)
+ end
- it 'knows ==' do
- expect(Version.new("1.2.0") == Version.new("1.2")).to eq(true)
- end
-
- it 'knows <' do
- expect(Version.new("1.1.1") < Version.new("1.2.1")).to eq(true)
- end
-
- it 'knows <' do
- expect(Version.new("1.1.1") < Version.new("1.3")).to eq(true)
- end
-
- it 'knows >=' do
- expect(Version.new("1.2.1") >= Version.new("1.1.1")).to eq(true)
- end
+ it 'knows <=' do
+ expect(Version.new("1.1") <= Version.new("1.1.0")).to eq(true)
+ end
- it 'knows >=' do
- expect(Version.new("1.2") >= Version.new("1.2.0")).to eq(true)
- end
-
- it 'knows <=' do
- expect(Version.new("1.1.1") <= Version.new("1.2.1")).to eq(true)
- end
-
- it 'knows <=' do
- expect(Version.new("1.2") <= Version.new("1.2.0")).to eq(true)
- end
-
- # oy vey
-
- it 'knows false >' do
- expect(Version.new("1.1.1") > Version.new("1.2.1")).to eq(false)
- end
-
- it 'knows false >' do
- expect(Version.new("1.2.0") > Version.new("1.2")).to eq(false)
- end
+ # oy vey
- it 'knows false ==' do
- expect(Version.new("1.2.1") == Version.new("1.2.2")).to eq(false)
- end
-
- it 'knows false <' do
- expect(Version.new("1.2.1") < Version.new("1.1.1")).to eq(false)
- end
-
- it 'knows false <' do
- expect(Version.new("1.2.0") < Version.new("1.2")).to eq(false)
- end
-
- it 'knows false >=' do
- expect(Version.new("1.1.1") >= Version.new("1.2.1")).to eq(false)
- end
-
- it 'knows false <=' do
- expect(Version.new("1.2.1") <= Version.new("1.1.1")).to eq(false)
- end
-
- # the goyim know
-
- it 'knows <=>' do
- expect(Version.new("1.2.1") <=> Version.new("1.1.1")).to eq(1)
- end
+ it 'knows false >' do
+ expect(Version.new("1.1.0") > Version.new("1.1.1")).to eq(false)
+ end
- it 'knows <=>' do
- expect(Version.new("1.2.0") <=> Version.new("1.2")).to eq(0)
- end
-
- it 'knows <=>' do
- expect(Version.new("1.1.1") <=> Version.new("1.2.1")).to eq(-1)
- end
+ it 'knows false >' do
+ expect(Version.new("1.1") > Version.new("1.1.0")).to eq(false)
+ end
+
+ it 'knows false ==' do
+ expect(Version.new("1.1.0") == Version.new("1.1.1")).to eq(false)
+ end
- # < > = should be ready
-
- it 'knows 0.1 != 1' do
- expect(Version.new("1") != Version.new("0.1")).to eq(true)
- end
+ it 'knows false <' do
+ expect(Version.new("1.1.1") < Version.new("1.1.0")).to eq(false)
+ end
- it 'knows 0/nothing is smaller than anything' do
- expect(Version.new("0") < Version.new("0.1")).to eq(true)
- expect(Version.new("") < Version.new("0.1")).to eq(true)
- end
-
- it 'knows 1.1.0 == 1.1' do
- expect(Version.new("1.1.0") == Version.new("1.1")).to eq(true)
- end
-
- #
- # to string
- #
-
- it 'returns regular array' do
- expect(Version.new("1.2.3.4").to_s).to eq("1.2.3.4")
- end
+ it 'knows false <' do
+ expect(Version.new("1.1") < Version.new("1.1.0")).to eq(false)
+ end
- it 'returns array with a zero at end' do
- expect(Version.new("1.2.3.0").to_s).to eq("1.2.3")
- end
-
- it 'returns an array with a 0 within' do
- expect(Version.new("1.0.3.1").to_s).to eq("1.0.3.1")
- end
-
- it 'returns an array with a 0 in the beginning' do
- expect(Version.new("0.0.3.1").to_s).to eq("0.0.3.1")
- end
-
- it 'returns an array with 10 in the ending' do
- expect(Version.new("1.0.3.10").to_s).to eq("1.0.3.10")
- end
+ it 'knows false >=' do
+ expect(Version.new("1.1.0") >= Version.new("1.1.1")).to eq(false)
+ end
- #
- # components
- #
-
- it 'returns a regular array' do
- expect(Version.new("1.2.3.4").components).to eq([1, 2, 3, 4])
- end
-
- it 'returns array with a zero at end' do
- a = Version.new("1.2.3.0")
- expect(a.components).to eq([1, 2, 3])
- end
-
- it 'returns an array with a 0 within' do
- a = Version.new("1.0.3.1")
- expect(a.components).to eq([1, 0, 3, 1])
- end
-
- it 'returns proper components(3)' do
- a = Version.new("1.2.3.4")
- expect(a.components(3)).to eq([1, 2, 3])
- expect { a.components(3) } .to_not change { a }
- end
-
- it 'knows what to do with a larger N' do
- a = Version.new("1.2.3")
- expect(a.components(8)).to eq([1, 2, 3, 0, 0, 0, 0, 0])
- expect { a.components(8) } .to_not change { a }
- end
-
- it 'knows what to do with cheesy stuff' do
- a = Version.new("1.2.3.0")
- expect(a.components(4)).to eq([1, 2, 3, 0])
- expect { a.components(4) } .to_not change { a }
- end
+ it 'knows false <=' do
+ expect(Version.new("1.1.1") <= Version.new("1.1.0")).to eq(false)
+ end
- it 'knows what to do with cheesy stuff and a larger N' do
- a = Version.new("1.2.3.0")
- expect(a.components(8)).to eq([1, 2, 3, 0, 0, 0, 0, 0])
- expect { a.components(8) } .to_not change { a }
- end
+ # oy gevalt
+
+ it 'knows >' do
+ expect(Version.new("1.2.1") > Version.new("1.1.1")).to eq(true)
+ end
+
+ it 'knows ==' do
+ expect(Version.new("1.2.0") == Version.new("1.2")).to eq(true)
+ end
- describe 'Range' do
- it 'runs the example' do
- expect(
- (Version::Range.new(Version.new('1'), Version.new('2'))
- .include? Version.new('1.5'))
- ).to eq(true)
+ it 'knows <' do
+ expect(Version.new("1.1.1") < Version.new("1.2.1")).to eq(true)
end
- it 'knows when there is an error' do
- expect(
- (Version::Range.new(Version.new('1'), Version.new('2'))
- .include? Version.new('20'))
- ).to eq(false)
+ it 'knows <' do
+ expect(Version.new("1.1.1") < Version.new("1.3")).to eq(true)
end
+
+ it 'knows >=' do
+ expect(Version.new("1.2.1") >= Version.new("1.1.1")).to eq(true)
+ end
- it 'knows 2 is not within (1;2)' do
- expect(
- (Version::Range.new(Version.new('1'), Version.new('2'))
- .include? Version.new('2'))
- ).to eq(false)
+ it 'knows >=' do
+ expect(Version.new("1.2") >= Version.new("1.2.0")).to eq(true)
end
+
+ it 'knows <=' do
+ expect(Version.new("1.1.1") <= Version.new("1.2.1")).to eq(true)
+ end
+
+ it 'knows <=' do
+ expect(Version.new("1.2") <= Version.new("1.2.0")).to eq(true)
+ end
+
+ # oy vey
+
+ it 'knows false >' do
+ expect(Version.new("1.1.1") > Version.new("1.2.1")).to eq(false)
+ end
+
+ it 'knows false >' do
+ expect(Version.new("1.2.0") > Version.new("1.2")).to eq(false)
+ end
- it 'throws ArgumentError' do
- expect { Version::Range.new('1', '5').include? 'a.2' }
- .to raise_error(ArgumentError)
+ it 'knows false ==' do
+ expect(Version.new("1.2.1") == Version.new("1.2.2")).to eq(false)
end
+
+ it 'knows false <' do
+ expect(Version.new("1.2.1") < Version.new("1.1.1")).to eq(false)
+ end
+
+ it 'knows false <' do
+ expect(Version.new("1.2.0") < Version.new("1.2")).to eq(false)
+ end
+
+ it 'knows false >=' do
+ expect(Version.new("1.1.1") >= Version.new("1.2.1")).to eq(false)
+ end
+
+ it 'knows false <=' do
+ expect(Version.new("1.2.1") <= Version.new("1.1.1")).to eq(false)
+ end
+
+ # the goyim know
+
+ it 'knows <=>' do
+ expect(Version.new("1.2.1") <=> Version.new("1.1.1")).to eq(1)
+ end
- it 'throws ArgumentError 2' do
- expect { Version::Range.new('a', '5').include? '1.2' }
- .to raise_error(ArgumentError)
+ it 'knows <=>' do
+ expect(Version.new("1.2.0") <=> Version.new("1.2")).to eq(0)
end
-
- it 'throws ArgumentError 3' do
- expect { Version::Range.new('1', 'b').include? '1.2' }
- .to raise_error(ArgumentError)
+
+ it 'knows <=>' do
+ expect(Version.new("1.1.1") <=> Version.new("1.2.1")).to eq(-1)
end
+ # < > = should be ready
- it 'knows string ranges' do
- expect((Version::Range.new('1', '5').include? '2.2')).to eq(true)
+ it 'knows 0.1 != 1' do
+ expect(Version.new("1") != Version.new("0.1")).to eq(true)
end
+
+ it 'knows 0/nothing is smaller than anything' do
+ expect(Version.new("0") < Version.new("0.1")).to eq(true)
+ expect(Version.new("") < Version.new("0.1")).to eq(true)
+ end
- it 'knows string ranges 2' do
- expect(
- (Version::Range.new('1', '5')
- .include? Version.new('2.2'))
- ).to eq(true)
+ it 'knows 1.1.0 == 1.1' do
+ expect(Version.new("1.1.0") == Version.new("1.1")).to eq(true)
end
+ end
+ #
+ # to string
+ #
+ describe '#to_s' do
+ it 'returns regular array' do
+ expect(Version.new("1.2.3.4").to_s).to eq("1.2.3.4")
+ end
- it 'knows string ranges 3' do
- expect(
- (Version::Range.new(Version.new('1'), Version.new('5'))
- .include? '2.2')
- ).to eq(true)
+ it 'returns array with a zero at end' do
+ expect(Version.new("1.2.3.0").to_s).to eq("1.2.3")
end
+
+ it 'returns an array with a 0 within' do
+ expect(Version.new("1.0.3.1").to_s).to eq("1.0.3.1")
+ end
+
+ it 'returns an array with a 0 in the beginning' do
+ expect(Version.new("0.0.3.1").to_s).to eq("0.0.3.1")
+ end
+
+ it 'returns an array with 10 in the ending' do
+ expect(Version.new("1.0.3.10").to_s).to eq("1.0.3.10")
+ end
+ end
+ #
+ # components
+ #
+ describe '#components' do
+ it 'returns a regular array' do
+ expect(Version.new("1.2.3.4").components).to eq([1, 2, 3, 4])
+ end
+
+ it 'returns array with a zero at end' do
+ a = Version.new("1.2.3.0")
+ expect(a.components).to eq([1, 2, 3])
+ end
+
+ it 'returns an array with a 0 within' do
+ a = Version.new("1.0.3.1")
+ expect(a.components).to eq([1, 0, 3, 1])
+ end
+
+ it 'returns proper components(3)' do
+ a = Version.new("1.2.3.4")
+ expect(a.components(3)).to eq([1, 2, 3])
+ expect { a.components(3) } .to_not change { a }
+ end
+
+ it 'knows what to do with a larger N' do
+ a = Version.new("1.2.3")
+ expect(a.components(8)).to eq([1, 2, 3, 0, 0, 0, 0, 0])
+ expect { a.components(8) } .to_not change { a }
+ end
+
+ it 'knows what to do with cheesy stuff' do
+ a = Version.new("1.2.3.0")
+ expect(a.components(4)).to eq([1, 2, 3, 0])
+ expect { a.components(4) } .to_not change { a }
+ end
- # include
-
- it 'can make example arrays' do
- expect(
- Version::Range.new(Version.new('1.1.0'), Version.new('1.2.2'))
- .to_a
- ).to eq(
- [
- '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'
- ]
- )
+ it 'knows what to do with cheesy stuff and a larger N' do
+ a = Version.new("1.2.3.0")
+ expect(a.components(8)).to eq([1, 2, 3, 0, 0, 0, 0, 0])
+ expect { a.components(8) } .to_not change { a }
end
+ end
- it 'can make small arrays' do
- expect(
- Version::Range.new(Version.new('1.1.0'), Version.new('1.1.1'))
- .to_a
- ).to eq(['1.1.0'])
+ describe 'Range' do
+ describe '#include?' do
+ it 'runs the example' do
+ expect(
+ (Version::Range.new(Version.new('1'), Version.new('2'))
+ .include? Version.new('1.5'))
+ ).to eq(true)
+ end
+
+ it 'knows when there is an error' do
+ expect(
+ (Version::Range.new(Version.new('1'), Version.new('2'))
+ .include? Version.new('20'))
+ ).to eq(false)
+ end
+
+ it 'knows 2 is not within (1;2)' do
+ expect(
+ (Version::Range.new(Version.new('1'), Version.new('2'))
+ .include? Version.new('2'))
+ ).to eq(false)
+ end
+
+ it 'throws ArgumentError' do
+ expect { Version::Range.new('1', '5').include? 'a.2' }
+ .to raise_error(ArgumentError)
+ end
+
+ it 'throws ArgumentError 2' do
+ expect { Version::Range.new('a', '5').include? '1.2' }
+ .to raise_error(ArgumentError)
+ end
+
+ it 'throws ArgumentError 3' do
+ expect { Version::Range.new('1', 'b').include? '1.2' }
+ .to raise_error(ArgumentError)
+ end
+
+ it 'knows string ranges' do
+ expect((Version::Range.new('1', '5').include? '2.2')).to eq(true)
+ end
+
+ it 'knows string ranges 2' do
+ expect(
+ (Version::Range.new('1', '5')
+ .include? Version.new('2.2'))
+ ).to eq(true)
+ end
+
+ it 'knows string ranges 3' do
+ expect(
+ (Version::Range.new(Version.new('1'), Version.new('5'))
+ .include? '2.2')
+ ).to eq(true)
+ end
end
+ # include
- it 'knows what to do with a bad array' do
- expect(
- Version::Range.new(Version.new('1.1.1'), Version.new('1.1.1'))
+ describe '#to_a' do
+ it 'can make example arrays' do
+ expect(
+ Version::Range.new(Version.new('1.1.0'), Version.new('1.2.2'))
.to_a
- ).to eq([])
- end
-
- it 'knows what to do with another bad array' do
- expect(
- Version::Range.new(Version.new('2.1.1'), Version.new('1.1.1'))
- .to_a
- ).to eq([])
+ ).to eq(
+ [
+ '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'
+ ]
+ )
+ end
+
+ it 'can make small arrays' do
+ expect(
+ Version::Range.new(Version.new('1.1.0'), Version.new('1.1.1'))
+ .to_a
+ ).to eq(['1.1.0'])
+ end
+
+ it 'knows what to do with a bad array' do
+ expect(
+ Version::Range.new(Version.new('1.1.1'), Version.new('1.1.1'))
+ .to_a
+ ).to eq([])
+ end
+
+ it 'knows what to do with another bad array' do
+ expect(
+ Version::Range.new(Version.new('2.1.1'), Version.new('1.1.1'))
+ .to_a
+ ).to eq([])
+ end
end
end
end

Христо обнови решението на 17.11.2016 23:33 (преди почти 2 години)

RSpec.describe 'Version' do
describe 'Input check' do
it 'accepts proper input' do
expect(Version.new('1.2.3')).to eq('1.2.3')
end
it 'accepts proper doubledigit input' do
expect(Version.new('1.25.3')).to eq('1.25.3')
end
it 'doesnt kill unnecessary 0s' do
expect(Version.new("1.0.1.0.1.0")).to eq("1.0.1.0.1")
end
it 'doesnt kill unnecessary 0s' do
expect(Version.new("1.0.1.0.1")).to eq("1.0.1.0.1")
end
it 'recognises an error' do
expect { Version.new('1..3') } .to raise_error(ArgumentError)
end
it 'tells you when you have tried a completely invalid input' do
expect { Version.new('1.1.a') } .to raise_error(ArgumentError)
- end
-
- it 'tells you when you have tried a completely invalid input' do
expect { Version.new('a') } .to raise_error(ArgumentError)
- end
-
- it 'tells you when you have tried a completely invalid input' do
expect { Version.new('1,1,1') } .to raise_error(ArgumentError)
end
it 'tells you when you have tried a negative number' do
expect { Version.new('-1.1.1') } .to raise_error(ArgumentError)
- end
-
- it 'tells you when you have tried a negative number' do
expect { Version.new('1.1.-0') } .to raise_error(ArgumentError)
end
it 'tells you when you try something funny' do
expect(Version.new('1') == Version.new('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'))
.to eq(true)
end
- it 'tells you when you try something funny' do
+ it 'tells you when you try something funny with 1 at the end' do
expect(Version.new('1') == Version.new('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1'))
.to eq(false)
end
end
- # input check ends here
-
describe 'Boolean checks' do
it 'knows the example test' do
- expect(Version.new('1.2.3') < Version.new('1.3.1')).to eq(true)
+ expect(Version.new('1.2.3')).to be < Version.new('1.3.1')
end
it 'knows >' do
- expect(Version.new("1.1.1") > Version.new("1.1.0")).to eq(true)
+ expect(Version.new("1.1.1")).to be > Version.new("1.1.0")
end
it 'knows ==' do
- expect(Version.new("1.1.0") == Version.new("1.1")).to eq(true)
+ expect(Version.new("1.1.0")).to be == Version.new("1.1")
end
it 'knows <' do
- expect(Version.new("1.1.0") < Version.new("1.1.1")).to eq(true)
+ expect(Version.new("1.1.0")).to be < Version.new("1.1.1")
end
it 'knows >=' do
- expect(Version.new("1.1.1") >= Version.new("1.1.0")).to eq(true)
+ expect(Version.new("1.1.1")).to be >= Version.new("1.1.0")
end
it 'knows >=' do
- expect(Version.new("1.1.0") >= Version.new("1.1")).to eq(true)
+ expect(Version.new("1.1.0")).to be >= Version.new("1.1")
end
it 'knows <=' do
- expect(Version.new("1.1.0") <= Version.new("1.1.1")).to eq(true)
+ expect(Version.new("1.1.0")).to be <= Version.new("1.1.1")
end
it 'knows <=' do
- expect(Version.new("1.1") <= Version.new("1.1.0")).to eq(true)
+ expect(Version.new("1.1")).to be <= Version.new("1.1.0")
end
# oy vey
it 'knows false >' do
- expect(Version.new("1.1.0") > Version.new("1.1.1")).to eq(false)
+ expect(Version.new("1.1.0")).to_not be > Version.new("1.1.1")
end
it 'knows false >' do
- expect(Version.new("1.1") > Version.new("1.1.0")).to eq(false)
+ expect(Version.new("1.1")).to_not be > Version.new("1.1.0")
end
it 'knows false ==' do
- expect(Version.new("1.1.0") == Version.new("1.1.1")).to eq(false)
+ expect(Version.new("1.1.0")).to_not be == Version.new("1.1.1")
end
it 'knows false <' do
- expect(Version.new("1.1.1") < Version.new("1.1.0")).to eq(false)
+ expect(Version.new("1.1.1")).to_not be < Version.new("1.1.0")
end
it 'knows false <' do
- expect(Version.new("1.1") < Version.new("1.1.0")).to eq(false)
+ expect(Version.new("1.1")).to_not be < Version.new("1.1.0")
end
it 'knows false >=' do
- expect(Version.new("1.1.0") >= Version.new("1.1.1")).to eq(false)
+ expect(Version.new("1.1.0")).to_not be >= Version.new("1.1.1")
end
it 'knows false <=' do
- expect(Version.new("1.1.1") <= Version.new("1.1.0")).to eq(false)
+ expect(Version.new("1.1.1")).to_not be <= Version.new("1.1.0")
end
# oy gevalt
it 'knows >' do
- expect(Version.new("1.2.1") > Version.new("1.1.1")).to eq(true)
+ expect(Version.new("1.2.1")).to be > Version.new("1.1.1")
end
it 'knows ==' do
- expect(Version.new("1.2.0") == Version.new("1.2")).to eq(true)
+ expect(Version.new("1.2.0")).to be == Version.new("1.2")
end
it 'knows <' do
- expect(Version.new("1.1.1") < Version.new("1.2.1")).to eq(true)
+ expect(Version.new("1.1.1")).to be < Version.new("1.2.1")
end
it 'knows <' do
- expect(Version.new("1.1.1") < Version.new("1.3")).to eq(true)
+ expect(Version.new("1.1.1")).to be < Version.new("1.3")
end
it 'knows >=' do
- expect(Version.new("1.2.1") >= Version.new("1.1.1")).to eq(true)
+ expect(Version.new("1.2.1")).to be >= Version.new("1.1.1")
end
it 'knows >=' do
- expect(Version.new("1.2") >= Version.new("1.2.0")).to eq(true)
+ expect(Version.new("1.2")).to be >= Version.new("1.2.0")
end
it 'knows <=' do
- expect(Version.new("1.1.1") <= Version.new("1.2.1")).to eq(true)
+ expect(Version.new("1.1.1")).to be <= Version.new("1.2.1")
end
it 'knows <=' do
- expect(Version.new("1.2") <= Version.new("1.2.0")).to eq(true)
+ expect(Version.new("1.2")).to be <= Version.new("1.2.0")
end
# oy vey
it 'knows false >' do
- expect(Version.new("1.1.1") > Version.new("1.2.1")).to eq(false)
+ expect(Version.new("1.1.1")).to_not be > Version.new("1.2.1")
end
it 'knows false >' do
- expect(Version.new("1.2.0") > Version.new("1.2")).to eq(false)
+ expect(Version.new("1.2.0")).to_not be > Version.new("1.2")
end
it 'knows false ==' do
- expect(Version.new("1.2.1") == Version.new("1.2.2")).to eq(false)
+ expect(Version.new("1.2.1")).to_not be == Version.new("1.2.2")
end
it 'knows false <' do
- expect(Version.new("1.2.1") < Version.new("1.1.1")).to eq(false)
+ expect(Version.new("1.2.1")).to_not be < Version.new("1.1.1")
end
it 'knows false <' do
- expect(Version.new("1.2.0") < Version.new("1.2")).to eq(false)
+ expect(Version.new("1.2.0")).to_not be < Version.new("1.2")
end
it 'knows false >=' do
- expect(Version.new("1.1.1") >= Version.new("1.2.1")).to eq(false)
+ expect(Version.new("1.1.1")).to_not be >= Version.new("1.2.1")
end
it 'knows false <=' do
- expect(Version.new("1.2.1") <= Version.new("1.1.1")).to eq(false)
+ expect(Version.new("1.2.1")).to_not be <= Version.new("1.1.1")
end
# the goyim know
it 'knows <=>' do
expect(Version.new("1.2.1") <=> Version.new("1.1.1")).to eq(1)
end
it 'knows <=>' do
expect(Version.new("1.2.0") <=> Version.new("1.2")).to eq(0)
end
it 'knows <=>' do
expect(Version.new("1.1.1") <=> Version.new("1.2.1")).to eq(-1)
end
# < > = should be ready
it 'knows 0.1 != 1' do
expect(Version.new("1") != Version.new("0.1")).to eq(true)
end
it 'knows 0/nothing is smaller than anything' do
- expect(Version.new("0") < Version.new("0.1")).to eq(true)
- expect(Version.new("") < Version.new("0.1")).to eq(true)
+ expect(Version.new("0")).to be < Version.new("0.1")
+ expect(Version.new("")).to be < Version.new("0.1")
end
it 'knows 1.1.0 == 1.1' do
expect(Version.new("1.1.0") == Version.new("1.1")).to eq(true)
end
end
- #
- # to string
- #
+
describe '#to_s' do
it 'returns regular array' do
expect(Version.new("1.2.3.4").to_s).to eq("1.2.3.4")
end
it 'returns array with a zero at end' do
expect(Version.new("1.2.3.0").to_s).to eq("1.2.3")
end
it 'returns an array with a 0 within' do
expect(Version.new("1.0.3.1").to_s).to eq("1.0.3.1")
end
it 'returns an array with a 0 in the beginning' do
expect(Version.new("0.0.3.1").to_s).to eq("0.0.3.1")
end
it 'returns an array with 10 in the ending' do
expect(Version.new("1.0.3.10").to_s).to eq("1.0.3.10")
end
end
- #
- # components
- #
+
describe '#components' do
it 'returns a regular array' do
expect(Version.new("1.2.3.4").components).to eq([1, 2, 3, 4])
end
it 'returns array with a zero at end' do
a = Version.new("1.2.3.0")
expect(a.components).to eq([1, 2, 3])
end
it 'returns an array with a 0 within' do
a = Version.new("1.0.3.1")
expect(a.components).to eq([1, 0, 3, 1])
end
it 'returns proper components(3)' do
a = Version.new("1.2.3.4")
expect(a.components(3)).to eq([1, 2, 3])
expect { a.components(3) } .to_not change { a }
end
it 'knows what to do with a larger N' do
a = Version.new("1.2.3")
expect(a.components(8)).to eq([1, 2, 3, 0, 0, 0, 0, 0])
expect { a.components(8) } .to_not change { a }
end
+
+ it 'knows what to do with a smaller N' do
+ a = Version.new("1.2.3.4.5.6")
+ expect(a.components(2)).to eq([1, 2])
+ expect { a.components(8) } .to_not change { a }
+ end
it 'knows what to do with cheesy stuff' do
a = Version.new("1.2.3.0")
expect(a.components(4)).to eq([1, 2, 3, 0])
expect { a.components(4) } .to_not change { a }
end
it 'knows what to do with cheesy stuff and a larger N' do
a = Version.new("1.2.3.0")
expect(a.components(8)).to eq([1, 2, 3, 0, 0, 0, 0, 0])
expect { a.components(8) } .to_not change { a }
end
+
+ it 'knows what to do with a smaller N and cheesy stuff' do
+ a = Version.new("1.0.3.4.5.6")
+ expect(a.components(2)).to eq([1, 0])
+ expect { a.components(8) } .to_not change { a }
+ end
end
describe 'Range' do
describe '#include?' do
it 'runs the example' do
expect(
(Version::Range.new(Version.new('1'), Version.new('2'))
.include? Version.new('1.5'))
).to eq(true)
end
it 'knows when there is an error' do
expect(
(Version::Range.new(Version.new('1'), Version.new('2'))
.include? Version.new('20'))
).to eq(false)
end
it 'knows 2 is not within (1;2)' do
expect(
(Version::Range.new(Version.new('1'), Version.new('2'))
.include? Version.new('2'))
).to eq(false)
end
it 'throws ArgumentError' do
expect { Version::Range.new('1', '5').include? 'a.2' }
.to raise_error(ArgumentError)
- end
-
- it 'throws ArgumentError 2' do
expect { Version::Range.new('a', '5').include? '1.2' }
.to raise_error(ArgumentError)
- end
-
- it 'throws ArgumentError 3' do
expect { Version::Range.new('1', 'b').include? '1.2' }
.to raise_error(ArgumentError)
end
it 'knows string ranges' do
expect((Version::Range.new('1', '5').include? '2.2')).to eq(true)
- end
-
- it 'knows string ranges 2' do
+
expect(
(Version::Range.new('1', '5')
.include? Version.new('2.2'))
).to eq(true)
- end
-
- it 'knows string ranges 3' do
+
expect(
(Version::Range.new(Version.new('1'), Version.new('5'))
.include? '2.2')
).to eq(true)
end
end
- # include
describe '#to_a' do
it 'can make example arrays' do
expect(
Version::Range.new(Version.new('1.1.0'), Version.new('1.2.2'))
.to_a
).to eq(
[
'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'
]
)
end
it 'can make small arrays' do
expect(
Version::Range.new(Version.new('1.1.0'), Version.new('1.1.1'))
.to_a
).to eq(['1.1.0'])
end
it 'knows what to do with a bad array' do
expect(
Version::Range.new(Version.new('1.1.1'), Version.new('1.1.1'))
.to_a
).to eq([])
end
it 'knows what to do with another bad array' do
expect(
Version::Range.new(Version.new('2.1.1'), Version.new('1.1.1'))
.to_a
).to eq([])
end
end
end
end

Христо обнови решението на 18.11.2016 17:15 (преди почти 2 години)

RSpec.describe 'Version' do
describe 'Input check' do
it 'accepts proper input' do
expect(Version.new('1.2.3')).to eq('1.2.3')
end
it 'accepts proper doubledigit input' do
expect(Version.new('1.25.3')).to eq('1.25.3')
end
it 'doesnt kill unnecessary 0s' do
expect(Version.new("1.0.1.0.1.0")).to eq("1.0.1.0.1")
end
it 'doesnt kill unnecessary 0s' do
expect(Version.new("1.0.1.0.1")).to eq("1.0.1.0.1")
end
it 'recognises an error' do
expect { Version.new('1..3') } .to raise_error(ArgumentError)
end
it 'tells you when you have tried a completely invalid input' do
expect { Version.new('1.1.a') } .to raise_error(ArgumentError)
expect { Version.new('a') } .to raise_error(ArgumentError)
expect { Version.new('1,1,1') } .to raise_error(ArgumentError)
end
it 'tells you when you have tried a negative number' do
expect { Version.new('-1.1.1') } .to raise_error(ArgumentError)
expect { Version.new('1.1.-0') } .to raise_error(ArgumentError)
end
it 'tells you when you try something funny' do
expect(Version.new('1') == Version.new('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0'))
.to eq(true)
end
it 'tells you when you try something funny with 1 at the end' do
expect(Version.new('1') == Version.new('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1'))
.to eq(false)
end
end
describe 'Boolean checks' do
it 'knows the example test' do
expect(Version.new('1.2.3')).to be < Version.new('1.3.1')
end
it 'knows >' do
expect(Version.new("1.1.1")).to be > Version.new("1.1.0")
end
it 'knows ==' do
expect(Version.new("1.1.0")).to be == Version.new("1.1")
end
it 'knows <' do
expect(Version.new("1.1.0")).to be < Version.new("1.1.1")
end
it 'knows >=' do
expect(Version.new("1.1.1")).to be >= Version.new("1.1.0")
end
it 'knows >=' do
expect(Version.new("1.1.0")).to be >= Version.new("1.1")
end
it 'knows <=' do
expect(Version.new("1.1.0")).to be <= Version.new("1.1.1")
end
it 'knows <=' do
expect(Version.new("1.1")).to be <= Version.new("1.1.0")
end
# oy vey
it 'knows false >' do
expect(Version.new("1.1.0")).to_not be > Version.new("1.1.1")
end
it 'knows false >' do
expect(Version.new("1.1")).to_not be > Version.new("1.1.0")
end
it 'knows false ==' do
expect(Version.new("1.1.0")).to_not be == Version.new("1.1.1")
end
it 'knows false <' do
expect(Version.new("1.1.1")).to_not be < Version.new("1.1.0")
end
it 'knows false <' do
expect(Version.new("1.1")).to_not be < Version.new("1.1.0")
end
it 'knows false >=' do
expect(Version.new("1.1.0")).to_not be >= Version.new("1.1.1")
end
it 'knows false <=' do
expect(Version.new("1.1.1")).to_not be <= Version.new("1.1.0")
end
# oy gevalt
it 'knows >' do
expect(Version.new("1.2.1")).to be > Version.new("1.1.1")
end
it 'knows ==' do
expect(Version.new("1.2.0")).to be == Version.new("1.2")
end
it 'knows <' do
expect(Version.new("1.1.1")).to be < Version.new("1.2.1")
end
it 'knows <' do
expect(Version.new("1.1.1")).to be < Version.new("1.3")
end
it 'knows >=' do
expect(Version.new("1.2.1")).to be >= Version.new("1.1.1")
end
it 'knows >=' do
expect(Version.new("1.2")).to be >= Version.new("1.2.0")
end
it 'knows <=' do
expect(Version.new("1.1.1")).to be <= Version.new("1.2.1")
end
it 'knows <=' do
expect(Version.new("1.2")).to be <= Version.new("1.2.0")
end
# oy vey
it 'knows false >' do
expect(Version.new("1.1.1")).to_not be > Version.new("1.2.1")
end
it 'knows false >' do
expect(Version.new("1.2.0")).to_not be > Version.new("1.2")
end
it 'knows false ==' do
expect(Version.new("1.2.1")).to_not be == Version.new("1.2.2")
end
it 'knows false <' do
expect(Version.new("1.2.1")).to_not be < Version.new("1.1.1")
end
it 'knows false <' do
expect(Version.new("1.2.0")).to_not be < Version.new("1.2")
end
it 'knows false >=' do
expect(Version.new("1.1.1")).to_not be >= Version.new("1.2.1")
end
it 'knows false <=' do
expect(Version.new("1.2.1")).to_not be <= Version.new("1.1.1")
end
# the goyim know
it 'knows <=>' do
expect(Version.new("1.2.1") <=> Version.new("1.1.1")).to eq(1)
end
it 'knows <=>' do
expect(Version.new("1.2.0") <=> Version.new("1.2")).to eq(0)
end
it 'knows <=>' do
expect(Version.new("1.1.1") <=> Version.new("1.2.1")).to eq(-1)
end
# < > = should be ready
it 'knows 0.1 != 1' do
expect(Version.new("1") != Version.new("0.1")).to eq(true)
end
it 'knows 0/nothing is smaller than anything' do
expect(Version.new("0")).to be < Version.new("0.1")
expect(Version.new("")).to be < Version.new("0.1")
end
it 'knows 1.1.0 == 1.1' do
expect(Version.new("1.1.0") == Version.new("1.1")).to eq(true)
end
end
describe '#to_s' do
it 'returns regular array' do
expect(Version.new("1.2.3.4").to_s).to eq("1.2.3.4")
end
it 'returns array with a zero at end' do
expect(Version.new("1.2.3.0").to_s).to eq("1.2.3")
end
it 'returns an array with a 0 within' do
expect(Version.new("1.0.3.1").to_s).to eq("1.0.3.1")
end
it 'returns an array with a 0 in the beginning' do
expect(Version.new("0.0.3.1").to_s).to eq("0.0.3.1")
end
it 'returns an array with 10 in the ending' do
expect(Version.new("1.0.3.10").to_s).to eq("1.0.3.10")
end
end
describe '#components' do
it 'returns a regular array' do
expect(Version.new("1.2.3.4").components).to eq([1, 2, 3, 4])
end
it 'returns array with a zero at end' do
a = Version.new("1.2.3.0")
expect(a.components).to eq([1, 2, 3])
end
it 'returns an array with a 0 within' do
a = Version.new("1.0.3.1")
expect(a.components).to eq([1, 0, 3, 1])
end
it 'returns proper components(3)' do
a = Version.new("1.2.3.4")
expect(a.components(3)).to eq([1, 2, 3])
expect { a.components(3) } .to_not change { a }
end
it 'knows what to do with a larger N' do
a = Version.new("1.2.3")
expect(a.components(8)).to eq([1, 2, 3, 0, 0, 0, 0, 0])
expect { a.components(8) } .to_not change { a }
end
it 'knows what to do with a smaller N' do
a = Version.new("1.2.3.4.5.6")
expect(a.components(2)).to eq([1, 2])
expect { a.components(8) } .to_not change { a }
end
it 'knows what to do with cheesy stuff' do
a = Version.new("1.2.3.0")
expect(a.components(4)).to eq([1, 2, 3, 0])
expect { a.components(4) } .to_not change { a }
end
it 'knows what to do with cheesy stuff and a larger N' do
a = Version.new("1.2.3.0")
expect(a.components(8)).to eq([1, 2, 3, 0, 0, 0, 0, 0])
expect { a.components(8) } .to_not change { a }
end
it 'knows what to do with a smaller N and cheesy stuff' do
a = Version.new("1.0.3.4.5.6")
expect(a.components(2)).to eq([1, 0])
expect { a.components(8) } .to_not change { a }
end
end
describe 'Range' do
describe '#include?' do
it 'runs the example' do
expect(
(Version::Range.new(Version.new('1'), Version.new('2'))
.include? Version.new('1.5'))
).to eq(true)
end
it 'knows when there is an error' do
expect(
(Version::Range.new(Version.new('1'), Version.new('2'))
.include? Version.new('20'))
).to eq(false)
end
it 'knows 2 is not within (1;2)' do
expect(
(Version::Range.new(Version.new('1'), Version.new('2'))
.include? Version.new('2'))
).to eq(false)
end
it 'throws ArgumentError' do
expect { Version::Range.new('1', '5').include? 'a.2' }
.to raise_error(ArgumentError)
expect { Version::Range.new('a', '5').include? '1.2' }
.to raise_error(ArgumentError)
expect { Version::Range.new('1', 'b').include? '1.2' }
.to raise_error(ArgumentError)
end
it 'knows string ranges' do
- expect((Version::Range.new('1', '5').include? '2.2')).to eq(true)
+ expect(Version::Range.new('1', '5').include?('2.2')).to eq(true)
expect(
(Version::Range.new('1', '5')
.include? Version.new('2.2'))
).to eq(true)
expect(
(Version::Range.new(Version.new('1'), Version.new('5'))
.include? '2.2')
).to eq(true)
end
end
describe '#to_a' do
it 'can make example arrays' do
expect(
Version::Range.new(Version.new('1.1.0'), Version.new('1.2.2'))
.to_a
).to eq(
[
'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'
]
)
end
it 'can make small arrays' do
expect(
Version::Range.new(Version.new('1.1.0'), Version.new('1.1.1'))
.to_a
).to eq(['1.1.0'])
end
it 'knows what to do with a bad array' do
expect(
Version::Range.new(Version.new('1.1.1'), Version.new('1.1.1'))
.to_a
).to eq([])
end
it 'knows what to do with another bad array' do
expect(
Version::Range.new(Version.new('2.1.1'), Version.new('1.1.1'))
.to_a
).to eq([])
end
end
end
end