Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
began a property tile-type test file
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
|
||
use Opoly::UI::Test; | ||
use Opoly::Player; | ||
use Opoly::Board::Group; | ||
|
||
use_ok( 'Opoly::Board::Tile' ); | ||
|
||
my $ui = Opoly::UI::Test->new(); | ||
my $player = Opoly::Player->new( name => 'John Doe', ui => $ui ); | ||
my $money = $player->money; | ||
|
||
my $houses_cost = 50; | ||
my $group = Opoly::Board::Group::Property->new( | ||
name => 'Test Group', | ||
houses_cost => $houses_cost, | ||
); | ||
|
||
my $price = 100; | ||
my $rent = [20, 50, 100, 200, 300, 500]; | ||
my $tile = Opoly::Board::Tile::Property->new( | ||
rent => $rent, | ||
price => $price, | ||
name => 'Test Tile', | ||
group => $group, | ||
address => 1, | ||
); | ||
|
||
isa_ok( $tile, 'Opoly::Board::Tile' ); | ||
isa_ok( $tile, 'Opoly::Board::Tile::Ownable' ); | ||
isa_ok( $tile, 'Opoly::Board::Tile::Property' ); | ||
is( $group->tiles->[0], $tile, 'The tile object exists in the groups\'s tiles arrayref' ); | ||
ok( ! $group->monopoly, 'Group is not a monopoly' ); | ||
|
||
$tile->arrive( $player ); | ||
is( $player->location, $tile, 'Player reports arriving at tile' ); | ||
is( $tile->occupants->[0], $player, 'Tile reports having player in its occupants arrayref' ); | ||
like( (grep { /^Buy/ } keys %{ $player->actions })[0], qr/^Buy/, 'Arrival at ownable tile adds buy action to player' ); | ||
|
||
$tile->leave( $player ); | ||
ok( ! $player->location, 'After leave, player has no location' ); | ||
ok( ! @{ $tile->occupants }, '... and the tile has no occupants' ); | ||
ok( ! (grep { /^Buy/ } keys %{ $player->actions }), 'Leaving ownable tile removes buy action from player' ); | ||
|
||
$tile->buy($player); | ||
ok( $tile->has_owner, 'After purchase: tile reports having an owner' ); | ||
is( $tile->owner, $player, 'After purchase: owner is correct' ); | ||
ok( (grep {$_ == $tile} @{ $player->properties }), 'After purchase: player reports tile in properties' ); | ||
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 constitute monopoly' ); | ||
|
||
# mortgaging | ||
$tile->mortgage; | ||
|
||
|
||
done_testing; | ||
|
||
|