Решение на Трета задача от Николина Гюрова

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

Към профила на Николина Гюрова

Резултати

  • 4 точки от тестове
  • 0 бонус точки
  • 4 точки общо
  • 32 успешни тест(а)
  • 12 неуспешни тест(а)

Код

module RBFS
TYPES = {
"TrueClass" => :boolean,
"FalseClass" => :boolean,
"NilClass" => :nil,
"Fixnum" => :number,
"Bignum" => :number,
"Float" => :number,
"Complex" => :number,
"String" => :string,
"Symbol" => :symbol,
}
class File
attr_reader :data_type, :data
def initialize(data = nil)
@data = data
@data_type = TYPES[data.class.name]
end
def data=(data)
@data = data
@data_type = TYPES[data.class.name]
end
def serialize
data_type.to_s + ':' + data.to_s
end
def self.parse(string_data)
end
end
class Directory
attr_reader :files, :directories
def initialize
@files = {}
@directories = {}
end
def add_file(name, file = File.new)
@files[name] = file
end
def add_directory(name, directory = Directory.new)
@directories[name] = directory
end
def [](name)
@directories[name] || @files[name]
end
def serialize
serialized = ""
serialized += serialize_array @files
serialized += serialize_array @directories
end
def serialize_array(array)
serialized = array.size.to_s + ':'
array.each do |name, value|
serialized += name.to_s + ':'
serialized += value.serialize.size.to_s + ':'
serialized += value.serialize.to_s
end
serialized
end
def self.parse(string_data)
end
end
end

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

..........FFFF..........F..FF..F..F..F..F..F

Failures:

  1) 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-1nxlthl/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)>'

  2) 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-1nxlthl/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)>'

  3) 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-1nxlthl/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)>'

  4) 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-1nxlthl/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)>'

  5) RBFS File data type nil can be parsed
     Failure/Error: expect(file.data     ).to eq nil
     NoMethodError:
       undefined method `data' for nil:NilClass
     # /tmp/d20141111-26053-1nxlthl/spec.rb:231: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 File data type string can be parsed
     Failure/Error: expect(file.data     ).to eq 'Hey there'
     NoMethodError:
       undefined method `data' for nil:NilClass
     # /tmp/d20141111-26053-1nxlthl/spec.rb:250: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 File data type string can parse a string with colons
     Failure/Error: expect(file.data     ).to eq 'Hay :)'
     NoMethodError:
       undefined method `data' for nil:NilClass
     # /tmp/d20141111-26053-1nxlthl/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)>'

  8) RBFS File data type symbol can be parsed
     Failure/Error: expect(file.data     ).to eq :hello
     NoMethodError:
       undefined method `data' for nil:NilClass
     # /tmp/d20141111-26053-1nxlthl/spec.rb:276: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)>'

  9) RBFS File data type number can be parsed
     Failure/Error: expect(file.data     ).to eq 1234
     NoMethodError:
       undefined method `data' for nil:NilClass
     # /tmp/d20141111-26053-1nxlthl/spec.rb:295: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)>'

  10) RBFS File data type float number can be parsed
     Failure/Error: expect(file.data     ).to eq 3.14
     NoMethodError:
       undefined method `data' for nil:NilClass
     # /tmp/d20141111-26053-1nxlthl/spec.rb:314: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)>'

  11) RBFS File data type boolean true can be parsed
     Failure/Error: expect(file.data     ).to eq true
     NoMethodError:
       undefined method `data' for nil:NilClass
     # /tmp/d20141111-26053-1nxlthl/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)>'

  12) RBFS File data type boolean false can be parsed
     Failure/Error: expect(file.data     ).to eq false
     NoMethodError:
       undefined method `data' for nil:NilClass
     # /tmp/d20141111-26053-1nxlthl/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.04192 seconds
44 examples, 12 failures

Failed examples:

rspec /tmp/d20141111-26053-1nxlthl/spec.rb:100 # RBFS Directory serialization ::parse can parse empty directories
rspec /tmp/d20141111-26053-1nxlthl/spec.rb:107 # RBFS Directory serialization ::parse can parse directories with files
rspec /tmp/d20141111-26053-1nxlthl/spec.rb:116 # RBFS Directory serialization ::parse can parse directory trees without files
rspec /tmp/d20141111-26053-1nxlthl/spec.rb:124 # RBFS Directory serialization ::parse can parse directories recursively
rspec /tmp/d20141111-26053-1nxlthl/spec.rb:229 # RBFS File data type nil can be parsed
rspec /tmp/d20141111-26053-1nxlthl/spec.rb:247 # RBFS File data type string can be parsed
rspec /tmp/d20141111-26053-1nxlthl/spec.rb:254 # RBFS File data type string can parse a string with colons
rspec /tmp/d20141111-26053-1nxlthl/spec.rb:273 # RBFS File data type symbol can be parsed
rspec /tmp/d20141111-26053-1nxlthl/spec.rb:292 # RBFS File data type number can be parsed
rspec /tmp/d20141111-26053-1nxlthl/spec.rb:311 # RBFS File data type float number can be parsed
rspec /tmp/d20141111-26053-1nxlthl/spec.rb:331 # RBFS File data type boolean true can be parsed
rspec /tmp/d20141111-26053-1nxlthl/spec.rb:350 # RBFS File data type boolean false can be parsed

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

Николина обнови решението на 10.11.2014 00:26 (преди около 10 години)

+module RBFS
+ TYPES = {
+ "TrueClass" => :boolean,
+ "FalseClass" => :boolean,
+ "NilClass" => :nil,
+ "Fixnum" => :number,
+ "Bignum" => :number,
+ "Float" => :number,
+ "Complex" => :number,
+ "String" => :string,
+ "Symbol" => :symbol,
+ }
+
+ class File
+ attr_reader :data_type, :data
+
+ def initialize(data = nil)
+ @data = data
+ @data_type = TYPES[data.class.name]
+ end
+
+ def data=(data)
+ @data = data
+ @data_type = TYPES[data.class.name]
+ end
+
+ def serialize
+ data_type.to_s + ':' + data.to_s
+ end
+
+ def self.parse(string_data)
+ end
+ end
+
+ class Directory
+ attr_reader :files, :directories
+
+ def initialize
+ @files = {}
+ @directories = {}
+ end
+
+ def add_file(name, file = File.new)
+ @files[name] = file
+ end
+
+ def add_directory(name, directory = Directory.new)
+ @directories[name] = directory
+ end
+
+ def [](name)
+ @directories[name] || @files[name]
+ end
+
+ def serialize
+ serialized = ""
+ serialized += serialize_array @files
+ serialized += serialize_array @directories
+ end
+
+ def serialize_array(array)
+ serialized = array.size.to_s + ':'
+ array.each do |name, value|
+ serialized += name.to_s + ':'
+ serialized += value.serialize.size.to_s + ':'
+ serialized += value.serialize.to_s
+ end
+
+ serialized
+ end
+
+ def self.parse(string_data)
+ end
+ end
+end