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

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

Към профила на Здравко Петров

Резултати

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

Код

RSpec.describe 'Version' do
describe "parameter_empty_string" do
it "empty_string" do
version = Version.new('')
expect(version).to eq(0)
end
it "zero_string" do
version = Version.new('0')
expect(version).to eq(0)
end
it "no_parameter_no_brackets" do
version = Version.new
expect(version).to eq(0)
end
end
describe "correct_params" do
it "version_object_nested" do
var = Version.new(Version.new(Version.new('1.2').to_s + '.9'))
expect(var).to eq('1.2.9')
end
it "variable_parameter" do
var = '1.3.5'
expect(Version.new(var)).to eq('1.3.5')
end
it "string_parameter" do
expect(Version.new('1.1.1')).to eq('1.1.1')
end
it "last_zero_parameter" do
expect(Version.new('1.1.0')).to eq('1.1.0')
end
it "zero_start_parameter" do
expect(Version.new('0.0.1')).to eq('0.0.1')
end
it "instance_parameter" do
version = Version.new('1.1.1')
expect(Version.new(version)).to eq('1.1.1')
end
it "negative_number_in_string_parameter" do
expect { Version.new('-1.1.1') }.to raise_error(ArgumentError)
end
it "negative_number_parameter" do
expect { Version.new(-1.1) }.to raise_error(ArgumentError)
end
end
describe "components_corectness" do
it "zero_component" do
expect(Version.new.components(0)).to eq([])
end
it "one_component" do
expect(Version.new.components(1)).to eq([0])
end
it "one_component_zero" do
expect(Version.new(0).components(1)).to eq([0])
end
it "zero_component_string" do
expect(Version.new('').components(1)).to eq([0])
end
it "more_component" do
expect(Version.new('1.3.5').components(3)).to eq([1, 3, 5])
end
it "param_more_components" do
expect(Version.new('1.3.5').components(5)).to eq([1, 3, 5, 0, 0])
end
it "wrong_component_parameter" do
error = NoMethodError
expect { Version.new('1.3.5').components("s") }.to raise_error(error)
end
it "mutabillity" do
version = Version.new('1.3.5').components(2)
version.to_s.upcase!
expect(version).to eq([1, 3])
end
end
describe "incorrect_parameter" do
it "argument_error_array" do
expect { Version.new(['1.2.3']) }.to raise_error(ArgumentError)
end
it "argument_error_range_number" do
expect { Version.new(0..3) }.to raise_error(ArgumentError)
end
it "argument_error_range_letter" do
expect { Version.new('a'..'z') }.to raise_error(ArgumentError)
end
it "argument_error_point_start" do
expect { Version.new('.3.3') }.to raise_error(ArgumentError)
end
it "argument_error_point_end" do
expect { Version.new('3.3.') }. to raise_error(ArgumentError)
end
it "argument_error_string" do
expect { Version.new('random_string') }.to raise_error(ArgumentError)
end
it "argument_error_dot" do
expect { Version.new('1.3.5.') }.to raise_error(ArgumentError)
end
end
describe "compare_two_versions" do
it "first_less_than_second" do
expect(Version.new('1.3.5')).to be < Version.new('1.3.6')
expect(Version.new('1.0.0')).to be < Version.new('1.0.0.1')
end
it "first_equal_second" do
expect(Version.new('1.3.5')).to be == Version.new('1.3.5')
expect(Version.new('1.0.0')).to be == Version.new(1)
end
it "first_bigger_than_second" do
expect(Version.new('1.3.5')).to be > Version.new('1.3.4')
expect(Version.new('1.0.0.0.1')).to be > Version.new('1.0.0')
end
it "first_not_less_second" do
expect(Version.new('1.1.1') < Version.new('1.1.0')).to eq(false)
expect(Version.new(''))
end
it "first_less_or_equal_second" do
expect(Version.new('1.3.5')).to be <= Version.new('1.3.5')
end
it "first_bigger_or_equal_second" do
expect(Version.new('1.3.5')).to be >= Version.new('1.3.5')
end
it "smaller_bigger_equal" do
expect(Version.new('1.1.0') <=> Version.new('1.1')).to eq(0)
end
it "shorter_longer" do
expect(Version.new('1.1')).to be < Version.new('1.1.0.1')
end
end
describe "to_string" do
it "no_parameter" do
expect(Version.new.to_s).to eq('')
end
it "zero_as_parameter" do
expect(Version.new(0).to_s).to eq('')
end
it "correct_input" do
expect(Version.new('1.3.5.6').to_s).to eq('1.3.5.6')
end
it "incorrect_input" do
expect { Version.new('1.3.4.').to_s }.to raise_error(ArgumentError)
end
it "last_zero" do
expect(Version.new('1.1.0').to_s).to eq('1.1')
end
it "zero_start" do
expect(Version.new('0.0.1').to_s).to eq('0.0.1')
end
end
describe "range_test_include" do
it "include_version" do
res = Version::Range.new('0.0.0.1', '0.0.0.2').include?('0.0.0.1.5')
expect(res).to eq(true)
end
it "include_fail" do
r = Version::Range.new(Version.new('1.5.0'), '1.0.1').include?('1.4.1')
expect(r).to eq(false)
end
it "include_nested" do
first = Version.new
second = Version.new(first.to_s + '0.9.2')
res = Version::Range.new(second, '1.0.0').include?('0.9.5')
expect(res).to eq(true)
end
it "include_from_x_to_x" do
res = Version::Range.new('1.3.5', '1.3.5').include?('1.3.5')
expect(res).to eq(false)
end
it "include_equal_to_start_version" do
res = Version::Range.new('1.0.1', '1.1.1').include?('1.0.1')
expect(res).to eq(true)
end
end
describe "range_test_to_a" do
it "correct_one" do
res = Version::Range.new('1.0.1', '1.0.2').to_a
expect(res).to eq(['1.0.1'])
end
it "empty_array" do
res = Version::Range.new('1.3.5', '1.3.5').to_a
expect(res).to eq([])
end
it "outrange_array" do
res = Version::Range.new('1.3.5', '1.3.3').to_a
expect(res).to eq([])
end
it "incorrect_range" do
expect { Version::Range.new '1.', '' }.to raise_error(ArgumentError)
end
end
end

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

.F....FF..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-apv47v/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 for comparison operators negatively
     Failure/Error: expect(@solution).to_not pass_tests
       expected this solution to not pass the tests:
       
         class Version
         def >(other)
           true
         end
           VALID_VERSION_REGEXP = /\A\z|\A[0-9]+(\.[0-9]+)*\z/
         
           include Comparable
         
           def initialize(version = '')
             unless VALID_VERSION_REGEXP.match(version.to_s)
               raise ArgumentError, "Invalid version string '#{version}'"
             end
         
             @components = version.to_s
               .split('.')
               .map(&:to_i)
               .reverse
               .drop_while(&:zero?)
               .reverse
           end
         
           def <=>(other)
             @components <=> Version.new(other).internal_components
           end
         
           def internal_components(positions = 0)
             padding_size = positions - @components.size
         
             if padding_size > 0
               @components + [0] * padding_size
             elsif positions != 0
               @components.take(positions)
             else
               @components.dup
             end
           end
         
           def components(positions = 0)
             padding_size = positions - @components.size
         
             if padding_size > 0
               @components + [0] * padding_size
             elsif positions != 0
               @components.take(positions)
             else
               @components.dup
             end
           end
         
           def to_s
             @components.join('.')
           end
         
           class Range
             include Enumerable
         
             def initialize(start_version, end_version)
               @start_version = Version.new(start_version)
               @end_version   = Version.new(end_version)
             end
         
             def include?(version)
               (@start_version <=> version) < 1 && (@end_version <=> version) == 1
             end
         
             def each
               current_version = @start_version
         
               while (current_version <=> @end_version) == -1
                 yield current_version
         
                 current_version = increment_version(current_version)
               end
             end
         
             private
         
             def increment_version(version)
               components = version.internal_components(3)
         
               components[2] += 1
         
               components.to_enum.with_index.reverse_each do |_, index|
                 component = components[index]
         
                 if component >= 10 && components[index - 1]
                   components[index]      = 0
                   components[index - 1] += 1
                 end
               end
         
               Version.new(components.join('.'))
             end
           end
         end
     # /tmp/d20161119-19072-apv47v/spec.rb:359: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 #components without 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)
             padding_size = positions - @components.size
           
             if padding_size > 0
               @components + [0] * padding_size
             else
               @components.take(positions)
             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-apv47v/spec.rb:402: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 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-apv47v/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)>'

  5) 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-apv47v/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 16.54 seconds
19 examples, 5 failures

Failed examples:

rspec /tmp/d20161119-19072-apv47v/spec.rb:241 # spec Version checks for ArgumentError with the correct message
rspec /tmp/d20161119-19072-apv47v/spec.rb:353 # spec Version checks for comparison operators negatively
rspec /tmp/d20161119-19072-apv47v/spec.rb:389 # spec Version tests #components without arguments
rspec /tmp/d20161119-19072-apv47v/spec.rb:441 # spec Version tests that #components cannot be used to modify the version
rspec /tmp/d20161119-19072-apv47v/spec.rb:515 # spec Version::Range tests include? with versions lower than the start one

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

Здравко обнови решението на 13.11.2016 14:58 (преди над 7 години)

+RSpec.describe 'Version' do
+ describe "parameter_empty_string" do
+ it "empty_string" do
+ version = Version.new('')
+ expect(version).to eq(0)
+ end
+
+ it "zero_string" do
+ version = Version.new('0')
+ expect(version).to eq(0)
+ end
+
+ it "no_parameter_no_brackets" do
+ version = Version.new
+ expect(version).to eq(0)
+ end
+ end
+
+ describe "correct_params" do
+ it "var" do
+ var = '1.3.5'
+ expect(Version.new(var)).to eq('1.3.5')
+ end
+
+ it "string" do
+ expect(Version.new('1.1.1')).to eq('1.1.1')
+ end
+
+ it "last_zero" do
+ expect(Version.new('1.1.0')).to eq('1.1.0')
+ end
+
+ it "zero_start" do
+ expect(Version.new('0.0.1')).to eq('0.0.1')
+ end
+ end
+
+ describe "components_corectness" do
+ it "zero_component" do
+ expect(Version.new.components(0)).to eq([])
+ end
+
+ it "one_component" do
+ expect(Version.new.components(1)).to eq([0])
+ end
+
+ it "one_component_zero" do
+ expect(Version.new(0).components(1)).to eq([0])
+ end
+
+ it "zero_component_string" do
+ expect(Version.new('').components(1)).to eq([0])
+ end
+
+ it "more_component" do
+ expect(Version.new('1.3.5').components(3)).to eq([1, 3, 5])
+ end
+
+ it "param_more_components" do
+ expect(Version.new('1.3.5').components(5)).to eq([1, 3, 5, 0, 0])
+ end
+
+ it "wrong_component_parameter" do
+ error = NoMethodError
+ expect { Version.new('1.3.5').components("s") }.to raise_error(error)
+ end
+ end
+
+ describe "incorrect_parameter" do
+ it "argument_error_array" do
+ expect { Version.new(['1.2.3']) }.to raise_error(ArgumentError)
+ end
+
+ it "argument_error_range_number" do
+ expect { Version.new(0..3) }.to raise_error(ArgumentError)
+ end
+
+ it "argument_error_range_letter" do
+ expect { Version.new(a..z) }.to raise_error(ArgumentError)
+ end
+
+ it "argument_error_point_start" do
+ expect { Version.new('.3.3') }.to raise_error(ArgumentError)
+ end
+
+ it "argument_error_string" do
+ expect { Version.new('random_string') }.to raise_error(ArgumentError)
+ end
+
+ it "argument_error_variable" do
+ expect { Version.new(random_variable) }.to raise_error(NameError)
+ end
+
+ it "argument_error_dot" do
+ expect { Version.new('1.3.5.') }.to raise_error(ArgumentError)
+ end
+ end
+
+ describe "compare_two_versions" do
+ it "less" do
+ statement = Version.new('1.3.5') < Version.new('1.3.6')
+ expect(statement).to eq(true)
+ end
+
+ it "equal" do
+ statement = Version.new('1.1.1') == Version.new('1.1.2')
+ expect(statement).to eq(false)
+ end
+
+ it "bigger" do
+ statement = Version.new('1.0.1') > Version.new('1.0.0')
+ expect(statement).to eq(true)
+ end
+
+ it "not_less" do
+ statement = Version.new('1.1.1') < Version.new('1.1.0')
+ expect(statement).to eq(false)
+ end
+
+ it "less_or_equal" do
+ statement = Version.new('1.1.1') <= Version.new('1.1.2')
+ expect(statement).to eq(true)
+ end
+
+ it "bigger_or_equal" do
+ statement = Version.new('1.1.1') >= Version.new('1.1.2')
+ expect(statement).to eq(false)
+ end
+
+ it "smaller_bigger_equal" do
+ statement = Version.new('1.1.0') <=> Version.new('1.1')
+ expect(statement).to eq(0)
+ end
+
+ it "shorter_longer" do
+ statement = Version.new('1.1') < Version.new('1.1.0.1')
+ expect(statement).to eq(true)
+ end
+ end
+
+ describe "to_string" do
+ it "no_parameter" do
+ expect(Version.new.to_s).to eq('')
+ end
+
+ it "zero" do
+ expect(Version.new(0).to_s).to eq('')
+ end
+
+ it "correct_input" do
+ expect(Version.new('1.3.5.6').to_s).to eq('1.3.5.6')
+ end
+
+ it "incorrect_input" do
+ expect { Version.new('1.3.4.').to_s }.to raise_error(ArgumentError)
+ end
+
+ it "last_zero" do
+ expect(Version.new('1.1.0').to_s).to eq('1.1')
+ end
+
+ it "zero_start" do
+ expect(Version.new('0.0.1').to_s).to eq('0.0.1')
+ end
+ end
+end

Здравко обнови решението на 14.11.2016 17:03 (преди над 7 години)

