Navigation Menu

Skip to content

Commit

Permalink
more ownable tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jberger committed Nov 18, 2011
1 parent 5a12b45 commit 05c076d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion t/tile-ownable.t
Expand Up @@ -16,11 +16,12 @@ my $money = $player->money;
my $group = Opoly::Board::Group::Ownable->new( name => 'Test Group' );
my $price = 100;
my $tile = Opoly::Board::Tile::Ownable->new( price => $price, name => 'Test Tile', group => $group, address => 1 );
my $action_tile = Opoly::Board::Tile::Ownable->new( price => $price, name => 'Test Tile', group => $group, address => 2 );

isa_ok( $tile, 'Opoly::Board::Tile' );
isa_ok( $tile, 'Opoly::Board::Tile::Ownable' );
is( $group->tiles->[0], $tile, 'The tile object exists in the groups\'s tiles arrayref' );
is( $group->monopoly, 0, 'Tile is not a monopoly' );
ok( ! $group->monopoly, 'Group is not a monopoly' );

$tile->arrive( $player );
is( $player->location, $tile, 'Player reports arriving at tile' );
Expand All @@ -40,10 +41,31 @@ is( $player->money, $money-=$price, 'After purchase: player paid correct amount'

# test some group stuff
is( $group->number_owned_by( $player ), 1, 'After purchase: group reports "one owned" by player' );
ok( ! $group->monopoly, 'After purchase: does not constitute monopoly' );

# buy $action_tile by action
$action_tile->arrive( $player );
my ($buy) = grep { /^Buy/ } keys %{ $player->actions };
ok( $buy, 'Has buy action' );
$player->actions->{$buy}->();
is( $action_tile->owner, $player, 'After purchase: owner is correct' );
is( $player->money, $money-=$price, 'After purchase: player paid correct amount' );
ok( ! (grep { /^Buy/ } keys %{ $player->actions }), 'After purchase ownable tile removes buy action from player' );

# test some group stuff
is( $group->number_owned_by( $player ), 2, 'After purchase: group reports "two owned" by player' );
ok( $group->monopoly, 'After purchase: constitutes monopoly' );

# mortgaging
$tile->mortgage;
ok( $tile->mortgaged, 'After mortgage: tile reports that it is mortgaged' );
ok( ! $group->monopoly, 'After mortgage: group is not a monopoly' );
is( $player->money, $money+=$price/2, 'Mortgage returns money to the owner' );

$tile->unmortgage;
ok( ! $tile->mortgaged, 'After unmortgage: tile reports that it is not mortgaged' );
ok( $group->monopoly, 'After unmortgage: group is a monopoly' );
is( $player->money, $money-=1.1*$price/2, 'Unmortgage removes money from the owner' );

done_testing;

Expand Down

0 comments on commit 05c076d

Please sign in to comment.