Решение на Трета задача от Мартин Христов

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

Към профила на Мартин Христов

Резултати

  • 3 точки от тестове
  • 0 бонус точки
  • 3 точки общо
  • 23 успешни тест(а)
  • 21 неуспешни тест(а)

Код

module RBFS
class File
def initialize data = nil
@data = data
end
def data_type
case data
when Fixnum then :number
when NilClass then :nil
when String then :string
when Symbol then :Symbol
when TrueClass || FalseClass then :boolean
end
end
attr_accessor :data
def serialize
data_type.to_s + ":" + data.to_s
end
def File.parse string_data
File.new(string_data)
end
end
class Directory
def initialize
@content = {}
end
def add_file name, file
@content[name] = file
end
def add_directory name, directory=nil
if directory
@content[name] = directory
else
@content[name] = Directory.new()
end
end
def [] name
if @content[name].class == File
@content[name]
else
@content[name]
end
end
def check_content array, filter, buffer
array[1].class == filter ? buffer[array[0]] = array[1] : buffer
end
def files
files = {}
@content.each do |item|
check_content item, File, files
end
files
end
def directories
directories = {}
@content.each do |item|
check_content item, Directory, directories
end
directories
end
def serialize
#TODO
end
def Directory.parse string_data
#TODO
end
end
end

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

....F...FFFFFF..........F..FFFFF..FFFF..FFFF

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-t4f4jm/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-t4f4jm/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-t4f4jm/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-t4f4jm/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-t4f4jm/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-t4f4jm/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-t4f4jm/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 nil can be parsed
     Failure/Error: expect(file.data     ).to eq nil
       
       expected: nil
            got: "nil:"
       
       (compared using ==)
     # /tmp/d20141111-26053-t4f4jm/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)>'

  9) RBFS File data type string can be parsed
     Failure/Error: expect(file.data     ).to eq 'Hey there'
       
       expected: "Hey there"
            got: "string:Hey there"
       
       (compared using ==)
     # /tmp/d20141111-26053-t4f4jm/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)>'

  10) RBFS File data type string can parse a string with colons
     Failure/Error: expect(file.data     ).to eq 'Hay :)'
       
       expected: "Hay :)"
            got: "string:Hay :)"
       
       (compared using ==)
     # /tmp/d20141111-26053-t4f4jm/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)>'

  11) RBFS File data type symbol can be detected
     Failure/Error: expect(file.data_type).to eq :symbol
       
       expected: :symbol
            got: :Symbol
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -:symbol
       +:Symbol
     # /tmp/d20141111-26053-t4f4jm/spec.rb:266: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)>'

  12) RBFS File data type symbol can be serialized
     Failure/Error: expect(file.serialize).to eq 'symbol:yo'
       
       expected: "symbol:yo"
            got: "Symbol:yo"
       
       (compared using ==)
     # /tmp/d20141111-26053-t4f4jm/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)>'

  13) RBFS File data type symbol can be parsed
     Failure/Error: expect(file.data     ).to eq :hello
       
       expected: :hello
            got: "symbol:hello"
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -:hello
       +"symbol:hello"
     # /tmp/d20141111-26053-t4f4jm/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)>'

  14) RBFS File data type number can be parsed
     Failure/Error: expect(file.data     ).to eq 1234
       
       expected: 1234
            got: "number:1234"
       
       (compared using ==)
     # /tmp/d20141111-26053-t4f4jm/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)>'

  15) RBFS File data type float number can be detected
     Failure/Error: expect(file.data_type).to eq :number
       
       expected: :number
            got: nil
       
       (compared using ==)
     # /tmp/d20141111-26053-t4f4jm/spec.rb:304: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 float number can be serialized
     Failure/Error: expect(file.serialize).to eq 'number:666.6'
       
       expected: "number:666.6"
            got: ":666.6"
       
       (compared using ==)
     # /tmp/d20141111-26053-t4f4jm/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)>'

  17) RBFS File data type float number can be parsed
     Failure/Error: expect(file.data     ).to eq 3.14
       
       expected: 3.14
            got: "number:3.14"
       
       (compared using ==)
     # /tmp/d20141111-26053-t4f4jm/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)>'

  18) RBFS File data type boolean true can be parsed
     Failure/Error: expect(file.data     ).to eq true
       
       expected: true
            got: "boolean:true"
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -true
       +"boolean:true"
     # /tmp/d20141111-26053-t4f4jm/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)>'

  19) RBFS File data type boolean false can be detected
     Failure/Error: expect(file.data_type).to eq :boolean
       
       expected: :boolean
            got: nil
       
       (compared using ==)
     # /tmp/d20141111-26053-t4f4jm/spec.rb:342: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)>'

  20) RBFS File data type boolean false can be serialized
     Failure/Error: expect(file.serialize).to eq 'boolean:false'
       
       expected: "boolean:false"
            got: ":false"
       
       (compared using ==)
     # /tmp/d20141111-26053-t4f4jm/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)>'

  21) RBFS File data type boolean false can be parsed
     Failure/Error: expect(file.data     ).to eq false
       
       expected: false
            got: "boolean:false"
       
       (compared using ==)
     # /tmp/d20141111-26053-t4f4jm/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.04832 seconds
44 examples, 21 failures

Failed examples:

rspec /tmp/d20141111-26053-t4f4jm/spec.rb:10 # RBFS Directory without files can be serialized
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:76 # RBFS Directory serialization #serialize can serialize
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:84 # RBFS Directory serialization #serialize can serialize multiple directories recursively
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:100 # RBFS Directory serialization ::parse can parse empty directories
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:107 # RBFS Directory serialization ::parse can parse directories with files
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:116 # RBFS Directory serialization ::parse can parse directory trees without files
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:124 # RBFS Directory serialization ::parse can parse directories recursively
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:229 # RBFS File data type nil can be parsed
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:247 # RBFS File data type string can be parsed
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:254 # RBFS File data type string can parse a string with colons
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:265 # RBFS File data type symbol can be detected
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:269 # RBFS File data type symbol can be serialized
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:273 # RBFS File data type symbol can be parsed
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:292 # RBFS File data type number can be parsed
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:303 # RBFS File data type float number can be detected
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:307 # RBFS File data type float number can be serialized
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:311 # RBFS File data type float number can be parsed
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:331 # RBFS File data type boolean true can be parsed
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:340 # RBFS File data type boolean false can be detected
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:345 # RBFS File data type boolean false can be serialized
rspec /tmp/d20141111-26053-t4f4jm/spec.rb:350 # RBFS File data type boolean false can be parsed

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

Мартин обнови решението на 08.11.2014 23:06 (преди над 9 години)

+module RBFS
+ class File
+ def initialize data = nil
+ @data = data
+ end
+
+ def data_type
+ case data
+ when Fixnum then :number
+ when NilClass then :nil
+ when String then :string
+ when Symbol then :Symbol
+ when TrueClass || FalseClass then :boolean
+ end
+ end
+
+ attr_accessor :data
+
+ def serialize
+ data_type.to_s + ":" + data.to_s
+ end
+
+ def File.parse string_data
+ File.new(string_data)
+ end
+ end
+
+ class Directory
+ def initialize
+ @content = {}
+ end
+ def add_file name, file
+ @content[name] = file
+ end
+
+ def add_directory name, directory=nil
+ if directory
+ @content[name] = directory
+ else
+ @content[name] = Directory.new()
+ end
+ end
+
+ def [] name
+ if @content[name].class == File
+ @content[name]
+ else
+ @content[name]
+ end
+ end
+
+ def check_content array, filter, buffer
+ array[1].class == filter ? buffer[array[0]] = array[1] : buffer
+ end
+
+ def files
+ files = {}
+ @content.each do |item|
+ check_content item, File, files
+ end
+ files
+ end
+
+
+ def directories
+ directories = {}
+ @content.each do |item|
+ check_content item, Directory, directories
+ end
+ directories
+ end
+
+ def serialize
+ #TODO
+ end
+
+ def Directory.parse string_data
+ #TODO
+ end
+ end
+end