RSpec.describe 'Version' do
describe "parameter_empty_string" do
it "empty_string" do
version = Version.new('')
expect(version).to eq(0)
end
it "zero_string" do
version = Version.new('0')
expect(version).to eq(0)
end
it "no_parameter_no_brackets" do
version = Version.new
expect(version).to eq(0)
end
end
describe "correct_params" do
- it "var" do
+ it "version_object_nested" do
+ var = Version.new(Version.new(Version.new('1.2').to_s + '.9'))
+ expect(var).to eq('1.2.9')
+ end
+
+ it "variable_parameter" do
var = '1.3.5'
expect(Version.new(var)).to eq('1.3.5')
end
- it "string" do
+ it "string_parameter" do
expect(Version.new('1.1.1')).to eq('1.1.1')
end
- it "last_zero" do
+ it "last_zero_parameter" do
expect(Version.new('1.1.0')).to eq('1.1.0')
end
- it "zero_start" do
+ it "zero_start_parameter" do
expect(Version.new('0.0.1')).to eq('0.0.1')
end
+
+ it "instance_parameter" do
+ version = Version.new('1.1.1')
+ expect(Version.new(version)).to eq('1.1.1')
+ end
+
+ it "negative_parameter" do
+ expect { Version.new('-1.1.1') }.to raise_error(ArgumentError)
+ end
end
describe "components_corectness" do
it "zero_component" do
expect(Version.new.components(0)).to eq([])
end
it "one_component" do
expect(Version.new.components(1)).to eq([0])
end
it "one_component_zero" do
expect(Version.new(0).components(1)).to eq([0])
end
it "zero_component_string" do
expect(Version.new('').components(1)).to eq([0])
end
it "more_component" do
expect(Version.new('1.3.5').components(3)).to eq([1, 3, 5])
end
it "param_more_components" do
expect(Version.new('1.3.5').components(5)).to eq([1, 3, 5, 0, 0])
end
it "wrong_component_parameter" do
error = NoMethodError
expect { Version.new('1.3.5').components("s") }.to raise_error(error)
end
end
describe "incorrect_parameter" do
it "argument_error_array" do
expect { Version.new(['1.2.3']) }.to raise_error(ArgumentError)
end
it "argument_error_range_number" do
expect { Version.new(0..3) }.to raise_error(ArgumentError)
end
it "argument_error_range_letter" do
- expect { Version.new(a..z) }.to raise_error(ArgumentError)
+ expect { Version.new('a'..'z') }.to raise_error(ArgumentError)
end
it "argument_error_point_start" do
expect { Version.new('.3.3') }.to raise_error(ArgumentError)
end
it "argument_error_string" do
expect { Version.new('random_string') }.to raise_error(ArgumentError)
end
it "argument_error_variable" do
expect { Version.new(random_variable) }.to raise_error(NameError)
end
it "argument_error_dot" do
expect { Version.new('1.3.5.') }.to raise_error(ArgumentError)
end
end
describe "compare_two_versions" do
- it "less" do
- statement = Version.new('1.3.5') < Version.new('1.3.6')
- expect(statement).to eq(true)
+ it "first_less_than_second" do
+ expect(Version.new('1.3.5')).to be < Version.new('1.3.6')
end
- it "equal" do
- statement = Version.new('1.1.1') == Version.new('1.1.2')
- expect(statement).to eq(false)
+ it "first_equal_second" do
+ expect(Version.new('1.3.5')).to be == Version.new('1.3.5')
end
- it "bigger" do
- statement = Version.new('1.0.1') > Version.new('1.0.0')
- expect(statement).to eq(true)
+ it "first_bigger_than_second" do
+ expect(Version.new('1.3.5')).to be > Version.new('1.3.4')
end
- it "not_less" do
- statement = Version.new('1.1.1') < Version.new('1.1.0')
- expect(statement).to eq(false)
+ it "first_not_less_second" do
+ expect(Version.new('1.1.1') < Version.new('1.1.0')).to eq(false)
end
- it "less_or_equal" do
- statement = Version.new('1.1.1') <= Version.new('1.1.2')
- expect(statement).to eq(true)
+ it "first_less_or_equal_second" do
+ expect(Version.new('1.3.5')).to be <= Version.new('1.3.5')
end
- it "bigger_or_equal" do
- statement = Version.new('1.1.1') >= Version.new('1.1.2')
- expect(statement).to eq(false)
+ it "first_bigger_or_equal_second" do
+ expect(Version.new('1.3.5')).to be >= Version.new('1.3.5')
end
it "smaller_bigger_equal" do
- statement = Version.new('1.1.0') <=> Version.new('1.1')
- expect(statement).to eq(0)
+ expect(Version.new('1.1.0') <=> Version.new('1.1')).to eq(0)
end
it "shorter_longer" do
- statement = Version.new('1.1') < Version.new('1.1.0.1')
- expect(statement).to eq(true)
+ expect(Version.new('1.1')).to be < Version.new('1.1.0.1')
end
end
describe "to_string" do
it "no_parameter" do
expect(Version.new.to_s).to eq('')
end
- it "zero" do
+ it "zero_as_parameter" do
expect(Version.new(0).to_s).to eq('')
end
it "correct_input" do
expect(Version.new('1.3.5.6').to_s).to eq('1.3.5.6')
end
it "incorrect_input" do
expect { Version.new('1.3.4.').to_s }.to raise_error(ArgumentError)
end
it "last_zero" do
expect(Version.new('1.1.0').to_s).to eq('1.1')
end
it "zero_start" do
expect(Version.new('0.0.1').to_s).to eq('0.0.1')
+ end
+ end
+
+ describe "range_test_include" do
+ it "include_version" do
+ res = Version::Range.new('0.0.0.1', '0.0.0.2').include?('0.0.0.1.5')
+ expect(res).to eq(true)
+ end
+
+ it "include_fail" do
+ r = Version::Range.new(Version.new('1.5.0'), '1.0.1').include?('1.4.1')
+ expect(r).to eq(false)
+ end
+
+ it "include_nested" do
+ first = Version.new
+ second = Version.new(first.to_s + '0.9.2')
+ res = Version::Range.new(second, '1.0.0').include?('0.9.5')
+ expect(res).to eq(true)
+ end
+
+ it "include_from_x_to_x" do
+ res = Version::Range.new('1.3.5', '1.3.5').include?('1.3.5')
+ expect(res).to eq(false)
+ end
+
+ it "include_equal_to_start_version" do
+ res = Version::Range.new('1.0.1', '1.1.1').include?('1.0.1')
+ expect(res).to eq(true)
+ end
+ end
+
+ describe "range_test_to_a" do
+ it "correct_one" do
+ res = Version::Range.new('1.0.1', '1.0.2').to_a
+ expect(res).to eq(['1.0.1'])
+ end
+
+ it "empty_array" do
+ res = Version::Range.new('1.3.5', '1.3.5').to_a
+ expect(res).to eq([])
+ end
+
+ it "outrange_array" do
+ res = Version::Range.new('1.3.5', '1.3.3').to_a
+ expect(res).to eq([])
end
end
end

