Решение на Четвърта задача - Unit тестване от Радослав Гайдаров
Обратно към всички решения
Към профила на Радослав Гайдаров
Резултати
- 4 точки от тестове
- 0 бонус точки
- 4 точки общо
- 14 успешни тест(а)
- 5 неуспешни тест(а)
Код
Лог от изпълнението
......F.F.F.F...F..
Failures:
1) 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-1h1m31g/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)>'
2) spec Version tests #components with less components than present
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
[42, 42, 42, 42, 42]
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-1h1m31g/spec.rb:420: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-1h1m31g/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 constructing ranges with strings
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 = start_version
@end_version = 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-1h1m31g/spec.rb:479: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-1h1m31g/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.87 seconds
19 examples, 5 failures
Failed examples:
rspec /tmp/d20161119-19072-1h1m31g/spec.rb:353 # spec Version checks for comparison operators negatively
rspec /tmp/d20161119-19072-1h1m31g/spec.rb:405 # spec Version tests #components with less components than present
rspec /tmp/d20161119-19072-1h1m31g/spec.rb:441 # spec Version tests that #components cannot be used to modify the version
rspec /tmp/d20161119-19072-1h1m31g/spec.rb:471 # spec Version::Range tests constructing ranges with strings
rspec /tmp/d20161119-19072-1h1m31g/spec.rb:515 # spec Version::Range tests include? with versions lower than the start one
История (1 версия и 0 коментара)
Радослав обнови решението на 18.11.2016 22:38 (преди над 8 години)