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

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

Към профила на Теодор Николов

Резултати

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

Код

module GameOfLife
class Board
def initialize(*fields)
@fields = fields
end
def each(&block)
@fields.each(&block)
end
def [](x,y)
@fields[x,y]
end
def next_generation
end
end
end

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

..F..FF...FFFFFFFF

Failures:

  1) GameOfLife::Board enumeration responds to each, map, count, etc.
     Failure/Error: board.should respond_to(enumerable_method)
       expected #<GameOfLife::Board:0x91990c0 @fields=[]> to respond to :count
     # /tmp/d20111221-3114-wt94ob/spec.rb:19:in `block (4 levels) in <top (required)>'
     # /tmp/d20111221-3114-wt94ob/spec.rb:18:in `each'
     # /tmp/d20111221-3114-wt94ob/spec.rb:18:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) GameOfLife::Board GameOfLife::Board enumeration live cells count returns 0 for an empty board
     Failure/Error: new_board.count.should eq 0
     NoMethodError:
       undefined method `count' for #<GameOfLife::Board:0x91a2260 @fields=[]>
     # /tmp/d20111221-3114-wt94ob/spec.rb:40:in `block (4 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) GameOfLife::Board GameOfLife::Board enumeration live cells count returns the number of live cells on a board
     Failure/Error: new_board([0, 0]).count.should eq 1
     NoMethodError:
       undefined method `count' for #<GameOfLife::Board:0x91a026c @fields=[[0, 0]]>
     # /tmp/d20111221-3114-wt94ob/spec.rb:44:in `block (4 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) GameOfLife::Board evolution returns a new board
     Failure/Error: next_gen.should be_kind_of(GameOfLife::Board)
       expected nil to be a kind of GameOfLife::Board
     # /tmp/d20111221-3114-wt94ob/spec.rb:76:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) GameOfLife::Board GameOfLife::Board evolution rules kills cells in underpopulated areas
     Failure/Error: board.count.should eq 1
     NoMethodError:
       undefined method `count' for #<GameOfLife::Board:0x9246eb4 @fields=[[1, 1]]>
     # /tmp/d20111221-3114-wt94ob/spec.rb:84:in `block (4 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) GameOfLife::Board GameOfLife::Board evolution rules preserves stable cells
     Failure/Error: board.count.should eq 4
     NoMethodError:
       undefined method `count' for #<GameOfLife::Board:0x92f2fd4>
     # /tmp/d20111221-3114-wt94ob/spec.rb:98:in `block (4 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) GameOfLife::Board GameOfLife::Board evolution rules kills cells in overpopulated areas
     Failure/Error: board.count.should eq 5
     NoMethodError:
       undefined method `count' for #<GameOfLife::Board:0x9321ce4>
     # /tmp/d20111221-3114-wt94ob/spec.rb:109:in `block (4 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) GameOfLife::Board GameOfLife::Board evolution rules sprouts new life when appropriate
     Failure/Error: board[1, 0].should be_false
       expected [] to be false
     # /tmp/d20111221-3114-wt94ob/spec.rb:120:in `block (4 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  9) GameOfLife::Board GameOfLife::Board evolution rules evolves a formation correctly
     Failure/Error: board.count.should eq 4
     NoMethodError:
       undefined method `count' for #<GameOfLife::Board:0x93e44ec>
     # /tmp/d20111221-3114-wt94ob/spec.rb:132:in `block (4 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  10) GameOfLife::Board GameOfLife::Board evolution rules oscilates the oscilators
     Failure/Error: board.count.should eq cells.count
     NoMethodError:
       undefined method `count' for #<GameOfLife::Board:0x93ee58c @fields=[[0, 1], [1, 1], [2, 1]]>
     # /tmp/d20111221-3114-wt94ob/spec.rb:172:in `expect_generation_in'
     # /tmp/d20111221-3114-wt94ob/spec.rb:145:in `block (5 levels) in <top (required)>'
     # /tmp/d20111221-3114-wt94ob/spec.rb:142:in `times'
     # /tmp/d20111221-3114-wt94ob/spec.rb:142:in `block (4 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  11) GameOfLife::Board GameOfLife::Board evolution rules keeps stable formations stable
     Failure/Error: board.count.should eq cells.count
     NoMethodError:
       undefined method `count' for nil:NilClass
     # /tmp/d20111221-3114-wt94ob/spec.rb:172:in `expect_generation_in'
     # /tmp/d20111221-3114-wt94ob/spec.rb:160:in `block (6 levels) in <top (required)>'
     # /tmp/d20111221-3114-wt94ob/spec.rb:158:in `times'
     # /tmp/d20111221-3114-wt94ob/spec.rb:158:in `block (5 levels) in <top (required)>'
     # /tmp/d20111221-3114-wt94ob/spec.rb:155:in `each'
     # /tmp/d20111221-3114-wt94ob/spec.rb:155:in `block (4 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.3182 seconds
18 examples, 11 failures

Failed examples:

rspec /tmp/d20111221-3114-wt94ob/spec.rb:15 # GameOfLife::Board enumeration responds to each, map, count, etc.
rspec /tmp/d20111221-3114-wt94ob/spec.rb:39 # GameOfLife::Board GameOfLife::Board enumeration live cells count returns 0 for an empty board
rspec /tmp/d20111221-3114-wt94ob/spec.rb:43 # GameOfLife::Board GameOfLife::Board enumeration live cells count returns the number of live cells on a board
rspec /tmp/d20111221-3114-wt94ob/spec.rb:72 # GameOfLife::Board evolution returns a new board
rspec /tmp/d20111221-3114-wt94ob/spec.rb:81 # GameOfLife::Board GameOfLife::Board evolution rules kills cells in underpopulated areas
rspec /tmp/d20111221-3114-wt94ob/spec.rb:95 # GameOfLife::Board GameOfLife::Board evolution rules preserves stable cells
rspec /tmp/d20111221-3114-wt94ob/spec.rb:106 # GameOfLife::Board GameOfLife::Board evolution rules kills cells in overpopulated areas
rspec /tmp/d20111221-3114-wt94ob/spec.rb:117 # GameOfLife::Board GameOfLife::Board evolution rules sprouts new life when appropriate
rspec /tmp/d20111221-3114-wt94ob/spec.rb:129 # GameOfLife::Board GameOfLife::Board evolution rules evolves a formation correctly
rspec /tmp/d20111221-3114-wt94ob/spec.rb:139 # GameOfLife::Board GameOfLife::Board evolution rules oscilates the oscilators
rspec /tmp/d20111221-3114-wt94ob/spec.rb:151 # GameOfLife::Board GameOfLife::Board evolution rules keeps stable formations stable

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

Теодор обнови решението на 20.12.2011 23:13 (преди над 8 години)

+module GameOfLife
+ class Board
+ def initialize(*fields)
+ @fields = fields
+ end
+
+ def each(&block)
+ @fields.each(&block)
+ end
+
+ def [](x,y)
+ @fields[x,y]
+ end
+ def next_generation
+
+ end
+ end
+end