Решение на Пета задача от Георги Стефанов

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

Към профила на Георги Стефанов

Резултати

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

Код

class ObjectStore
def initialize()
@store = {}
@add_store = {}
@remove_store = {}
end
def add(name = 0, object = 0)
@add_store[name] = object
"Added #{name} to stage."
end
def remove(name)
@remove_store[name] = @store.delete(name)
if @remove_store[name] == nil
"Object #{name} is not committed."
else
"Added #{name} for removal."
end
end
def commit(message)
if @add_store.empty? and @remove_store.empty?
"Nothing to commit, working directory clean"
else
@store.merge(@add_store)
remove_size = @remove_store.length
@remove_store = {}
add_size = @add_store.length
@add_store = {}
"#{message} #{add_size + remove_size} objects changed"
end
end
end
#I'm very sorry that I couldn't finish this task.
#Had very little time during last week. :(

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

FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Failures:

  1) ObjectStore can add objects
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:22:in `block (2 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) ObjectStore can commit objects
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:27:in `block (2 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) ObjectStore cannot commit without changed objects
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:34:in `block (2 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) ObjectStore can remove objects
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:39:in `block (2 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) ObjectStore can commit changes which include only removed objects
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:47:in `block (2 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) ObjectStore cannot remove objects that are not committed
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:57:in `block (2 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) ObjectStore can show head
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:64:in `block (2 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) ObjectStore cannot show head for empty repository
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:73:in `block (2 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) ObjectStore can show log of changes for a single commit
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:78:in `block (2 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) ObjectStore can show log of changes for a single commit
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:87:in `block (2 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) ObjectStore can show log of changes for multiple commits
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:96:in `block (2 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) ObjectStore shows the log for the current branch only
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:112:in `block (2 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) ObjectStore cannot show log for empty repository
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:132:in `block (2 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) ObjectStore can list branches
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:137:in `block (2 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) ObjectStore can create branches
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:144:in `block (2 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) ObjectStore cannot create branch if already exists
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:149:in `block (2 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) ObjectStore can switch branches
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:154:in `block (2 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) ObjectStore cannot switch to nonexisting branch
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:167:in `block (2 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) ObjectStore can remove branch
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:172:in `block (2 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) ObjectStore cannot remove current branch
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:178:in `block (2 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) ObjectStore cannot remove nonexisting branch
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:183:in `block (2 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) ObjectStore can be initialized with block
     Failure/Error: repo = ObjectStore.init do
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:188:in `block (2 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) ObjectStore can return objects
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:199:in `block (2 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) ObjectStore cannot return not committed objects
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:206:in `block (2 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) ObjectStore cannot return objects when no commits
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:213:in `block (2 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) ObjectStore can checkout commits
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:218:in `block (2 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) ObjectStore cannot checkout commits with nonexisting hashes
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:228:in `block (2 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) ObjectStore cannot checkout commits in empty repository
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:235:in `block (2 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) ObjectStore can show the objects in a repo after overwriting an object
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:240:in `block (2 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) ObjectStore can show the objects of a repo after removing an object
     Failure/Error: repo = ObjectStore.init
     NoMethodError:
       undefined method `init' for ObjectStore:Class
     # /tmp/d20160111-5693-jwnid2/spec.rb:254:in `block (2 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.01017 seconds
30 examples, 30 failures

Failed examples:

rspec /tmp/d20160111-5693-jwnid2/spec.rb:21 # ObjectStore can add objects
rspec /tmp/d20160111-5693-jwnid2/spec.rb:26 # ObjectStore can commit objects
rspec /tmp/d20160111-5693-jwnid2/spec.rb:33 # ObjectStore cannot commit without changed objects
rspec /tmp/d20160111-5693-jwnid2/spec.rb:38 # ObjectStore can remove objects
rspec /tmp/d20160111-5693-jwnid2/spec.rb:46 # ObjectStore can commit changes which include only removed objects
rspec /tmp/d20160111-5693-jwnid2/spec.rb:56 # ObjectStore cannot remove objects that are not committed
rspec /tmp/d20160111-5693-jwnid2/spec.rb:63 # ObjectStore can show head
rspec /tmp/d20160111-5693-jwnid2/spec.rb:72 # ObjectStore cannot show head for empty repository
rspec /tmp/d20160111-5693-jwnid2/spec.rb:77 # ObjectStore can show log of changes for a single commit
rspec /tmp/d20160111-5693-jwnid2/spec.rb:86 # ObjectStore can show log of changes for a single commit
rspec /tmp/d20160111-5693-jwnid2/spec.rb:95 # ObjectStore can show log of changes for multiple commits
rspec /tmp/d20160111-5693-jwnid2/spec.rb:111 # ObjectStore shows the log for the current branch only
rspec /tmp/d20160111-5693-jwnid2/spec.rb:131 # ObjectStore cannot show log for empty repository
rspec /tmp/d20160111-5693-jwnid2/spec.rb:136 # ObjectStore can list branches
rspec /tmp/d20160111-5693-jwnid2/spec.rb:143 # ObjectStore can create branches
rspec /tmp/d20160111-5693-jwnid2/spec.rb:148 # ObjectStore cannot create branch if already exists
rspec /tmp/d20160111-5693-jwnid2/spec.rb:153 # ObjectStore can switch branches
rspec /tmp/d20160111-5693-jwnid2/spec.rb:166 # ObjectStore cannot switch to nonexisting branch
rspec /tmp/d20160111-5693-jwnid2/spec.rb:171 # ObjectStore can remove branch
rspec /tmp/d20160111-5693-jwnid2/spec.rb:177 # ObjectStore cannot remove current branch
rspec /tmp/d20160111-5693-jwnid2/spec.rb:182 # ObjectStore cannot remove nonexisting branch
rspec /tmp/d20160111-5693-jwnid2/spec.rb:187 # ObjectStore can be initialized with block
rspec /tmp/d20160111-5693-jwnid2/spec.rb:198 # ObjectStore can return objects
rspec /tmp/d20160111-5693-jwnid2/spec.rb:205 # ObjectStore cannot return not committed objects
rspec /tmp/d20160111-5693-jwnid2/spec.rb:212 # ObjectStore cannot return objects when no commits
rspec /tmp/d20160111-5693-jwnid2/spec.rb:217 # ObjectStore can checkout commits
rspec /tmp/d20160111-5693-jwnid2/spec.rb:227 # ObjectStore cannot checkout commits with nonexisting hashes
rspec /tmp/d20160111-5693-jwnid2/spec.rb:234 # ObjectStore cannot checkout commits in empty repository
rspec /tmp/d20160111-5693-jwnid2/spec.rb:239 # ObjectStore can show the objects in a repo after overwriting an object
rspec /tmp/d20160111-5693-jwnid2/spec.rb:253 # ObjectStore can show the objects of a repo after removing an object

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

Георги обнови решението на 23.11.2015 13:25 (преди над 9 години)

+class ObjectStore
+
+ def initialize()
+ @store = {}
+ @add_store = {}
+ @remove_store = {}
+ end
+
+ def add(name = 0, object = 0)
+ @add_store[name] = object
+ "Added #{name} to stage."
+ end
+
+ def remove(name)
+ @remove_store[name] = @store.delete(name)
+ if @remove_store[name] == nil
+ "Object #{name} is not committed."
+ else
+ "Added #{name} for removal."
+ end
+ end
+
+ def commit(message)
+ if @add_store.empty? and @remove_store.empty?
+ "Nothing to commit, working directory clean"
+ else
+ @store.merge(@add_store)
+ remove_size = @remove_store.length
+ @remove_store = {}
+ add_size = @add_store.length
+ @add_store = {}
+ "#{message} #{add_size + remove_size} objects changed"
+ end
+ end
+
+end
+
+#I'm very sorry that I couldn't finish this task.
+#Had very little time during last week. :(