Added several assertions

This commit is contained in:
Olivier Teulière 2012-02-19 12:26:44 +01:00
parent 32957abfcc
commit 66eec913c9
3 changed files with 32 additions and 1 deletions

View file

@ -159,12 +159,18 @@ void Board::addRound(const Dictionary &iDic, const Round &iRound)
{
if (isVacant(row, col + i))
{
ASSERT(iRound.isPlayedFromRack(i), "Invalid round (1)");
t = iRound.getTile(i);
m_tilesRow[row][col + i] = t;
m_jokerRow[row][col + i] = iRound.isJoker(i);
m_tilesCol[col + i][row] = t;
m_jokerCol[col + i][row] = iRound.isJoker(i);
}
else
{
ASSERT(!iRound.isPlayedFromRack(i), "Invalid round (2)");
ASSERT(t == m_tilesRow[row][col + i].toUpper(), "Invalid round (3)");
}
}
}
else
@ -174,12 +180,18 @@ void Board::addRound(const Dictionary &iDic, const Round &iRound)
{
if (isVacant(row + i, col))
{
ASSERT(iRound.isPlayedFromRack(i), "Invalid round (1)");
t = iRound.getTile(i);
m_tilesRow[row + i][col] = t;
m_jokerRow[row + i][col] = iRound.isJoker(i);
m_tilesCol[col][row + i] = t;
m_jokerCol[col][row + i] = iRound.isJoker(i);
}
else
{
ASSERT(!iRound.isPlayedFromRack(i), "Invalid round (2)");
ASSERT(t == m_tilesRow[row + i][col].toUpper(), "Invalid round (3)");
}
}
}
buildCross(iDic);
@ -206,6 +218,8 @@ void Board::removeRound(const Dictionary &iDic, const Round &iRound)
"Invalid round removal");
if (iRound.isPlayedFromRack(i))
{
ASSERT(iRound.isJoker(i) == m_jokerRow[row][col + i],
"Invalid round removal");
m_tilesRow[row][col + i] = Tile();
m_jokerRow[row][col + i] = false;
m_crossRow[row][col + i].setAny();
@ -223,6 +237,8 @@ void Board::removeRound(const Dictionary &iDic, const Round &iRound)
"Invalid round removal");
if (iRound.isPlayedFromRack(i))
{
ASSERT(iRound.isJoker(i) == m_jokerRow[row + i][col],
"Invalid round removal");
m_tilesRow[row + i][col] = Tile();
m_jokerRow[row + i][col] = false;
m_crossRow[row + i][col].setAny();

View file

@ -26,6 +26,7 @@
#include "tile.h"
#include "round.h"
#include "encoding.h"
#include "debug.h"
INIT_LOGGER(game, Round);
@ -45,32 +46,44 @@ void Round::setWord(const vector<Tile> &iTiles)
}
void Round::setTile(unsigned int iIndex, const Tile &iTile)
{
ASSERT(iIndex < m_word.size(), "Invalid index");
m_word[iIndex] = iTile;
}
void Round::setFromRack(unsigned int iIndex)
{
ASSERT(iIndex < m_word.size(), "Invalid index");
m_rackOrigin[iIndex] = true;
}
void Round::setFromBoard(unsigned int iIndex)
{
ASSERT(iIndex < m_word.size(), "Invalid index");
m_rackOrigin[iIndex] = false;
}
bool Round::isJoker(unsigned int iIndex) const
{
ASSERT(iIndex < m_word.size(), "Invalid index");
return m_word[iIndex].isJoker();
}
const Tile& Round::getTile(unsigned int iIndex) const
{
ASSERT(iIndex < m_word.size(), "Invalid index");
return m_word[iIndex];
}
bool Round::isPlayedFromRack(unsigned int iIndex) const
{
ASSERT(iIndex < m_word.size(), "Invalid index");
return m_rackOrigin[iIndex];
}
@ -96,6 +109,8 @@ void Round::addRightFromRack(const Tile &iTile, bool iJoker)
void Round::removeRight()
{
ASSERT(!m_word.empty() && !m_rackOrigin.empty(),
"Trying to remove tiles that were never added");
m_word.pop_back();
m_rackOrigin.pop_back();
}

View file

@ -55,7 +55,7 @@ public:
*************************/
void setPoints(int iPoints) { m_points = iPoints; }
void setBonus(bool iBonus) { m_bonus = iBonus; }
void setTile(unsigned int iIndex, const Tile &iTile) { m_word[iIndex] = iTile; }
void setTile(unsigned int iIndex, const Tile &iTile);
void setWord(const vector<Tile> &iTiles);
void setFromRack(unsigned int iIndex);
void setFromBoard(unsigned int iIndex);