Здравко обнови решението на 14.11.2016 17:03 (преди над 7 години)

RSpec.describe 'Version' do
describe "parameter_empty_string" do
it "empty_string" do
version = Version.new('')
expect(version).to eq(0)
end
it "zero_string" do
version = Version.new('0')
expect(version).to eq(0)
end
it "no_parameter_no_brackets" do
version = Version.new
expect(version).to eq(0)
end
end
describe "correct_params" do
it "version_object_nested" do
var = Version.new(Version.new(Version.new('1.2').to_s + '.9'))
expect(var).to eq('1.2.9')
end
it "variable_parameter" do
var = '1.3.5'
expect(Version.new(var)).to eq('1.3.5')
end
it "string_parameter" do
expect(Version.new('1.1.1')).to eq('1.1.1')
end
it "last_zero_parameter" do
expect(Version.new('1.1.0')).to eq('1.1.0')
end
it "zero_start_parameter" do
expect(Version.new('0.0.1')).to eq('0.0.1')
end
it "instance_parameter" do
version = Version.new('1.1.1')
expect(Version.new(version)).to eq('1.1.1')
end
it "negative_parameter" do
expect { Version.new('-1.1.1') }.to raise_error(ArgumentError)
end
end
describe "components_corectness" do
it "zero_component" do
expect(Version.new.components(0)).to eq([])
end
it "one_component" do
expect(Version.new.components(1)).to eq([0])
end
it "one_component_zero" do
expect(Version.new(0).components(1)).to eq([0])
end
it "zero_component_string" do
expect(Version.new('').components(1)).to eq([0])
end
it "more_component" do
expect(Version.new('1.3.5').components(3)).to eq([1, 3, 5])
end
it "param_more_components" do
expect(Version.new('1.3.5').components(5)).to eq([1, 3, 5, 0, 0])
end
it "wrong_component_parameter" do
error = NoMethodError
expect { Version.new('1.3.5').components("s") }.to raise_error(error)
end
end
describe "incorrect_parameter" do
it "argument_error_array" do
expect { Version.new(['1.2.3']) }.to raise_error(ArgumentError)
end
it "argument_error_range_number" do
expect { Version.new(0..3) }.to raise_error(ArgumentError)
end
it "argument_error_range_letter" do
expect { Version.new('a'..'z') }.to raise_error(ArgumentError)
end
it "argument_error_point_start" do
expect { Version.new('.3.3') }.to raise_error(ArgumentError)
end
it "argument_error_string" do
expect { Version.new('random_string') }.to raise_error(ArgumentError)
end
- it "argument_error_variable" do
- expect { Version.new(random_variable) }.to raise_error(NameError)
- end
-
it "argument_error_dot" do
expect { Version.new('1.3.5.') }.to raise_error(ArgumentError)
end
end
describe "compare_two_versions" do
it "first_less_than_second" do
expect(Version.new('1.3.5')).to be < Version.new('1.3.6')
end
it "first_equal_second" do
expect(Version.new('1.3.5')).to be == Version.new('1.3.5')
end
it "first_bigger_than_second" do
expect(Version.new('1.3.5')).to be > Version.new('1.3.4')
end
it "first_not_less_second" do
expect(Version.new('1.1.1') < Version.new('1.1.0')).to eq(false)
end
it "first_less_or_equal_second" do
expect(Version.new('1.3.5')).to be <= Version.new('1.3.5')
end
it "first_bigger_or_equal_second" do
expect(Version.new('1.3.5')).to be >= Version.new('1.3.5')
end
it "smaller_bigger_equal" do
expect(Version.new('1.1.0') <=> Version.new('1.1')).to eq(0)
end
it "shorter_longer" do
expect(Version.new('1.1')).to be < Version.new('1.1.0.1')
end
end
describe "to_string" do
it "no_parameter" do
expect(Version.new.to_s).to eq('')
end
it "zero_as_parameter" do
expect(Version.new(0).to_s).to eq('')
end
it "correct_input" do
expect(Version.new('1.3.5.6').to_s).to eq('1.3.5.6')
end
it "incorrect_input" do
expect { Version.new('1.3.4.').to_s }.to raise_error(ArgumentError)
end
it "last_zero" do
expect(Version.new('1.1.0').to_s).to eq('1.1')
end
it "zero_start" do
expect(Version.new('0.0.1').to_s).to eq('0.0.1')
end
end
describe "range_test_include" do
it "include_version" do
res = Version::Range.new('0.0.0.1', '0.0.0.2').include?('0.0.0.1.5')
expect(res).to eq(true)
end
it "include_fail" do
r = Version::Range.new(Version.new('1.5.0'), '1.0.1').include?('1.4.1')
expect(r).to eq(false)
end
it "include_nested" do
first = Version.new
second = Version.new(first.to_s + '0.9.2')
res = Version::Range.new(second, '1.0.0').include?('0.9.5')
expect(res).to eq(true)
end
it "include_from_x_to_x" do
res = Version::Range.new('1.3.5', '1.3.5').include?('1.3.5')
expect(res).to eq(false)
end
it "include_equal_to_start_version" do
res = Version::Range.new('1.0.1', '1.1.1').include?('1.0.1')
expect(res).to eq(true)
end
end
describe "range_test_to_a" do
it "correct_one" do
res = Version::Range.new('1.0.1', '1.0.2').to_a
expect(res).to eq(['1.0.1'])
end
it "empty_array" do
res = Version::Range.new('1.3.5', '1.3.5').to_a
expect(res).to eq([])
end
it "outrange_array" do
res = Version::Range.new('1.3.5', '1.3.3').to_a
expect(res).to eq([])
end
end
end

Здравко обнови решението на 14.11.2016 21:56 (преди над 7 години)

RSpec.describe 'Version' do
describe "parameter_empty_string" do
it "empty_string" do
version = Version.new('')
expect(version).to eq(0)
end
it "zero_string" do
version = Version.new('0')
expect(version).to eq(0)
end
it "no_parameter_no_brackets" do
version = Version.new
expect(version).to eq(0)
end
end
describe "correct_params" do
it "version_object_nested" do
var = Version.new(Version.new(Version.new('1.2').to_s + '.9'))
expect(var).to eq('1.2.9')
end
it "variable_parameter" do
var = '1.3.5'
expect(Version.new(var)).to eq('1.3.5')
end
it "string_parameter" do
expect(Version.new('1.1.1')).to eq('1.1.1')
end
it "last_zero_parameter" do
expect(Version.new('1.1.0')).to eq('1.1.0')
end
it "zero_start_parameter" do
expect(Version.new('0.0.1')).to eq('0.0.1')
end
it "instance_parameter" do
version = Version.new('1.1.1')
expect(Version.new(version)).to eq('1.1.1')
end
- it "negative_parameter" do
+ it "negative_number_in_string_parameter" do
expect { Version.new('-1.1.1') }.to raise_error(ArgumentError)
+ end
+
+ it "negative_number_parameter" do
+ expect { Version.new(-1.1) }.to raise_error(ArgumentError)
end
end
describe "components_corectness" do
it "zero_component" do
expect(Version.new.components(0)).to eq([])
end
it "one_component" do
expect(Version.new.components(1)).to eq([0])
end
it "one_component_zero" do
expect(Version.new(0).components(1)).to eq([0])
end
it "zero_component_string" do
expect(Version.new('').components(1)).to eq([0])
end
it "more_component" do
expect(Version.new('1.3.5').components(3)).to eq([1, 3, 5])
end
it "param_more_components" do
expect(Version.new('1.3.5').components(5)).to eq([1, 3, 5, 0, 0])
end
it "wrong_component_parameter" do
error = NoMethodError
expect { Version.new('1.3.5').components("s") }.to raise_error(error)
end
end
describe "incorrect_parameter" do
it "argument_error_array" do
expect { Version.new(['1.2.3']) }.to raise_error(ArgumentError)
end
it "argument_error_range_number" do
expect { Version.new(0..3) }.to raise_error(ArgumentError)
end
it "argument_error_range_letter" do
expect { Version.new('a'..'z') }.to raise_error(ArgumentError)
end
it "argument_error_point_start" do
expect { Version.new('.3.3') }.to raise_error(ArgumentError)
end
it "argument_error_string" do
expect { Version.new('random_string') }.to raise_error(ArgumentError)
end
it "argument_error_dot" do
expect { Version.new('1.3.5.') }.to raise_error(ArgumentError)
end
end
describe "compare_two_versions" do
it "first_less_than_second" do
expect(Version.new('1.3.5')).to be < Version.new('1.3.6')
end
it "first_equal_second" do
expect(Version.new('1.3.5')).to be == Version.new('1.3.5')
end
it "first_bigger_than_second" do
expect(Version.new('1.3.5')).to be > Version.new('1.3.4')
end
it "first_not_less_second" do
expect(Version.new('1.1.1') < Version.new('1.1.0')).to eq(false)
end
it "first_less_or_equal_second" do
expect(Version.new('1.3.5')).to be <= Version.new('1.3.5')
end
it "first_bigger_or_equal_second" do
expect(Version.new('1.3.5')).to be >= Version.new('1.3.5')
end
it "smaller_bigger_equal" do
expect(Version.new('1.1.0') <=> Version.new('1.1')).to eq(0)
end
it "shorter_longer" do
expect(Version.new('1.1')).to be < Version.new('1.1.0.1')
end
end
describe "to_string" do
it "no_parameter" do
expect(Version.new.to_s).to eq('')
end
it "zero_as_parameter" do
expect(Version.new(0).to_s).to eq('')
end
it "correct_input" do
expect(Version.new('1.3.5.6').to_s).to eq('1.3.5.6')
end
it "incorrect_input" do
expect { Version.new('1.3.4.').to_s }.to raise_error(ArgumentError)
end
it "last_zero" do
expect(Version.new('1.1.0').to_s).to eq('1.1')
end
it "zero_start" do
expect(Version.new('0.0.1').to_s).to eq('0.0.1')
end
end
describe "range_test_include" do
it "include_version" do
res = Version::Range.new('0.0.0.1', '0.0.0.2').include?('0.0.0.1.5')
expect(res).to eq(true)
end
it "include_fail" do
r = Version::Range.new(Version.new('1.5.0'), '1.0.1').include?('1.4.1')
expect(r).to eq(false)
end
it "include_nested" do
first = Version.new
second = Version.new(first.to_s + '0.9.2')
res = Version::Range.new(second, '1.0.0').include?('0.9.5')
expect(res).to eq(true)
end
it "include_from_x_to_x" do
res = Version::Range.new('1.3.5', '1.3.5').include?('1.3.5')
expect(res).to eq(false)
end
it "include_equal_to_start_version" do
res = Version::Range.new('1.0.1', '1.1.1').include?('1.0.1')
expect(res).to eq(true)
end
end
describe "range_test_to_a" do
it "correct_one" do
res = Version::Range.new('1.0.1', '1.0.2').to_a
expect(res).to eq(['1.0.1'])
end
it "empty_array" do
res = Version::Range.new('1.3.5', '1.3.5').to_a
expect(res).to eq([])
end
it "outrange_array" do
res = Version::Range.new('1.3.5', '1.3.3').to_a
expect(res).to eq([])
end
end
end

Здравко обнови решението на 18.11.2016 14:26 (преди над 7 години)

RSpec.describe 'Version' do
describe "parameter_empty_string" do
it "empty_string" do
version = Version.new('')
expect(version).to eq(0)
end
it "zero_string" do
version = Version.new('0')
expect(version).to eq(0)
end
it "no_parameter_no_brackets" do
version = Version.new
expect(version).to eq(0)
end
end
describe "correct_params" do
it "version_object_nested" do
var = Version.new(Version.new(Version.new('1.2').to_s + '.9'))
expect(var).to eq('1.2.9')
end
it "variable_parameter" do
var = '1.3.5'
expect(Version.new(var)).to eq('1.3.5')
end
it "string_parameter" do
expect(Version.new('1.1.1')).to eq('1.1.1')
end
it "last_zero_parameter" do
expect(Version.new('1.1.0')).to eq('1.1.0')
end
it "zero_start_parameter" do
expect(Version.new('0.0.1')).to eq('0.0.1')
end
it "instance_parameter" do
version = Version.new('1.1.1')
expect(Version.new(version)).to eq('1.1.1')
end
it "negative_number_in_string_parameter" do
expect { Version.new('-1.1.1') }.to raise_error(ArgumentError)
end
it "negative_number_parameter" do
expect { Version.new(-1.1) }.to raise_error(ArgumentError)
end
end
describe "components_corectness" do
it "zero_component" do
expect(Version.new.components(0)).to eq([])
end
it "one_component" do
expect(Version.new.components(1)).to eq([0])
end
it "one_component_zero" do
expect(Version.new(0).components(1)).to eq([0])
end
it "zero_component_string" do
expect(Version.new('').components(1)).to eq([0])
end
it "more_component" do
expect(Version.new('1.3.5').components(3)).to eq([1, 3, 5])
end
it "param_more_components" do
expect(Version.new('1.3.5').components(5)).to eq([1, 3, 5, 0, 0])
end
it "wrong_component_parameter" do
error = NoMethodError
expect { Version.new('1.3.5').components("s") }.to raise_error(error)
end
+
+ it "mutabillity" do
+ version = Version.new('1.3.5').components(2)
+ version.to_s.upcase!
+ expect(version).to eq([1, 3])
+ end
end
describe "incorrect_parameter" do
it "argument_error_array" do
expect { Version.new(['1.2.3']) }.to raise_error(ArgumentError)
end
it "argument_error_range_number" do
expect { Version.new(0..3) }.to raise_error(ArgumentError)
end
it "argument_error_range_letter" do
expect { Version.new('a'..'z') }.to raise_error(ArgumentError)
end
it "argument_error_point_start" do
expect { Version.new('.3.3') }.to raise_error(ArgumentError)
end
+ it "argument_error_point_end" do
+ expect { Version.new('3.3.') }. to raise_error(ArgumentError)
+ end
+
it "argument_error_string" do
expect { Version.new('random_string') }.to raise_error(ArgumentError)
end
it "argument_error_dot" do
expect { Version.new('1.3.5.') }.to raise_error(ArgumentError)
end
end
describe "compare_two_versions" do
it "first_less_than_second" do
expect(Version.new('1.3.5')).to be < Version.new('1.3.6')
+ expect(Version.new('1.0.0')).to be < Version.new('1.0.0.1')
end
it "first_equal_second" do
expect(Version.new('1.3.5')).to be == Version.new('1.3.5')
+ expect(Version.new('1.0.0')).to be == Version.new(1)
end
it "first_bigger_than_second" do
expect(Version.new('1.3.5')).to be > Version.new('1.3.4')
+ expect(Version.new('1.0.0.0.1')).to be > Version.new('1.0.0')
end
it "first_not_less_second" do
expect(Version.new('1.1.1') < Version.new('1.1.0')).to eq(false)
+ expect(Version.new(''))
end
it "first_less_or_equal_second" do
expect(Version.new('1.3.5')).to be <= Version.new('1.3.5')
end
it "first_bigger_or_equal_second" do
expect(Version.new('1.3.5')).to be >= Version.new('1.3.5')
end
it "smaller_bigger_equal" do
expect(Version.new('1.1.0') <=> Version.new('1.1')).to eq(0)
end
it "shorter_longer" do
expect(Version.new('1.1')).to be < Version.new('1.1.0.1')
end
end
describe "to_string" do
it "no_parameter" do
expect(Version.new.to_s).to eq('')
end
it "zero_as_parameter" do
expect(Version.new(0).to_s).to eq('')
end
it "correct_input" do
expect(Version.new('1.3.5.6').to_s).to eq('1.3.5.6')
end
it "incorrect_input" do
expect { Version.new('1.3.4.').to_s }.to raise_error(ArgumentError)
end
it "last_zero" do
expect(Version.new('1.1.0').to_s).to eq('1.1')
end
it "zero_start" do
expect(Version.new('0.0.1').to_s).to eq('0.0.1')
end
end
describe "range_test_include" do
it "include_version" do
res = Version::Range.new('0.0.0.1', '0.0.0.2').include?('0.0.0.1.5')
expect(res).to eq(true)
end
it "include_fail" do
r = Version::Range.new(Version.new('1.5.0'), '1.0.1').include?('1.4.1')
expect(r).to eq(false)
end
it "include_nested" do
first = Version.new
second = Version.new(first.to_s + '0.9.2')
res = Version::Range.new(second, '1.0.0').include?('0.9.5')
expect(res).to eq(true)
end
it "include_from_x_to_x" do
res = Version::Range.new('1.3.5', '1.3.5').include?('1.3.5')
expect(res).to eq(false)
end
it "include_equal_to_start_version" do
res = Version::Range.new('1.0.1', '1.1.1').include?('1.0.1')
expect(res).to eq(true)
end
end
describe "range_test_to_a" do
it "correct_one" do
res = Version::Range.new('1.0.1', '1.0.2').to_a
expect(res).to eq(['1.0.1'])
end
it "empty_array" do
res = Version::Range.new('1.3.5', '1.3.5').to_a
expect(res).to eq([])
end
it "outrange_array" do
res = Version::Range.new('1.3.5', '1.3.3').to_a
expect(res).to eq([])
+ end
+
+ it "incorrect_range" do
+ expect { Version::Range.new '1.', '' }.to raise_error(ArgumentError)
end
end
end