Решение на Трета задача от Йоан Динков

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

Към профила на Йоан Динков

Резултати

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

Код

module RBFS
class File
def data_type
case @data
when NilClass then :nil
when Symbol then :symbol
when TrueClass, FalseClass then :boolean
when String then :string
else :number
end
end
def data
@data
end
def data=(value)
@data = value
end
def initialize(input)
@data = input
end
def serialize
"#{self.data_type}:#{@data.to_s}"
end
def self.get_value(type, value)
case type
when :nil then nil
when :string then value
when :boolean then value == 'true'
when :symbol then value.to_sym
end
if (type == :number && (value.to_f == value.to_i))
value.to_f
else
value.to_i
end
end
def self.parse(string_data)
type = string_data.split(':')[0].to_sym
value = string_data.split(':')[1]
new_file_value = self.get_value(type, value)
File.new(new_file_value)
end
end
class Directory
def initialize
@children = {}
end
def files
@children.reject {|key, value| value.is_a?(Directory)}
end
def directories
@children.reject {|key, value| value.is_a?(File)}
end
def add_file(name, file)
@children[name] = file unless name.include? ':'
end
def add_directory(name, directory)
directory = Directory.new if directory.nil?
@children[name] = directory unless name.include? ':'
end
def [](name)
if (self.directories[name].is_nil?)
self.files[name]
else
self.directories[name]
end
end
def serialize
str = '' << self.files.count.to_s << ":"
self.files.each {|name, file|
str << "#{name}:#{file.serialize.length}:#{file.serialize}:"}
str = str.chomp(':') unless self.files.count == 0
str << self.directories.count.to_s << ":"
self.directories.each { |name, directory|
str << "#{name}:#{directory.serialize.length}:#{directory.serialize}" }
str
end
def self.parse(string)
end
end
end

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

.F......FFFFFFFFFFFFF.FFFFFFFFFFFFFFFFFFFFFF

Failures:

  1) RBFS Directory can create empty directory
     Failure/Error: directory.add_directory 'home'
     ArgumentError:
       wrong number of arguments (1 for 2)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:70:in `add_directory'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:150:in `block (3 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: directory.add_directory 'rbfs'
     ArgumentError:
       wrong number of arguments (1 for 2)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:70:in `add_directory'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:79: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: directory.add_directory 'rbfs'
     ArgumentError:
       wrong number of arguments (1 for 2)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:70:in `add_directory'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:88: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-1q96z6o/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-1q96z6o/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-1q96z6o/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-1q96z6o/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 Directory #[] can walk a single directory
     Failure/Error: expect(directory['home']).to eq home
     NoMethodError:
       undefined method `is_nil?' for #<RBFS::Directory:0xba536d98>
     # /tmp/d20141111-26053-1q96z6o/solution.rb:76:in `[]'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:178: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)>'

  9) RBFS Directory #[] can walk multiple directories
     Failure/Error: expect(directory['home']['user']['ruby']).to eq ruby
     NoMethodError:
       undefined method `is_nil?' for #<RBFS::Directory:0xba535e48>
     # /tmp/d20141111-26053-1q96z6o/solution.rb:76:in `[]'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:182: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)>'

  10) RBFS Directory #[] can get files
     Failure/Error: expect(directory['home']['user']['ruby']['file']).to eq file
     NoMethodError:
       undefined method `is_nil?' for #<RBFS::Directory:0xba534cf0>
     # /tmp/d20141111-26053-1q96z6o/solution.rb:76:in `[]'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:186: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)>'

  11) RBFS Directory #[] returns nil if directory or file doesnt exist
     Failure/Error: expect(directory['home']['another_user']).to be_nil
     NoMethodError:
       undefined method `is_nil?' for #<RBFS::Directory:0xba533ef4>
     # /tmp/d20141111-26053-1q96z6o/solution.rb:76:in `[]'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:190: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)>'

  12) RBFS Directory #[] is case-sensitive
     Failure/Error: expect(directory['HOME']).to be_nil
     NoMethodError:
       undefined method `is_nil?' for nil:NilClass
     # /tmp/d20141111-26053-1q96z6o/solution.rb:76:in `[]'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:194: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)>'

  13) RBFS File has nil as initial data
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:203:in `block (3 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)>'

  14) RBFS File can store data
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:207:in `block (3 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)>'

  15) RBFS File data type nil can be detected
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:219: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)>'

  16) RBFS File data type nil can be serialized
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:219: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)>'

  17) RBFS File data type nil can be parsed
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:219: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)>'

  18) RBFS File data type string can be detected
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:237: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)>'

  19) RBFS File data type string can be serialized
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:237: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)>'

  20) RBFS File data type string can be parsed
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:237: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)>'

  21) RBFS File data type string can parse a string with colons
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:237: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)>'

  22) RBFS File data type symbol can be detected
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:263: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)>'

  23) RBFS File data type symbol can be serialized
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:263: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)>'

  24) RBFS File data type symbol can be parsed
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:263: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)>'

  25) RBFS File data type number can be detected
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:282: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)>'

  26) RBFS File data type number can be serialized
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:282: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)>'

  27) RBFS File data type number can be parsed
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:282: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)>'

  28) RBFS File data type float number can be detected
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:301: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)>'

  29) RBFS File data type float number can be serialized
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:301: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)>'

  30) RBFS File data type float number can be parsed
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:301: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)>'

  31) RBFS File data type boolean true can be detected
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:322:in `block (6 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)>'

  32) RBFS File data type boolean true can be serialized
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:327:in `block (6 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)>'

  33) RBFS File data type boolean true can be parsed
     Failure/Error: expect(file.data     ).to eq true
       
       expected: true
            got: 0
       
       (compared using ==)
     # /tmp/d20141111-26053-1q96z6o/spec.rb:334:in `block (6 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)>'

  34) RBFS File data type boolean false can be detected
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:341:in `block (6 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)>'

  35) RBFS File data type boolean false can be serialized
     Failure/Error: subject(:file) { RBFS::File.new }
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-1q96z6o/solution.rb:22:in `initialize'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `new'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:200:in `block (3 levels) in <top (required)>'
     # /tmp/d20141111-26053-1q96z6o/spec.rb:346:in `block (6 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)>'

  36) RBFS File data type boolean false can be parsed
     Failure/Error: expect(file.data     ).to eq false
       
       expected: false
            got: 0
       
       (compared using ==)
     # /tmp/d20141111-26053-1q96z6o/spec.rb:353:in `block (6 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.04242 seconds
44 examples, 36 failures

Failed examples:

rspec /tmp/d20141111-26053-1q96z6o/spec.rb:149 # RBFS Directory can create empty directory
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:76 # RBFS Directory serialization #serialize can serialize
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:84 # RBFS Directory serialization #serialize can serialize multiple directories recursively
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:100 # RBFS Directory serialization ::parse can parse empty directories
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:107 # RBFS Directory serialization ::parse can parse directories with files
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:116 # RBFS Directory serialization ::parse can parse directory trees without files
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:124 # RBFS Directory serialization ::parse can parse directories recursively
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:177 # RBFS Directory #[] can walk a single directory
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:181 # RBFS Directory #[] can walk multiple directories
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:185 # RBFS Directory #[] can get files
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:189 # RBFS Directory #[] returns nil if directory or file doesnt exist
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:193 # RBFS Directory #[] is case-sensitive
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:202 # RBFS File has nil as initial data
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:206 # RBFS File can store data
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:221 # RBFS File data type nil can be detected
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:225 # RBFS File data type nil can be serialized
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:229 # RBFS File data type nil can be parsed
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:239 # RBFS File data type string can be detected
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:243 # RBFS File data type string can be serialized
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:247 # RBFS File data type string can be parsed
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:254 # RBFS File data type string can parse a string with colons
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:265 # RBFS File data type symbol can be detected
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:269 # RBFS File data type symbol can be serialized
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:273 # RBFS File data type symbol can be parsed
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:284 # RBFS File data type number can be detected
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:288 # RBFS File data type number can be serialized
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:292 # RBFS File data type number can be parsed
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:303 # RBFS File data type float number can be detected
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:307 # RBFS File data type float number can be serialized
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:311 # RBFS File data type float number can be parsed
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:321 # RBFS File data type boolean true can be detected
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:326 # RBFS File data type boolean true can be serialized
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:331 # RBFS File data type boolean true can be parsed
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:340 # RBFS File data type boolean false can be detected
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:345 # RBFS File data type boolean false can be serialized
rspec /tmp/d20141111-26053-1q96z6o/spec.rb:350 # RBFS File data type boolean false can be parsed

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

Йоан обнови решението на 10.11.2014 00:31 (преди почти 10 години)

+module RBFS
+ class File
+
+ def data_type
+ case @data
+ when NilClass then :nil
+ when Symbol then :symbol
+ when TrueClass, FalseClass then :boolean
+ when String then :string
+ else :number
+ end
+ end
+
+ def data
+ @data
+ end
+
+ def data=(value)
+ @data = value
+ end
+
+ def initialize(input)
+ @data = input
+ end
+
+ def serialize
+ "#{self.data_type}:#{@data.to_s}"
+ end
+
+ def self.get_value(type, value)
+ case type
+ when :nil then nil
+ when :string then value
+ when :boolean then value == 'true'
+ when :symbol then value.to_sym
+ end
+
+ if (type == :number && (value.to_f == value.to_i))
+ value.to_f
+ else
+ value.to_i
+ end
+ end
+
+ def self.parse(string_data)
+ type = string_data.split(':')[0].to_sym
+ value = string_data.split(':')[1]
+ new_file_value = self.get_value(type, value)
+ File.new(new_file_value)
+ end
+ end
+
+ class Directory
+ def initialize
+ @children = {}
+ end
+
+ def files
+ @children.reject {|key, value| value.is_a?(Directory)}
+ end
+
+ def directories
+ @children.reject {|key, value| value.is_a?(File)}
+ end
+
+ def add_file(name, file)
+ @children[name] = file unless name.include? ':'
+ end
+
+ def add_directory(name, directory)
+ directory = Directory.new if directory.nil?
+ @children[name] = directory unless name.include? ':'
+ end
+
+ def [](name)
+ if (self.directories[name].is_nil?)
+ self.files[name]
+ else
+ self.directories[name]
+ end
+ end
+
+ def serialize
+ str = '' << self.files.count.to_s << ":"
+ self.files.each {|name, file|
+ str << "#{name}:#{file.serialize.length}:#{file.serialize}:"}
+ str = str.chomp(':') unless self.files.count == 0
+ str << self.directories.count.to_s << ":"
+ self.directories.each { |name, directory|
+ str << "#{name}:#{directory.serialize.length}:#{directory.serialize}" }
+ str
+ end
+
+ def self.parse(string)
+ end
+ end
+end
+f = RBFS::File.new(42)
+
+dir2 = RBFS::Directory.new()
+dir2.add_file("README", f)
+
+dir1 = RBFS::Directory.new()
+dir1.add_directory("directory2", dir2)
+
+dir0 = RBFS::Directory.new()
+dir0.add_directory("directory1", dir1)
+puts(dir0.serialize)
+
+file1 = RBFS::File.new("Hello world!")
+file2 = RBFS::File.new("describe RBFS")
+dir1 = RBFS::Directory.new()
+
+dir = RBFS::Directory.new()
+dir.add_file("README", file1)
+dir.add_file("spec.rb", file2)
+dir.add_directory("RBFS", dir1)
+puts(dir.serialize())

Йоан обнови решението на 10.11.2014 00:31 (преди почти 10 години)

module RBFS
class File
def data_type
case @data
when NilClass then :nil
when Symbol then :symbol
when TrueClass, FalseClass then :boolean
when String then :string
else :number
end
end
def data
@data
end
def data=(value)
@data = value
end
def initialize(input)
@data = input
end
def serialize
"#{self.data_type}:#{@data.to_s}"
end
def self.get_value(type, value)
case type
when :nil then nil
when :string then value
when :boolean then value == 'true'
when :symbol then value.to_sym
end
if (type == :number && (value.to_f == value.to_i))
value.to_f
else
value.to_i
end
end
def self.parse(string_data)
type = string_data.split(':')[0].to_sym
value = string_data.split(':')[1]
new_file_value = self.get_value(type, value)
File.new(new_file_value)
end
end
class Directory
def initialize
@children = {}
end
def files
@children.reject {|key, value| value.is_a?(Directory)}
end
def directories
@children.reject {|key, value| value.is_a?(File)}
end
def add_file(name, file)
@children[name] = file unless name.include? ':'
end
def add_directory(name, directory)
directory = Directory.new if directory.nil?
@children[name] = directory unless name.include? ':'
end
def [](name)
if (self.directories[name].is_nil?)
self.files[name]
else
self.directories[name]
end
end
def serialize
str = '' << self.files.count.to_s << ":"
self.files.each {|name, file|
str << "#{name}:#{file.serialize.length}:#{file.serialize}:"}
str = str.chomp(':') unless self.files.count == 0
str << self.directories.count.to_s << ":"
self.directories.each { |name, directory|
str << "#{name}:#{directory.serialize.length}:#{directory.serialize}" }
str
end
def self.parse(string)
end
end
-end
-f = RBFS::File.new(42)
+end
-
-dir2 = RBFS::Directory.new()
-dir2.add_file("README", f)
-
-dir1 = RBFS::Directory.new()
-dir1.add_directory("directory2", dir2)
-
-dir0 = RBFS::Directory.new()
-dir0.add_directory("directory1", dir1)
-puts(dir0.serialize)
-
-file1 = RBFS::File.new("Hello world!")
-file2 = RBFS::File.new("describe RBFS")
-dir1 = RBFS::Directory.new()
-
-dir = RBFS::Directory.new()
-dir.add_file("README", file1)
-dir.add_file("spec.rb", file2)
-dir.add_directory("RBFS", dir1)
-puts(dir.serialize())