Решение на Трета задача от Любомир Петков

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

Към профила на Любомир Петков

Резултати

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

Код

module RBFS
class File
attr_accessor :data
def initialize(data = nil)
@data = data
end
def data_type
case @data
when nil then :nil
when String then :string
when Symbol then :symbol
when Integer, Float then :number
when TrueClass, FalseClass then :boolean
end
end
def serialize
"#{data_type}:#{data}"
end
def File.parse(string_data)
data_type, data = string_data.split(":")
case data_type
when "nil" then File.new
when "string" then File.new(data)
when "symbol" then File.new(:"#{data}")
when "number" then create_file_object_with_int_or_float_data_value(data)
when "boolean" then create_file_object_with_data_value_true_or_false(data)
end
end
def File.create_file_object_with_int_or_float_data_value(data)
(data.include? ".") ? File.new(data.to_f) : File.new(data.to_i)
end
def File.create_file_object_with_data_value_true_or_false(data)
data == "true" ? File.new(true) : File.new(false)
end
end
class Directory
def initialize(files = {}, directories = {})
@files = files
@directories = directories
end
def add_file(name, file)
@files[name] = file
end
def add_directory(name, directory = nil)
@directories[name] = directory ? directory : Directory.new
end
def [](name)
directories[name] ? directories[name] : files[name]
end
def serialize
end
def Directory.parse(string_data)
end
def files
@files
end
def directories
@directories
end
end
end

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

....F...FFFFFF..............F...............

Failures:

  1) RBFS Directory without files can be serialized
     Failure/Error: expect(directory.serialize).to eq '0:0:'
       
       expected: "0:0:"
            got: nil
       
       (compared using ==)
     # /tmp/d20141111-26053-1ncu71a/spec.rb:11:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) RBFS Directory serialization #serialize can serialize
     Failure/Error: expect(directory.serialize).to eq simple_serialized_string
       
       expected: "2:README:19:string:Hello world!spec.rb:20:string:describe RBFS1:rbfs:4:0:0:"
            got: nil
       
       (compared using ==)
     # /tmp/d20141111-26053-1ncu71a/spec.rb:81:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) RBFS Directory serialization #serialize can serialize multiple directories recursively
     Failure/Error: expect(directory.serialize).to eq recursive_serialized_string
       
       expected: "2:README:19:string:Hello world!spec.rb:20:string:describe RBFS2:rbfs:64:1:solution.rb:13:symbol:hidden1:spec:24:1:test:12:boolean:true0:sample:4:0:0:"
            got: nil
       
       (compared using ==)
     # /tmp/d20141111-26053-1ncu71a/spec.rb:95:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) RBFS Directory serialization ::parse can parse empty directories
     Failure/Error: expect(parsed_directory.files      ).to eq({})
     NoMethodError:
       undefined method `files' for nil:NilClass
     # /tmp/d20141111-26053-1ncu71a/spec.rb:103:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) RBFS Directory serialization ::parse can parse directories with files
     Failure/Error: expect(parsed_directory.files.size     ).to eq    2
     NoMethodError:
       undefined method `files' for nil:NilClass
     # /tmp/d20141111-26053-1ncu71a/spec.rb:110:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) RBFS Directory serialization ::parse can parse directory trees without files
     Failure/Error: expect(parsed_directory['dir1']        ).to be_an RBFS::Directory
     NoMethodError:
       undefined method `[]' for nil:NilClass
     # /tmp/d20141111-26053-1ncu71a/spec.rb:119:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) RBFS Directory serialization ::parse can parse directories recursively
     Failure/Error: expect(parsed_directory.files.size     ).to eq 2
     NoMethodError:
       undefined method `files' for nil:NilClass
     # /tmp/d20141111-26053-1ncu71a/spec.rb:127:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) RBFS File data type string can parse a string with colons
     Failure/Error: expect(file.data     ).to eq 'Hay :)'
       
       expected: "Hay :)"
            got: "Hay "
       
       (compared using ==)
     # /tmp/d20141111-26053-1ncu71a/spec.rb:257:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.04167 seconds
44 examples, 8 failures

Failed examples:

rspec /tmp/d20141111-26053-1ncu71a/spec.rb:10 # RBFS Directory without files can be serialized
rspec /tmp/d20141111-26053-1ncu71a/spec.rb:76 # RBFS Directory serialization #serialize can serialize
rspec /tmp/d20141111-26053-1ncu71a/spec.rb:84 # RBFS Directory serialization #serialize can serialize multiple directories recursively
rspec /tmp/d20141111-26053-1ncu71a/spec.rb:100 # RBFS Directory serialization ::parse can parse empty directories
rspec /tmp/d20141111-26053-1ncu71a/spec.rb:107 # RBFS Directory serialization ::parse can parse directories with files
rspec /tmp/d20141111-26053-1ncu71a/spec.rb:116 # RBFS Directory serialization ::parse can parse directory trees without files
rspec /tmp/d20141111-26053-1ncu71a/spec.rb:124 # RBFS Directory serialization ::parse can parse directories recursively
rspec /tmp/d20141111-26053-1ncu71a/spec.rb:254 # RBFS File data type string can parse a string with colons

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

Любомир обнови решението на 07.11.2014 18:35 (преди около 10 години)

+module RBFS
+
+ class File
+
+ attr_accessor :data
+
+ def initialize(data = nil)
+ @data = data
+ end
+
+ def data_type
+ case @data
+ when nil then :nil
+ when String then :string
+ when Symbol then :symbol
+ when Integer, Float then :number
+ when TrueClass, FalseClass then :boolean
+ end
+ end
+
+ def serialize
+ end
+
+ def File.parse(string_data)
+ end
+ end
+
+ class Directory
+
+ def initialize(files = {}, directories = {})
+ @files = files
+ @directories = directories
+ end
+
+ def add_file(name, file)
+ @files[name] = file
+ end
+
+ def add_directory(name, directory = nil)
+ @directories[name] = directory ? directory : Directory.new
+ end
+
+ def [](name)
+ directories[name] ? directories[name] : files[name]
+ end
+
+ def serialize
+ end
+
+ def Directory.parse(string_data)
+ end
+
+ def files
+ @files
+ end
+
+ def directories
+ @directories
+ end
+ end
+end

Любомир обнови решението на 09.11.2014 01:46 (преди около 10 години)

module RBFS
- class File
+class File
- attr_accessor :data
+ attr_accessor :data
- def initialize(data = nil)
- @data = data
- end
+ def initialize(data = nil)
+ @data = data
+ end
- def data_type
- case @data
- when nil then :nil
- when String then :string
- when Symbol then :symbol
- when Integer, Float then :number
- when TrueClass, FalseClass then :boolean
- end
+ def data_type
+ case @data
+ when nil then :nil
+ when String then :string
+ when Symbol then :symbol
+ when Integer, Float then :number
+ when TrueClass, FalseClass then :boolean
end
+ end
- def serialize
- end
+ def serialize
+ "#{data_type}:#{data}"
+ end
- def File.parse(string_data)
+ def File.parse(string_data)
+ data_type, data = string_data.split(":")
+ case data_type
+ when "nil" then File.new
+ when "string" then File.new(data)
+ when "symbol" then File.new(:"#{data}")
+ when "number" then create_file_object_with_int_or_float_data(data)
+ when "boolean" then create_file_object_with_data_values_true_or_false(data)
end
end
- class Directory
+ def File.create_file_object_with_int_or_float_data(data)
+ (data.include? ".") ? File.new(data.to_f) : File.new(data.to_i)
+ end
- def initialize(files = {}, directories = {})
- @files = files
- @directories = directories
- end
+ def File.create_file_object_with_data_values_true_or_false(data)
+ data == "true" ? File.new(true) : File.new(false)
+ end
+end
- def add_file(name, file)
- @files[name] = file
- end
+class Directory
- def add_directory(name, directory = nil)
- @directories[name] = directory ? directory : Directory.new
- end
+ def initialize(files = {}, directories = {})
+ @files = files
+ @directories = directories
+ end
- def [](name)
- directories[name] ? directories[name] : files[name]
- end
+ def add_file(name, file)
+ @files[name] = file
+ end
- def serialize
- end
+ def add_directory(name, directory = nil)
+ @directories[name] = directory ? directory : Directory.new
+ end
- def Directory.parse(string_data)
- end
+ def [](name)
+ directories[name] ? directories[name] : files[name]
+ end
- def files
- @files
- end
+ def serialize
+ end
- def directories
- @directories
- end
+ def Directory.parse(string_data)
end
+
+ def files
+ @files
+ end
+
+ def directories
+ @directories
+ end
+end
end

Любомир обнови решението на 09.11.2014 01:52 (преди около 10 години)

module RBFS
class File
attr_accessor :data
def initialize(data = nil)
@data = data
end
def data_type
case @data
when nil then :nil
when String then :string
when Symbol then :symbol
when Integer, Float then :number
when TrueClass, FalseClass then :boolean
end
end
def serialize
"#{data_type}:#{data}"
end
def File.parse(string_data)
data_type, data = string_data.split(":")
case data_type
when "nil" then File.new
when "string" then File.new(data)
when "symbol" then File.new(:"#{data}")
when "number" then create_file_object_with_int_or_float_data(data)
when "boolean" then create_file_object_with_data_values_true_or_false(data)
end
end
- def File.create_file_object_with_int_or_float_data(data)
+ def File.create_file_object_with_int_or_float_data_value(data)
(data.include? ".") ? File.new(data.to_f) : File.new(data.to_i)
end
def File.create_file_object_with_data_values_true_or_false(data)
data == "true" ? File.new(true) : File.new(false)
end
end
class Directory
def initialize(files = {}, directories = {})
@files = files
@directories = directories
end
def add_file(name, file)
@files[name] = file
end
def add_directory(name, directory = nil)
@directories[name] = directory ? directory : Directory.new
end
def [](name)
directories[name] ? directories[name] : files[name]
end
def serialize
end
def Directory.parse(string_data)
end
def files
@files
end
def directories
@directories
end
end
end

Любомир обнови решението на 09.11.2014 01:56 (преди около 10 години)

module RBFS
class File
attr_accessor :data
def initialize(data = nil)
@data = data
end
def data_type
case @data
when nil then :nil
when String then :string
when Symbol then :symbol
when Integer, Float then :number
when TrueClass, FalseClass then :boolean
end
end
def serialize
"#{data_type}:#{data}"
end
def File.parse(string_data)
data_type, data = string_data.split(":")
case data_type
when "nil" then File.new
when "string" then File.new(data)
when "symbol" then File.new(:"#{data}")
- when "number" then create_file_object_with_int_or_float_data(data)
+ when "number" then create_file_object_with_int_or_float_data_value(data)
when "boolean" then create_file_object_with_data_values_true_or_false(data)
end
end
def File.create_file_object_with_int_or_float_data_value(data)
(data.include? ".") ? File.new(data.to_f) : File.new(data.to_i)
end
def File.create_file_object_with_data_values_true_or_false(data)
data == "true" ? File.new(true) : File.new(false)
end
end
class Directory
def initialize(files = {}, directories = {})
@files = files
@directories = directories
end
def add_file(name, file)
@files[name] = file
end
def add_directory(name, directory = nil)
@directories[name] = directory ? directory : Directory.new
end
def [](name)
directories[name] ? directories[name] : files[name]
end
def serialize
end
def Directory.parse(string_data)
end
def files
@files
end
def directories
@directories
end
end
end

Любомир обнови решението на 09.11.2014 01:59 (преди около 10 години)

module RBFS
class File
attr_accessor :data
def initialize(data = nil)
@data = data
end
def data_type
case @data
when nil then :nil
when String then :string
when Symbol then :symbol
when Integer, Float then :number
when TrueClass, FalseClass then :boolean
end
end
def serialize
"#{data_type}:#{data}"
end
def File.parse(string_data)
data_type, data = string_data.split(":")
case data_type
when "nil" then File.new
when "string" then File.new(data)
when "symbol" then File.new(:"#{data}")
when "number" then create_file_object_with_int_or_float_data_value(data)
- when "boolean" then create_file_object_with_data_values_true_or_false(data)
+ when "boolean" then create_file_object_with_data_value_true_or_false(data)
end
end
def File.create_file_object_with_int_or_float_data_value(data)
(data.include? ".") ? File.new(data.to_f) : File.new(data.to_i)
end
- def File.create_file_object_with_data_values_true_or_false(data)
+ def File.create_file_object_with_data_value_true_or_false(data)
data == "true" ? File.new(true) : File.new(false)
end
end
class Directory
def initialize(files = {}, directories = {})
@files = files
@directories = directories
end
def add_file(name, file)
@files[name] = file
end
def add_directory(name, directory = nil)
@directories[name] = directory ? directory : Directory.new
end
def [](name)
directories[name] ? directories[name] : files[name]
end
def serialize
end
def Directory.parse(string_data)
end
def files
@files
end
def directories
@directories
end
end
end