More tests
This commit is contained in:
parent
aee703b107
commit
9b00030039
2 changed files with 38 additions and 3 deletions
|
@ -210,9 +210,15 @@ int CTTRTSGame::AddUnit( CUnit&& unit )
|
|||
if( (pos.x >= dimentions.x) || (pos.y >= dimentions.y) )
|
||||
return 1;
|
||||
|
||||
for ( const OrderUnitPair& pair: m_OrderUnitPairs )
|
||||
{
|
||||
if( pair.unit.getPos() == unit.getPos() )
|
||||
return 2;
|
||||
}
|
||||
// Add the unit with a blank order
|
||||
m_OrderUnitPairs.push_back( OrderUnitPair(std::move(unit), COrder()) );
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,18 +82,47 @@ const char* tests()
|
|||
unit.setPos( {2,2} );
|
||||
unit.setPlayer(0);
|
||||
|
||||
game.AddUnit(std::move(unit));
|
||||
if ( game.AddUnit(std::move(unit)) )
|
||||
return "Game failed to add valid unit";
|
||||
|
||||
order.unit = id;
|
||||
order.order = order_c::F;
|
||||
|
||||
game.IssueOrder(0,order);
|
||||
if( game.IssueOrder(0,order) )
|
||||
return "Game failed to issue valid order";
|
||||
|
||||
game.SimulateToNextTurn();
|
||||
if (game.SimulateToNextTurn() )
|
||||
return "Game failed to simulate valid turn";
|
||||
|
||||
if( game.GetUnitByIDConst(id).getPos() != uvector2{3,2} )
|
||||
return "Simple movement order failed";
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
CTTRTSGame game( 5, 5 );
|
||||
|
||||
{
|
||||
CUnit unit = CUnit::getUnitFromVis('^');
|
||||
unit.setPos( {2,2} );
|
||||
unit.setPlayer(0);
|
||||
|
||||
game.AddUnit(std::move(unit));
|
||||
}
|
||||
|
||||
{
|
||||
CUnit unit = CUnit::getUnitFromVis('^');
|
||||
unit.setPos( {2,2} );
|
||||
unit.setPlayer(0);
|
||||
|
||||
if( !game.AddUnit(std::move(unit)) )
|
||||
return "Game should have rejected unit placed on the same spot";
|
||||
|
||||
if( game.GetNumUnits() != 1 )
|
||||
return "Game ended up with too many units";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue