Делян обнови решението на 18.11.2016 23:00 (преди над 8 години)
+RSpec.describe 'Version' do
+
+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 comparing Versions when a version is constructed from another Version object is equal to the one it is constructed from Failure/Error: eq_version_1 = Vesion.new("5.4.7") NameError: uninitialized constant Vesion # ./solution_spec.rb:29:in `block (4 levels) in <top (required)>' 2) Version comparing Versions when a version is logically equal to another is equal to the other version Failure/Error: eq_version_1 = Vesion.new("5.4.0") NameError: uninitialized constant Vesion # ./solution_spec.rb:36:in `block (4 levels) in <top (required)>' Finished in 0.00966 seconds 10 examples, 2 failures Failed examples: rspec ./solution_spec.rb:28 # Version comparing Versions when a version is constructed from another Version object is equal to the one it is constructed from rspec ./solution_spec.rb:35 # Version comparing Versions when a version is logically equal to another is equal to the other version # /tmp/d20161119-19072-1kq66q4/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.73189 seconds 1 example, 1 failure Failed examples: rspec /tmp/d20161119-19072-1kq66q4/spec.rb:179 # spec passes for the correct solution