Framework for movement and action orders, plus some better organisation of the test code

This commit is contained in:
Marc Di Luzio 2014-12-16 13:13:00 +00:00
parent 008739dee6
commit 72b35dbc06
5 changed files with 115 additions and 44 deletions

View file

@ -4,69 +4,73 @@
#include "board.h"
#include "orders.h"
// Namespace for testing functions
namespace tests
const char* tests()
{
// print a board
void debug_print( CBoard& b )
{
for ( unsigned int r = 0; r < b.rows; r++ )
{
for ( unsigned int c = 0; c < b.cols; c++ )
{
std::cout<<(char)(b.get(c,r));
}
std::cout<<std::endl;
}
}
// Test the board data class
void test_CBoard()
{
CBoard board = CBoard(10,5);
std::cout<<"Blank board"<<std::endl;
board.clear();
debug_print(board);
std::cout<<"Filled board"<<std::endl;
board.fill(48);
debug_print(board);
}
};
// Main program entry point
int main()
{
tests::test_CBoard();
{
std::cout<<"Basic V unit construction"<<std::endl;
CUnitV myV;
std::cout<<myV.getVisual()<<std::endl;
if( myV.getVisual() != 'v' && myV.getVisual() != '<' && myV.getVisual() != '^' && myV.getVisual() != '>' )
return "failed to properly create V unit";
}
{
std::cout<<"CUnit factory V unit construction"<<std::endl;
std::unique_ptr<CUnit> myV = CUnit::getUnitFromVis('v');
if( myV->getVisual() != 'v' )
std::cout<<"ERROR, failed to properly create V unit"<<std::endl;
return "failed to properly create V unit";
}
{
std::cout<<"COrder construction and conversion"<<std::endl;
COrder order;
order.order = 'F';
order.unit = 10;
std::string order_string = GetStringFromOrder(order);
std::cout<<order_string<<std::endl;
COrder order2 = GetOrderFromString(order_string);
if ( order2 != order )
std::cout<<"ERROR, failed order string conversion test"<<std::endl;
return "failed order string conversion test";
}
{
COrder order;
order.order = 'F';
if (!isMovementOrder(order) )
return "Failed to detect a movement order";
if (isActionOrder(order) )
return "Wrongly detected an action order";
}
{
COrder order;
order.order = 'L';
if (! isActionOrder(order) )
return "Failed to detect a action order";
if (isMovementOrder(order) )
return "Wrongly detected an movement order";
}
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;
};