1 2 3 4 5 6 7 8 | TEST_F(TicTacToeTestFixture,IWantAGameBoard) { IGameBoard *gameBoard=NULL; EXPECT_NO_THROW(gameBoard=new SimpleGameBoard("simpleGame")); EXPECT_TRUE(gameBoard!=NULL); EXPECT_NO_THROW(delete gameBoard); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | virtual void PutChess(int x,int y,char chess)=0; virtual char GetChess(int x,int y)=0 ; 有了这个思路,我想这样设计这个测试用例: TEST_F(TicTacToeTestFixture,PutandGetChess) { char xChess='X'; char yChess='Y'; IGameBoard *gameBoard=new SimpleGameBoard("simpleBoard"); gameBoard->utChess(0,0,xChess); gameBoard->utChess(2,2,yChess); EXPECT_EQ(xChess,gameBoard->GetChess(0,0)); EXPECT_EQ(yChess,gameBoard->GetChess(2,2)); 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; } char SimpleGameBoard::GetChess( int x,int y ) { assert(x<xMaxDim&&y<yMaxDim); assert(data_.size()==yMaxDim*xMaxDim); return data_[x*3+y]; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | TEST_F(TicTacToeTestFixture,JugeThreeInLine) { IGameBoard *gameBoard=new SimpleGameBoard("simpleBoard"); IGameBoard *gameBoard2=new SimpleGameBoard("simpleboard2"); char xChess='x',yChess='o'; gameBoard->utChess(0,0,xChess); gameBoard2->utChess(0,1,yChess); gameBoard->utChess(1,1,xChess); gameBoard2->utChess(1,1,yChess); gameBoard->utChess(2,2,xChess); gameBoard2->utChess(2,1,yChess); EXPECT_TRUE(gameBoard->CheckWinOut(xChess)); EXPECT_TRUE(gameBoard2->CheckWinOut(yChess)); EXPECT_FALSE(gameBoard->CheckWinOut(yChess)); EXPECT_FALSE(gameBoard2-)CheckWinOut(xChess)); delete gameBoard; delete gameBoard2; } |
1 2 3 4 | bool SimpleGameBoard::CheckWinOut(char chess) { return IsThreeInLine_(chess); } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |