Решение на Трета задача от Димитър Шукерски

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

Към профила на Димитър Шукерски

Резултати

  • 2 точки от тестове
  • 0 бонус точки
  • 2 точки общо
  • 16 успешни тест(а)
  • 28 неуспешни тест(а)

Код

module RBFS
class File
attr_reader :data_type, :data
def initialize(obj = nil)
@data_type = obj.class
self.data = obj
end
def is_boolean(obj)
if obj.class == TrueClass or obj.class == FalseClass
@data_type = :boolean
end
end
def is_string(obj)
if obj.class == String
@data_type = :string
end
end
def is_symbol(obj)
if obj.class == Symbol
@data_type = :symbol
end
end
def is_number(obj)
if obj.class == Fixnum or obj.class == Float
@data_type = :number
end
end
def is_nil(obj)
if obj.class == NilClass
@data_type = :nil
end
end
def data=(obj)
is_nil(obj)
is_number(obj)
is_symbol(obj)
is_string(obj)
is_boolean(obj)
@data = obj
end
def serialize(obj)
"#{@data_type}:#{@data}"
end
end
class Directory
attr_reader :files, :directories
def initialize()
@files = Hash.new {}
@directories = Hash.new {}
end
def add_file(name, file)
@files[name] = file
end
def add_directory(name, directory)
@directories[name] = directory
end
end
end

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

