From 9b000300390e1418d3407273431613683038b0f3 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Tue, 16 Dec 2014 13:13:01 +0000 Subject: [PATCH] More tests --- game/game.cpp | 6 ++++++ test/test.cpp | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/game/game.cpp b/game/game.cpp index 701d6ed..8cf47d3 100644 --- a/game/game.cpp +++ b/game/game.cpp @@ -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; } diff --git a/test/test.cpp b/test/test.cpp index b236270..beb65bd 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -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;