Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
jhannah committed Nov 15, 2014
1 parent 062541a commit 56dd7c6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
15 changes: 15 additions & 0 deletions code_retreat/2014/perl/Board.pm
Expand Up @@ -62,6 +62,21 @@ sub will_live {
return 0;
}

sub all_living_cells {
my $self = shift;
my @cells;

foreach (my $x (keys($self->board))) {
foreach (my $y (keys($self->board->{$x}))) {
if($self->board->{$x}->{$y} == 1) {
push (@cells, "$x,$y");
}
}

return join (@cells, "|");
}

}

1;

Expand Down
27 changes: 16 additions & 11 deletions code_retreat/2014/perl/board.t
Expand Up @@ -2,17 +2,22 @@ use Test::More;
use Board;

ok(my $b = Board->new());
#ok($b->set_cell(5,5), "set_cell");
#ok($b->set_cell(4,5), "set_cell");
#ok($b->set_cell(5,6), "set_cell");
#ok($b->set_cell(5,3), "set_cell");
ok($b->set_cell(3,3,1), "set_cell");
ok($b->check_cell(3,3), "check_cell");
ok($b = $b->go, "go");
ok(!$b->check_cell(3,3), "check_cell");

ok($b = $b->go, "go");
ok($b->display, "display");

# Lone living cell dies:
ok($b->set_cell(3,3,1), "set_cell");
ok($b->check_cell(3,3), "check_cell");
ok($b = $b->go, "go");
ok(!$b->check_cell(3,3), "check_cell");

# Dead cell can burst into life:
ok($b->set_cell(3,3,1), "set_cell");
ok($b->set_cell(3,4,1), "set_cell");
ok($b->set_cell(3,5,1), "set_cell");
ok($b = $b->go, "go");
ok(!$b->check_cell(3,3), "check_cell");
is($b->all_living_cells, '2,4', "all_living_cells");

ok($b->display, "display");

done_testing();

Expand Down

0 comments on commit 56dd7c6

Please sign in to comment.