.F..F...FFFFFFFFFFF....FF.FFF.FF.FF.FF.FF.FF

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-l2ci49/solution.rb:66:in `add_directory'
     # /tmp/d20141111-26053-l2ci49/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 without files can be serialized
     Failure/Error: expect(directory.serialize).to eq '0:0:'
     NoMethodError:
       undefined method `serialize' for #<RBFS::Directory:0xba35e250 @files={}, @directories={}>
     # /tmp/d20141111-26053-l2ci49/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)>'

  3) RBFS Directory serialization #serialize can serialize
     Failure/Error: directory.add_directory 'rbfs'
     ArgumentError:
       wrong number of arguments (1 for 2)
     # /tmp/d20141111-26053-l2ci49/solution.rb:66:in `add_directory'
     # /tmp/d20141111-26053-l2ci49/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)>'

  4) 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-l2ci49/solution.rb:66:in `add_directory'
     # /tmp/d20141111-26053-l2ci49/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)>'

  5) RBFS Directory serialization ::parse can parse empty directories
     Failure/Error: parsed_directory = RBFS::Directory.parse('0:0:')
     NoMethodError:
       undefined method `parse' for RBFS::Directory:Class
     # /tmp/d20141111-26053-l2ci49/spec.rb:101: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 directories with files
     Failure/Error: parsed_directory = RBFS::Directory.parse(simple_serialized_string)
     NoMethodError:
       undefined method `parse' for RBFS::Directory:Class
     # /tmp/d20141111-26053-l2ci49/spec.rb:108: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 directory trees without files
     Failure/Error: parsed_directory = RBFS::Directory.parse('0:2:dir1:15:0:1:dir2:4:0:0:dir3:4:0:0:')
     NoMethodError:
       undefined method `parse' for RBFS::Directory:Class
     # /tmp/d20141111-26053-l2ci49/spec.rb:117: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 serialization ::parse can parse directories recursively
     Failure/Error: parsed_directory = RBFS::Directory.parse(recursive_serialized_string)
     NoMethodError:
       undefined method `parse' for RBFS::Directory:Class
     # /tmp/d20141111-26053-l2ci49/spec.rb:125: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 Directory #[] can walk a single directory
     Failure/Error: expect(directory['home']).to eq home
     NoMethodError:
       undefined method `[]' for #<RBFS::Directory:0xba277710>
     # /tmp/d20141111-26053-l2ci49/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)>'

  10) RBFS Directory #[] can walk multiple directories
     Failure/Error: expect(directory['home']['user']['ruby']).to eq ruby
     NoMethodError:
       undefined method `[]' for #<RBFS::Directory:0xba276324>
     # /tmp/d20141111-26053-l2ci49/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)>'

  11) RBFS Directory #[] can get files
     Failure/Error: expect(directory['home']['user']['ruby']['file']).to eq file
     NoMethodError:
       undefined method `[]' for #<RBFS::Directory:0xba275474>
     # /tmp/d20141111-26053-l2ci49/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)>'

  12) RBFS Directory #[] returns nil if directory or file doesnt exist
     Failure/Error: expect(directory['home']['another_user']).to be_nil
     NoMethodError:
       undefined method `[]' for #<RBFS::Directory:0xba2744d4>
     # /tmp/d20141111-26053-l2ci49/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)>'

  13) RBFS Directory #[] is case-sensitive
     Failure/Error: expect(directory['HOME']).to be_nil
     NoMethodError:
       undefined method `[]' for #<RBFS::Directory:0xba273520>
     # /tmp/d20141111-26053-l2ci49/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)>'

  14) RBFS File data type nil can be serialized
     Failure/Error: expect(file.serialize).to eq 'nil:'
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-l2ci49/solution.rb:49:in `serialize'
     # /tmp/d20141111-26053-l2ci49/spec.rb:226: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)>'

  15) RBFS File data type nil can be parsed
     Failure/Error: file = RBFS::File.parse('nil:')
     NoMethodError:
       undefined method `parse' for RBFS::File:Class
     # /tmp/d20141111-26053-l2ci49/spec.rb:230: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 string can be serialized
     Failure/Error: expect(file.serialize).to eq 'string:Hi'
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-l2ci49/solution.rb:49:in `serialize'
     # /tmp/d20141111-26053-l2ci49/spec.rb:244: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 string can be parsed
     Failure/Error: file = RBFS::File.parse('string:Hey there')
     NoMethodError:
       undefined method `parse' for RBFS::File:Class
     # /tmp/d20141111-26053-l2ci49/spec.rb:248: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 parse a string with colons
     Failure/Error: file = RBFS::File.parse('string:Hay :)')
     NoMethodError:
       undefined method `parse' for RBFS::File:Class
     # /tmp/d20141111-26053-l2ci49/spec.rb:255: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 symbol can be serialized
     Failure/Error: expect(file.serialize).to eq 'symbol:yo'
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-l2ci49/solution.rb:49:in `serialize'
     # /tmp/d20141111-26053-l2ci49/spec.rb:270: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 symbol can be parsed
     Failure/Error: file = RBFS::File.parse('symbol:hello')
     NoMethodError:
       undefined method `parse' for RBFS::File:Class
     # /tmp/d20141111-26053-l2ci49/spec.rb:274: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 number can be serialized
     Failure/Error: expect(file.serialize).to eq 'number:666'
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-l2ci49/solution.rb:49:in `serialize'
     # /tmp/d20141111-26053-l2ci49/spec.rb:289: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 number can be parsed
     Failure/Error: file = RBFS::File.parse('number:1234')
     NoMethodError:
       undefined method `parse' for RBFS::File:Class
     # /tmp/d20141111-26053-l2ci49/spec.rb:293: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 float number can be serialized
     Failure/Error: expect(file.serialize).to eq 'number:666.6'
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-l2ci49/solution.rb:49:in `serialize'
     # /tmp/d20141111-26053-l2ci49/spec.rb:308: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 float number can be parsed
     Failure/Error: file = RBFS::File.parse('number:3.14')
     NoMethodError:
       undefined method `parse' for RBFS::File:Class
     # /tmp/d20141111-26053-l2ci49/spec.rb:312: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 boolean true can be serialized
     Failure/Error: expect(file.serialize).to eq 'boolean:true'
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-l2ci49/solution.rb:49:in `serialize'
     # /tmp/d20141111-26053-l2ci49/spec.rb:328: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)>'

  26) RBFS File data type boolean true can be parsed
     Failure/Error: file = RBFS::File.parse('boolean:true')
     NoMethodError:
       undefined method `parse' for RBFS::File:Class
     # /tmp/d20141111-26053-l2ci49/spec.rb:332: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)>'

  27) RBFS File data type boolean false can be serialized
     Failure/Error: expect(file.serialize).to eq 'boolean:false'
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141111-26053-l2ci49/solution.rb:49:in `serialize'
     # /tmp/d20141111-26053-l2ci49/spec.rb:347: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)>'

  28) RBFS File data type boolean false can be parsed
     Failure/Error: file = RBFS::File.parse('boolean:false')
     NoMethodError:
       undefined method `parse' for RBFS::File:Class
     # /tmp/d20141111-26053-l2ci49/spec.rb:351: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.03927 seconds
44 examples, 28 failures

Failed examples:

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

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

Димитър обнови решението на 10.11.2014 01:34 (преди над 9 години)

+module RBFS
+ class File
+ attr_reader :data_type, :data
+
+ def initialize(obj = nil)
+ @data_type = obj.class
+ self.data = obj
+ end
+
+ def is_boolean(obj)
+ if obj.class == TrueClass or obj.class == FalseClass
+ @data_type = :boolean
+ end
+ end
+
+ def is_string(obj)
+ if obj.class == String
+ @data_type = :string
+ end
+ end
+
+ def is_symbol(obj)
+ if obj.class == Symbol
+ @data_type = :symbol
+ end
+ end
+
+ def is_number(obj)
+ if obj.class == Fixnum or obj.class == Float
+ @data_type = :number
+ end
+ end
+
+ def is_nil(obj)
+ if obj.class == NilClass
+ @data_type = :nil
+ end
+ end
+
+ def data=(obj)
+ is_nil(obj)
+ is_number(obj)
+ is_symbol(obj)
+ is_string(obj)
+ is_boolean(obj)
+ @data = obj
+ end
+
+ def serialize(obj)
+ "#{@data_type}:#{@data}"
+ end
+ end
+
+ class Directory
+ attr_reader :files, :directories
+
+ def initialize()
+ @files = Hash.new {}
+ @directories = Hash.new {}
+ end
+
+ def add_file(name, file)
+ @files[name] = file
+ end
+
+ def add_directory(name, directory)
+ @directories[name] = directory
+ end
+ end
+end