ttrts/test/test.cpp
Marc Di Luzio aee703b107 Finialise the full game step
Had to rework a ton of code from bad design.
NOTE: FRIENDLY FIRE IS ON >:D
2014-12-16 13:13:01 +00:00

117 lines
2.2 KiB
C++

#include <iostream> // std::cout
#include "board.h"
#include "orders.h"
#include "game.h"
const char* tests()
{
{
CBoard board = CBoard(10,5);
board.clear();
board.fill(48);
}
{
CUnit unit;
unit.setFromVisual('v');
if( unit.getVisual() != 118 )
return "failed to properly create V unit";
}
{
CUnit unit;
CUnit unit2;
if( unit.getID() == unit2.getID() )
return "Unit IDs the same";
}
{
CUnit unit = CUnit::getUnitFromVis('v');
if( unit.getVisual() != 'v' )
return "failed to properly create V unit with factory";
}
{
COrder order;
order.order = order_c::F;
order.unit = 10;
std::string order_string = GetStringFromOrder(order);
COrder order2 = GetOrderFromString(order_string);
if ( order2 != order )
return "failed order string conversion test";
}
{
COrder order;
order.order = order_c::F;
if (!isMovementOrder(order) )
return "Failed to detect a movement order";
if (isActionOrder(order) )
return "Wrongly detected an action order";
}
{
COrder order;
order.order = order_c::A;
if (! isActionOrder(order) )
return "Failed to detect a action order";
if (isMovementOrder(order) )
return "Wrongly detected an movement order";
}
{
CTTRTSGame game( 15, 10 );
if( game.SimulateToNextTurn() )
return "Failed to simulate a blank game";
if( game.GetNumUnits() )
return "Game started with non-zero unit number";
}
{
CTTRTSGame game( 5, 5 );
CUnit unit = CUnit::getUnitFromVis('>');
const unit_id_t id = unit.getID();
COrder order;
unit.setPos( {2,2} );
unit.setPlayer(0);
game.AddUnit(std::move(unit));
order.unit = id;
order.order = order_c::F;
game.IssueOrder(0,order);
game.SimulateToNextTurn();
if( game.GetUnitByIDConst(id).getPos() != uvector2{3,2} )
return "Simple movement order failed";
}
return nullptr;
}
// Main program entry point
int main()
{
std::cout<<"Running tests"<<std::endl;
const char* res = tests();
if( res )
{
std::cout<<"Tests failed - "<<res<<std::endl;
return -1;
}
std::cout<<"Tests succeeded"<<std::endl;
return 0;
};