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

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

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

Резултати

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

Код

RSpec.describe 'Version' do
describe 'Version' do
context 'initialization' do
it 'creates a basic Version' do
expect(Version.new("1")).to be_a Version
end
it 'creates a valid Version' do
valid_options = ["1", "1.1.1", "1.1.1.1", Version.new("1")]
valid_options.each do |version|
expect(Version.new(version)).to be_truthy
end
end
it 'creates an invalid Version' do
invalid_options = [
"asd", :sym, "1,1", "-1", "-1.1", "1..1", ".1", ".."
]
invalid_options.each do |version|
expect { Version.new(version) }.to raise_error(ArgumentError)
expect { Version.new(version) }
.to raise_error("Invalid version string '#{version}'")
end
end
it 'creates a Version from an empty string or without an argument' do
expect(Version.new("")).to be_an_instance_of Version
expect(Version.new).to be_an_instance_of Version
end
end
context 'comparison' do
it '#>' do
expect(Version.new("1.1.1")).to be > Version.new("1.1")
expect(Version.new("1.2")).to be > Version.new("1.1.9")
expect(Version.new("2.0")).to be > Version.new("1.9")
expect(Version.new("1.1.9")).to be > Version.new("1.1.8.9")
end
it '#<' do
expect(Version.new("0.1")).to be < Version.new("1")
expect(Version.new("0.0.1")).to be < Version.new("0.1")
expect(Version.new("3")).to be < Version.new("3.0.0.0.1")
expect(Version.new("5")).to be < Version.new("5.5.5")
end
it '#<=' do
expect(Version.new("0.1")).to be <= Version.new("1")
expect(Version.new("0.0.1")).to be <= Version.new("0.1")
expect(Version.new("3")).to be <= Version.new("3.0.0.0.1")
expect(Version.new("1.0")).to be <= Version.new("1")
end
it '#>=' do
expect(Version.new("1.1.1")).to be >= Version.new("1.1")
expect(Version.new("1.2")).to be >= Version.new("1.1.9")
expect(Version.new("2.0")).to be >= Version.new("1.9")
expect(Version.new("1.1.9")).to be >= Version.new("1.1.8.9")
expect(Version.new("1.0")).to be >= Version.new("1")
end
it '#==' do
expect(Version.new("1.1.0")).to be == Version.new("1.1")
expect(Version.new("2.0")).to be == Version.new("2")
expect(Version.new("2.0.0.0.0.0")).to be == Version.new("2")
end
it '#<=>' do
expect(Version.new("1.0.1") <=> Version.new("1.1")).to equal -1
expect(Version.new("1.2") <=> Version.new("1.1.9")).to equal 1
expect(Version.new("2.0") <=> Version.new("2")).to equal 0
end
end
context '#to_s' do
it 'basic versions' do
expect(Version.new("1.1").to_s).to eq "1.1"
expect(Version.new("1").to_s).to eq "1"
expect(Version.new("0").to_s).to eq ""
expect(Version.new("1.1.1.1.1").to_s).to eq "1.1.1.1.1"
end
it 'complex versions' do
expect(Version.new("1.1.0").to_s).to eq "1.1"
expect(Version.new("1.0.0").to_s).to eq "1"
expect(Version.new("0.0").to_s).to eq ""
expect(Version.new("1.1.1.1.1.0.0.0.0.0.0.0.0.0.0.0").to_s)
.to eq "1.1.1.1.1"
end
end
context '#components' do
it 'basic versions' do
expect(Version.new("1.1").components).to eq [1, 1]
expect(Version.new("2").components).to eq [2]
expect(Version.new("2.2").components).to eq [2, 2]
expect(Version.new("1.2.3.4.5.6.7.8.9").components)
.to eq [1, 2, 3, 4, 5, 6, 7, 8, 9]
end
it 'zero ending versions' do
expect(Version.new("1.1.0").components).to eq [1, 1]
expect(Version.new("2.0.0.0.0.0.0").components).to eq [2]
expect(Version.new("2.0.2.0").components).to eq [2, 0, 2]
end
it '#components with a given count' do
expect(Version.new("1.1.0").components(1)).to eq [1]
expect(Version.new("1.2.3.4.5.6.7.8").components(4))
.to match_array [1, 2, 3, 4]
expect(Version.new("1.2.3.4.5.6.7.8").components(7))
.to match_array [1, 2, 3, 4, 5, 6, 7]
expect(Version.new("1.2.3.4.5.6.7.8").components(10))
.to match_array [1, 2, 3, 4, 5, 6, 7, 8, 0, 0]
expect(Version.new("1.2").components(5)).to match_array [1, 2, 0, 0, 0]
end
end
end
describe 'Range' do
context 'initialization' do
it 'creates an instance of Range' do
expect(Range.new(Version.new("1"), "1.9")).to be_a Range
expect(Range.new("1.1", "1.9")).to be_a Range
expect(Range.new(Version.new("1"), Version.new("1.9"))).to be_a Range
end
end
context '#include?' do
it 'checks if argument is >= starting and < ending version' do
expect(Range.new("1.1", "1.4").include?("1.3")).to be_truthy
expect(Range.new("1.1", "1.4").include?("1.4")).to be_falsy
expect(Range.new("1", "2").include?(Version.new("1.5"))).to be_truthy
expect(Range.new("1", "2").include?("1.5")).to be_truthy
expect(Range.new("1", "1.1.1").include?("1.1")).to be_truthy
expect(Range.new("1", "1.1.1").include?("1.1.1")).to be_falsy
expect(Range.new("2.12", "2.42").include?("2.15")).to be_truthy
end
end
context '#to_a' do
it 'checls if version are included in an array' do
expect(Range.new("1.1", "1.2").to_a).to match_array [
'1.1', '1.1.1', '1.1.2', '1.1.3', '1.1.4', '1.1.5',
'1.1.6', '1.1.7', '1.1.8', '1.1.9'
]
expect(Range.new("1.1.1", "1.1.5").to_a).to match_array [
'1.1.1', '1.1.2', '1.1.3', '1.1.4'
]
expect(Range.new("1.9.9", "2.0.2").to_a).to match_array [
"1.9.9", "2", "2.0.1"
]
expect(Range.new("1.1.0", "1.2.2").to_a).to match_array [
'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
end
end
end

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

F

Failures:

  1) spec passes for the correct solution
     Failure/Error: expect(SOLUTION).to pass_tests
       expected this solution to pass the tests:
       
         class Version
           VALID_VERSION_REGEXP = /\A\z|\A[0-9]+(\.[0-9]+)*\z/
         
           include Comparable
         
           def initialize(version = '')
             unless VALID_VERSION_REGEXP.match(version.to_s)
               raise ArgumentError, "Invalid version string '#{version}'"
             end
         
             @components = version.to_s
               .split('.')
               .map(&:to_i)
               .reverse
               .drop_while(&:zero?)
               .reverse
           end
         
           def <=>(other)
             @components <=> Version.new(other).internal_components
           end
         
           def internal_components(positions = 0)
             padding_size = positions - @components.size
         
             if padding_size > 0
               @components + [0] * padding_size
             elsif positions != 0
               @components.take(positions)
             else
               @components.dup
             end
           end
         
           def components(positions = 0)
             padding_size = positions - @components.size
         
             if padding_size > 0
               @components + [0] * padding_size
             elsif positions != 0
               @components.take(positions)
             else
               @components.dup
             end
           end
         
           def to_s
             @components.join('.')
           end
         
           class Range
             include Enumerable
         
             def initialize(start_version, end_version)
               @start_version = Version.new(start_version)
               @end_version   = Version.new(end_version)
             end
         
             def include?(version)
               (@start_version <=> version) < 1 && (@end_version <=> version) == 1
             end
         
             def each
               current_version = @start_version
         
               while (current_version <=> @end_version) == -1
                 yield current_version
         
                 current_version = increment_version(current_version)
               end
             end
         
             private
         
             def increment_version(version)
               components = version.internal_components(3)
         
               components[2] += 1
         
               components.to_enum.with_index.reverse_each do |_, index|
                 component = components[index]
         
                 if component >= 10 && components[index - 1]
                   components[index]      = 0
                   components[index - 1] += 1
                 end
               end
         
               Version.new(components.join('.'))
             end
           end
         end
       
       
       RSpec log:
       
         ................FF
         
         Failures:
         
           1) Version Range #include? checks if argument is >= starting and < ending version
              Failure/Error: expect(Range.new("1.1", "1.4").include?("1.4")).to be_falsy
                expected: falsey value
                     got: true
              # ./solution_spec.rb:131:in `block (4 levels) in <top (required)>'
         
           2) Version Range #to_a checls if version are included in an array
              Failure/Error: expect(Range.new("1.1", "1.2").to_a).to match_array [
                expected collection contained:  ["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"]
                actual collection contained:    ["1.1", "1.2"]
                the missing elements were:      ["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"]
                the extra elements were:        ["1.2"]
              # ./solution_spec.rb:142:in `block (4 levels) in <top (required)>'
         
         Finished in 0.01406 seconds
         18 examples, 2 failures
         
         Failed examples:
         
         rspec ./solution_spec.rb:129 # Version Range #include? checks if argument is >= starting and < ending version
         rspec ./solution_spec.rb:141 # Version Range #to_a checls if version are included in an array
     # /tmp/d20161119-19072-4adnix/spec.rb:180:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.74408 seconds
1 example, 1 failure

Failed examples:

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

История (2 версии и 11 коментара)

Мартин обнови решението на 16.11.2016 20:07 (преди над 7 години)

+RSpec.describe 'Version' do
+ def init_version(version)
+ Version.new(version)
+ end
+
+ describe 'Version' do
+ context 'initialization' do
+ invalid_options = ["asd", :sym, "1,1", "-1", "-1.1", "1..1", ".1", ".."]
+ valid_options = ["1", "1.1.1", "1.1.1.1", Version.new("1")]
+
+ def error_message(version)
+ "Invalid version string '#{version}'"
+ end
+
+ it 'creates a basic Version' do
+ expect(init_version("1")).to be_a Version
+ end
+
+ it 'creates a valid Version' do
+ valid_options.each do |version|
+ expect(init_version(version)).to be_truthy
+ end
+ end
+
+ it 'creates an invalid Version' do
+ invalid_options.each do |version|
+ expect { init_version(version) }.to raise_error(ArgumentError)
+ expect { init_version(version) }
+ .to raise_error(error_message(version))
+ end
+ end
+
+ it 'creates a Version from an empty string or without an argument' do
+ expect(init_version("")).to be_an_instance_of Version
+ expect(Version.new).to be_an_instance_of Version
+ end
+ end
+
+ context 'comparison' do
+ it 'tests bigger than' do
+ expect(init_version("1.1.1") > init_version("1.1")).to be_truthy
+ expect(init_version("1.2") > init_version("1.1.9")).to be_truthy
+ expect(init_version("2.0") > init_version("1.9")).to be_truthy
+ expect(init_version("1.1.9") > init_version("1.1.8.9")).to be_truthy
+ end
+
+ it 'tests less than' do
+ expect(init_version("0.1") < init_version("1")).to be_truthy
+ expect(init_version("0.0.1") < init_version("0.1")).to be_truthy
+ expect(init_version("3") < init_version("3.0.0.0.1")).to be_truthy
+ expect(init_version("5") < init_version("5.5.5")).to be_truthy
+ end
+
+ it 'tests less than or equal' do
+ expect(init_version("0.1") <= init_version("1")).to be_truthy
+ expect(init_version("0.0.1") <= init_version("0.1")).to be_truthy
+ expect(init_version("3") <= init_version("3.0.0.0.1")).to be_truthy
+ expect(init_version("1.0") <= init_version("1")).to be_truthy
+ end
+
+ it 'tests bigger than or equal' do
+ expect(init_version("1.1.1") >= init_version("1.1")).to be_truthy
+ expect(init_version("1.2") >= init_version("1.1.9")).to be_truthy
+ expect(init_version("2.0") >= init_version("1.9")).to be_truthy
+ expect(init_version("1.1.9") >= init_version("1.1.8.9")).to be_truthy
+ expect(init_version("1.0") >= init_version("1")).to be_truthy
+ end
+
+ it 'tests equal' do
+ expect(init_version("1.1.0") == init_version("1.1")).to be_truthy
+ expect(init_version("2.0") == init_version("2")).to be_truthy
+ end
+
+ it 'tests less, equal or bigger than' do
+ expect(init_version("1.0.1") <=> init_version("1.1")).to equal -1
+ expect(init_version("1.2") <=> init_version("1.1.9")).to equal 1
+ expect(init_version("2.0") <=> init_version("2")).to equal 0
+ end
+ end
+
+ context '#to_s' do
+ it 'test for basic versions' do
+ expect(init_version("1.1").to_s).to eql "1.1"
+ expect(init_version("1").to_s).to eql "1"
+ expect(init_version("0").to_s).to eql ""
+ expect(init_version("1.1.1.1.1").to_s).to eql "1.1.1.1.1"
+ end
+
+ it 'test for complex versions' do
+ expect(init_version("1.1.0").to_s).to eql "1.1"
+ expect(init_version("1.0.0").to_s).to eql "1"
+ expect(init_version("0.0").to_s).to eql ""
+ expect(init_version("1.1.1.1.1.0.0.0.0.0.0.0.0.0.0.0").to_s)
+ .to eql "1.1.1.1.1"
+ end
+ end
+
+ context '#components' do
+ def compose(args)
+ if args.length == 1
+ Version.new(args[0]).components
+ else
+ Version.new(args[0]).components(args[1])
+ end
+ end
+
+ it 'test basic versions' do
+ expect(compose(["1.1"])).to eq [1, 1]
+ expect(compose(["2"])).to eq [2]
+ expect(compose(["2.2"])).to eq [2, 2]
+ expect(compose(["1.2.3.4.5.6.7.8.9"]))
+ .to eq [1, 2, 3, 4, 5, 6, 7, 8, 9]
+ end
+
+ it 'test zero ending versions' do
+ expect(compose(["1.1.0"])).to eq [1, 1]
+ expect(compose(["2.0.0.0.0.0.0"])).to eq [2]
+ expect(compose(["2.0.2.0"])).to eq [2, 0, 2]
+ end
+
+ it 'tests #components with a given count' do
+ expect(compose(["1.1.0", 1])).to eq [1]
+ expect(compose(["1.2.3.4.5.6.7.8", 4])).to match_array [1, 2, 3, 4]
+ expect(compose(["1.2.3.4.5.6.7.8", 7]))
+ .to match_array [1, 2, 3, 4, 5, 6, 7]
+ expect(compose(["1.2.3.4.5.6.7.8", 10]))
+ .to match_array [1, 2, 3, 4, 5, 6, 7, 8, 0, 0]
+ expect(compose(["1.2", 5])).to match_array [1, 2, 0, 0, 0]
+ end
+ end
+ end
+
+ describe 'Range' do
+ def init_range(start_version, end_version)
+ Range.new(start_version, end_version)
+ end
+ context 'initialization' do
+ it 'creates an instance of Range' do
+ expect(init_range(Version.new("1"), "1.9")).to be_a Range
+ expect(init_range("1.1", "1.9")).to be_a Range
+ expect(init_range(Version.new("1"), Version.new("1.9"))).to be_a Range
+ end
+ end
+ context '#include?' do
+ it 'checks if passed version is bigger or equal to the starting
+ and less than the ending version' do
+ expect(init_range("1.1", "1.4").include?("1.3")).to be_truthy
+ expect(init_range("1.1", "1.4").include?("1.4")).to be_falsy
+ expect(init_range("1", "2").include?(Version.new("1.5"))).to be_truthy
+ expect(init_range("1", "2").include?("1.5")).to be_truthy
+ expect(init_range("1", "1.1.1").include?("1.1")).to be_truthy
+ expect(init_range("1", "1.1.1").include?("1.1.1")).to be_falsy
+ expect(init_range("2.12", "2.42").include?("2.15")).to be_truthy
+ end
+ end
+
+ context '#to_a' do
+ it 'tests if versions are included in the array' do
+ expect(init_range("1.1", "1.2").to_a).to match_array [
+ '1.1', '1.1.1', '1.1.2', '1.1.3', '1.1.4', '1.1.5',
+ '1.1.6', '1.1.7', '1.1.8', '1.1.9'
+ ]
+ expect(init_range("1.1.1", "1.1.5").to_a).to match_array [
+ '1.1.1', '1.1.2', '1.1.3', '1.1.4'
+ ]
+ expect(init_range("1.9.9", "2.0.2").to_a).to match_array [
+ "1.9.9", "2", "2.0.1"
+ ]
+ expect(init_range("1.1.0", "1.2.2").to_a).to match_array [
+ '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
+ end
+ end
+end

Мартин обнови решението на 17.11.2016 14:37 (преди над 7 години)

RSpec.describe 'Version' do
- def init_version(version)
- Version.new(version)
- end
-
describe 'Version' do
context 'initialization' do
- invalid_options = ["asd", :sym, "1,1", "-1", "-1.1", "1..1", ".1", ".."]
- valid_options = ["1", "1.1.1", "1.1.1.1", Version.new("1")]
-
- def error_message(version)
- "Invalid version string '#{version}'"
- end
-
it 'creates a basic Version' do
- expect(init_version("1")).to be_a Version
+ expect(Version.new("1")).to be_a Version
end
it 'creates a valid Version' do
+ valid_options = ["1", "1.1.1", "1.1.1.1", Version.new("1")]
valid_options.each do |version|
- expect(init_version(version)).to be_truthy
+ expect(Version.new(version)).to be_truthy
end
end
it 'creates an invalid Version' do
+ invalid_options = [
+ "asd", :sym, "1,1", "-1", "-1.1", "1..1", ".1", ".."
+ ]
invalid_options.each do |version|
- expect { init_version(version) }.to raise_error(ArgumentError)
- expect { init_version(version) }
- .to raise_error(error_message(version))
+ expect { Version.new(version) }.to raise_error(ArgumentError)
+ expect { Version.new(version) }
+ .to raise_error("Invalid version string '#{version}'")
end
end
it 'creates a Version from an empty string or without an argument' do
- expect(init_version("")).to be_an_instance_of Version
+ expect(Version.new("")).to be_an_instance_of Version
expect(Version.new).to be_an_instance_of Version
end
end
context 'comparison' do
- it 'tests bigger than' do
- expect(init_version("1.1.1") > init_version("1.1")).to be_truthy
- expect(init_version("1.2") > init_version("1.1.9")).to be_truthy
- expect(init_version("2.0") > init_version("1.9")).to be_truthy
- expect(init_version("1.1.9") > init_version("1.1.8.9")).to be_truthy
+ it '#>' do
+ expect(Version.new("1.1.1")).to be > Version.new("1.1")
+ expect(Version.new("1.2")).to be > Version.new("1.1.9")
+ expect(Version.new("2.0")).to be > Version.new("1.9")
+ expect(Version.new("1.1.9")).to be > Version.new("1.1.8.9")
end
- it 'tests less than' do
- expect(init_version("0.1") < init_version("1")).to be_truthy
- expect(init_version("0.0.1") < init_version("0.1")).to be_truthy
- expect(init_version("3") < init_version("3.0.0.0.1")).to be_truthy
- expect(init_version("5") < init_version("5.5.5")).to be_truthy
+ it '#<' do
+ expect(Version.new("0.1")).to be < Version.new("1")
+ expect(Version.new("0.0.1")).to be < Version.new("0.1")
+ expect(Version.new("3")).to be < Version.new("3.0.0.0.1")
+ expect(Version.new("5")).to be < Version.new("5.5.5")
end
- it 'tests less than or equal' do
- expect(init_version("0.1") <= init_version("1")).to be_truthy
- expect(init_version("0.0.1") <= init_version("0.1")).to be_truthy
- expect(init_version("3") <= init_version("3.0.0.0.1")).to be_truthy
- expect(init_version("1.0") <= init_version("1")).to be_truthy
+ it '#<=' do
+ expect(Version.new("0.1")).to be <= Version.new("1")
+ expect(Version.new("0.0.1")).to be <= Version.new("0.1")
+ expect(Version.new("3")).to be <= Version.new("3.0.0.0.1")
+ expect(Version.new("1.0")).to be <= Version.new("1")
end
- it 'tests bigger than or equal' do
- expect(init_version("1.1.1") >= init_version("1.1")).to be_truthy
- expect(init_version("1.2") >= init_version("1.1.9")).to be_truthy
- expect(init_version("2.0") >= init_version("1.9")).to be_truthy
- expect(init_version("1.1.9") >= init_version("1.1.8.9")).to be_truthy
- expect(init_version("1.0") >= init_version("1")).to be_truthy
+ it '#>=' do
+ expect(Version.new("1.1.1")).to be >= Version.new("1.1")
+ expect(Version.new("1.2")).to be >= Version.new("1.1.9")
+ expect(Version.new("2.0")).to be >= Version.new("1.9")
+ expect(Version.new("1.1.9")).to be >= Version.new("1.1.8.9")
+ expect(Version.new("1.0")).to be >= Version.new("1")
end
- it 'tests equal' do
- expect(init_version("1.1.0") == init_version("1.1")).to be_truthy
- expect(init_version("2.0") == init_version("2")).to be_truthy
+ it '#==' do
+ expect(Version.new("1.1.0")).to be == Version.new("1.1")
+ expect(Version.new("2.0")).to be == Version.new("2")
+ expect(Version.new("2.0.0.0.0.0")).to be == Version.new("2")
end
- it 'tests less, equal or bigger than' do
- expect(init_version("1.0.1") <=> init_version("1.1")).to equal -1
- expect(init_version("1.2") <=> init_version("1.1.9")).to equal 1
- expect(init_version("2.0") <=> init_version("2")).to equal 0
+ it '#<=>' do
+ expect(Version.new("1.0.1") <=> Version.new("1.1")).to equal -1
+ expect(Version.new("1.2") <=> Version.new("1.1.9")).to equal 1
+ expect(Version.new("2.0") <=> Version.new("2")).to equal 0
end
end
context '#to_s' do
- it 'test for basic versions' do
- expect(init_version("1.1").to_s).to eql "1.1"
- expect(init_version("1").to_s).to eql "1"
- expect(init_version("0").to_s).to eql ""
- expect(init_version("1.1.1.1.1").to_s).to eql "1.1.1.1.1"
+ it 'basic versions' do
+ expect(Version.new("1.1").to_s).to eq "1.1"
+ expect(Version.new("1").to_s).to eq "1"
+ expect(Version.new("0").to_s).to eq ""
+ expect(Version.new("1.1.1.1.1").to_s).to eq "1.1.1.1.1"
end
- it 'test for complex versions' do
- expect(init_version("1.1.0").to_s).to eql "1.1"
- expect(init_version("1.0.0").to_s).to eql "1"
- expect(init_version("0.0").to_s).to eql ""
- expect(init_version("1.1.1.1.1.0.0.0.0.0.0.0.0.0.0.0").to_s)
- .to eql "1.1.1.1.1"
+ it 'complex versions' do
+ expect(Version.new("1.1.0").to_s).to eq "1.1"
+ expect(Version.new("1.0.0").to_s).to eq "1"
+ expect(Version.new("0.0").to_s).to eq ""
+ expect(Version.new("1.1.1.1.1.0.0.0.0.0.0.0.0.0.0.0").to_s)
+ .to eq "1.1.1.1.1"
end
end
context '#components' do
- def compose(args)
- if args.length == 1
- Version.new(args[0]).components
- else
- Version.new(args[0]).components(args[1])
- end
- end
-
- it 'test basic versions' do
- expect(compose(["1.1"])).to eq [1, 1]
- expect(compose(["2"])).to eq [2]
- expect(compose(["2.2"])).to eq [2, 2]
- expect(compose(["1.2.3.4.5.6.7.8.9"]))
+ it 'basic versions' do
+ expect(Version.new("1.1").components).to eq [1, 1]
+ expect(Version.new("2").components).to eq [2]
+ expect(Version.new("2.2").components).to eq [2, 2]
+ expect(Version.new("1.2.3.4.5.6.7.8.9").components)
.to eq [1, 2, 3, 4, 5, 6, 7, 8, 9]
end
- it 'test zero ending versions' do
- expect(compose(["1.1.0"])).to eq [1, 1]
- expect(compose(["2.0.0.0.0.0.0"])).to eq [2]
- expect(compose(["2.0.2.0"])).to eq [2, 0, 2]
+ it 'zero ending versions' do
+ expect(Version.new("1.1.0").components).to eq [1, 1]
+ expect(Version.new("2.0.0.0.0.0.0").components).to eq [2]
+ expect(Version.new("2.0.2.0").components).to eq [2, 0, 2]
end
- it 'tests #components with a given count' do
- expect(compose(["1.1.0", 1])).to eq [1]
- expect(compose(["1.2.3.4.5.6.7.8", 4])).to match_array [1, 2, 3, 4]
- expect(compose(["1.2.3.4.5.6.7.8", 7]))
+ it '#components with a given count' do
+ expect(Version.new("1.1.0").components(1)).to eq [1]
+ expect(Version.new("1.2.3.4.5.6.7.8").components(4))
+ .to match_array [1, 2, 3, 4]
+ expect(Version.new("1.2.3.4.5.6.7.8").components(7))
.to match_array [1, 2, 3, 4, 5, 6, 7]
- expect(compose(["1.2.3.4.5.6.7.8", 10]))
+ expect(Version.new("1.2.3.4.5.6.7.8").components(10))
.to match_array [1, 2, 3, 4, 5, 6, 7, 8, 0, 0]
- expect(compose(["1.2", 5])).to match_array [1, 2, 0, 0, 0]
+ expect(Version.new("1.2").components(5)).to match_array [1, 2, 0, 0, 0]
end
end
end
describe 'Range' do
- def init_range(start_version, end_version)
- Range.new(start_version, end_version)
- end
context 'initialization' do
it 'creates an instance of Range' do
- expect(init_range(Version.new("1"), "1.9")).to be_a Range
- expect(init_range("1.1", "1.9")).to be_a Range
- expect(init_range(Version.new("1"), Version.new("1.9"))).to be_a Range
+ expect(Range.new(Version.new("1"), "1.9")).to be_a Range
+ expect(Range.new("1.1", "1.9")).to be_a Range
+ expect(Range.new(Version.new("1"), Version.new("1.9"))).to be_a Range
end
end
context '#include?' do
- it 'checks if passed version is bigger or equal to the starting
- and less than the ending version' do
- expect(init_range("1.1", "1.4").include?("1.3")).to be_truthy
- expect(init_range("1.1", "1.4").include?("1.4")).to be_falsy
- expect(init_range("1", "2").include?(Version.new("1.5"))).to be_truthy
- expect(init_range("1", "2").include?("1.5")).to be_truthy
- expect(init_range("1", "1.1.1").include?("1.1")).to be_truthy
- expect(init_range("1", "1.1.1").include?("1.1.1")).to be_falsy
- expect(init_range("2.12", "2.42").include?("2.15")).to be_truthy
+ it 'checks if argument is >= starting and < ending version' do
+ expect(Range.new("1.1", "1.4").include?("1.3")).to be_truthy
+ expect(Range.new("1.1", "1.4").include?("1.4")).to be_falsy
+ expect(Range.new("1", "2").include?(Version.new("1.5"))).to be_truthy
+ expect(Range.new("1", "2").include?("1.5")).to be_truthy
+ expect(Range.new("1", "1.1.1").include?("1.1")).to be_truthy
+ expect(Range.new("1", "1.1.1").include?("1.1.1")).to be_falsy
+ expect(Range.new("2.12", "2.42").include?("2.15")).to be_truthy
end
end
context '#to_a' do
- it 'tests if versions are included in the array' do
- expect(init_range("1.1", "1.2").to_a).to match_array [
+ it 'checls if version are included in an array' do
+ expect(Range.new("1.1", "1.2").to_a).to match_array [
'1.1', '1.1.1', '1.1.2', '1.1.3', '1.1.4', '1.1.5',
'1.1.6', '1.1.7', '1.1.8', '1.1.9'
]
- expect(init_range("1.1.1", "1.1.5").to_a).to match_array [
+ expect(Range.new("1.1.1", "1.1.5").to_a).to match_array [
'1.1.1', '1.1.2', '1.1.3', '1.1.4'
]
- expect(init_range("1.9.9", "2.0.2").to_a).to match_array [
+ expect(Range.new("1.9.9", "2.0.2").to_a).to match_array [
"1.9.9", "2", "2.0.1"
]
- expect(init_range("1.1.0", "1.2.2").to_a).to match_array [
+ expect(Range.new("1.1.0", "1.2.2").to_a).to match_array [
'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
end
end
end