1 2 3 4 5 6 7 8 9 10 | TEST_F(TicTacToeTestFixture,BizException_Occupied){ IGameBoard *gameBoard=new SimpleGameBoard("simple board"); char xChar='X',yChar='0'; EXPECT_NO_THROW(gameBoard->utChess(0,0,xChar)); EXPECT_THROW(gameBoard->utChess(0,0,xChar),ChessOverlapException); EXPECT_NO_THROW(gameBoard->utChess(2,2,yChar)); EXPECT_THROW(gameBoard->utChess(2,2,yChar),ChessOverlapException); delete gameBoard; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | void SimpleGameBoard:utChess( int x,int y,char chess ) { assert(x<xMaxDim&&y<yMaxDim); int xy=x*3+y; if(data_.size()==0){ initboard_(); data_[xy]=chess; return ; } if(data_[xy]!='+') { throw ChessOverlapException("chess overlap!"); } else data_[xy]=chess; } |
1 2 3 4 5 6 7 8 9 10 11 12 | EST_F(TicTacToeTestFixture,IsEndedInADraw) { char xChess='X',yChess='O'; IGameBoard *gameBoard=new SimpleGameBoard("simpleBoard"); gameBoard->utChess(0,0,yChess);gameBoard->utChess(0,1,xChess);gameBoard->utChess(0,2,yChess); gameBoard->utChess(1,0,xChess);gameBoard->utChess(1,1,yChess);gameBoard->utChess(1,2,yChess); gameBoard->PutChess(2,0,xChess);gameBoard->PutChess(2,1,yChess);gameBoard->PutChess(2,2,xChess); GameBoardStatus status=gameBoard->CheckWinOut(yChess); EXPECT_TRUE(status==GAMEDRAW); <br>GameBoardStatus status2=gameBoard->CheckWinOut(xChess); EXPECT_TRUE(status2==GAMEDRAW); delete gameBoard; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 | GameBoardStatus SimpleGameBoard::CheckWinOut(char chess) { if(IsThreeInLine_(chess)){ return GAMEMWINOUT; } else if(IsEndedInADraw_()){ return GAMEDRAW; } else{ return GAMERUNNING; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | TEST_F(TicTacToeTestFixture,SaveTheBoard) { IGameBoard * gameBoard=new SimpleGameBoard("simpleBoard"); char xChess='x',yChess='o'; gameBoard->PutChess(0,0,xChess); gameBoard->PutChess(1,2,yChess); IGameIO *gameIO=new SimpleGameIO(); EXPECT_NO_THROW(gameIO->save(gameBoard,"somewhere")); delete gameBoard; delete gameIO; } TEST_F(TicTacToeTestFixture,LoadTheBoard) { IGameBoard * gameBoard=new SimpleGameBoard("simpleBoard"); char xChess='x',yChess='o'; gameBoard->PutChess(0,0,xChess); gameBoard->PutChess(1,2,yChess); IGameIO *gameIO=new SimpleGameIO(); EXPECT_NO_THROW(gameIO->save(gameBoard,"somewhere")); IGameBoard *game=gameIO->load("somewhere"); EXPECT_EQ(xChess,game->GetChess(0,0)); EXPECT_EQ(yChess,game->GetChess(1,2)); EXPECT_EQ('+',game->GetChess(2,2)); delete game; |
1 2 3 | delete gameBoard; delete gameIO; } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |