Решение на Шеста задача от Михаил Илиев

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

Към профила на Михаил Илиев

Резултати

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

Код

module GameOfLife
class Board
include Enumerable
def initialize(*args)
@alive = args.uniq
end
def each
@alive.each { |cell| yield cell}
end
def [](x, y)
@alive.include? [x, y]
end
def count
@alive.count
end
def next_generation
@alive
end
end
end

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

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

Failures:

  1) GameOfLife::Board evolution returns a new board
     Failure/Error: next_gen.should be_kind_of(GameOfLife::Board)
       expected [] to be a kind of GameOfLife::Board
     # /tmp/d20111221-3114-w58sqr/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)>'

  2) GameOfLife::Board GameOfLife::Board evolution rules kills cells in underpopulated areas
     Failure/Error: next_gen.count.should eq 0
       
       expected: 0
            got: 1
       
       (compared using ==)
     # /tmp/d20111221-3114-w58sqr/spec.rb:91: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 evolution rules kills cells in overpopulated areas
     Failure/Error: next_gen[1, 1].should be_false
       expected [[1, 1]] to be false
     # /tmp/d20111221-3114-w58sqr/spec.rb:114: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 GameOfLife::Board evolution rules evolves a formation correctly
     Failure/Error: board.count.should eq cells.count
       
       expected: 7
            got: 4
       
       (compared using ==)
     # /tmp/d20111221-3114-w58sqr/spec.rb:172:in `expect_generation_in'
     # /tmp/d20111221-3114-w58sqr/spec.rb:136: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)>'

  5) GameOfLife::Board GameOfLife::Board evolution rules oscilates the oscilators
     Failure/Error: (board.to_a - cells).should eq []
       
       expected: []
            got: [[0, 1], [2, 1]]
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -[]
       +[[0, 1], [2, 1]]
     # /tmp/d20111221-3114-w58sqr/spec.rb:173:in `expect_generation_in'
     # /tmp/d20111221-3114-w58sqr/spec.rb:145:in `block (5 levels) in <top (required)>'
     # /tmp/d20111221-3114-w58sqr/spec.rb:142:in `times'
     # /tmp/d20111221-3114-w58sqr/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)>'

  6) GameOfLife::Board GameOfLife::Board evolution rules keeps stable formations stable
     Failure/Error: board = board.next_generation
     NoMethodError:
       undefined method `next_generation' for [[0, 0], [1, 0], [0, 1], [1, 1]]:Array
     # /tmp/d20111221-3114-w58sqr/spec.rb:159:in `block (6 levels) in <top (required)>'
     # /tmp/d20111221-3114-w58sqr/spec.rb:158:in `times'
     # /tmp/d20111221-3114-w58sqr/spec.rb:158:in `block (5 levels) in <top (required)>'
     # /tmp/d20111221-3114-w58sqr/spec.rb:155:in `each'
     # /tmp/d20111221-3114-w58sqr/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.32584 seconds
18 examples, 6 failures

Failed examples:

rspec /tmp/d20111221-3114-w58sqr/spec.rb:72 # GameOfLife::Board evolution returns a new board
rspec /tmp/d20111221-3114-w58sqr/spec.rb:81 # GameOfLife::Board GameOfLife::Board evolution rules kills cells in underpopulated areas
rspec /tmp/d20111221-3114-w58sqr/spec.rb:106 # GameOfLife::Board GameOfLife::Board evolution rules kills cells in overpopulated areas
rspec /tmp/d20111221-3114-w58sqr/spec.rb:129 # GameOfLife::Board GameOfLife::Board evolution rules evolves a formation correctly
rspec /tmp/d20111221-3114-w58sqr/spec.rb:139 # GameOfLife::Board GameOfLife::Board evolution rules oscilates the oscilators
rspec /tmp/d20111221-3114-w58sqr/spec.rb:151 # GameOfLife::Board GameOfLife::Board evolution rules keeps stable formations stable

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

Михаил обнови решението на 20.12.2011 17:55 (преди над 8 години)

+module GameOfLife
+
+ class Board
+ include Enumerable
+
+ def initialize(*args)
+ @alive = args.uniq
+ end
+
+ def each
+ @alive.each { |cell| yield cell}
+ end
+
+ def [](x, y)
+ @alive.include? [x, y]
+ end
+
+ def count
+ @alive.count
+ end
+
+ def next_generation
+ @alive
+ end
+ end
+end