Решение на Четвърта задача - Unit тестване от Мартин Христов
Обратно към всички решения
Към профила на Мартин Христов
Резултати
- 0 точки от тестове
- 0 бонус точки
- 0 точки общо
- 0 успешни тест(а)
- 1 неуспешни тест(а)
Код
Лог от изпълнението
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 (преди над 8 години)
Мартин обнови решението на 17.11.2016 14:37 (преди над 8 години)