Skip to content

Commit bdad9fd

Browse files
committed
Added tests, hopefully I did it right
1 parent 86a7991 commit bdad9fd

File tree

3 files changed

+57
-47
lines changed

3 files changed

+57
-47
lines changed

tests/test_DevelopmentCards.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ void testKnightCard(Player& test_player, bool correct_result, GameBoard& test_bo
253253

254254
}
255255

256+
256257
TEST(DevCardTest, KnightCard){
257258
GameBoard test_board({"tester1", "tester2", "tester3"});
258259
Player& test_player1 = test_board.getPlayer(0);
@@ -261,19 +262,20 @@ TEST(DevCardTest, KnightCard){
261262

262263
std::unique_ptr<DevelopmentCard> test_card = std::unique_ptr<DevelopmentCard>(new KnightCard());
263264

264-
test_player1.addOre(3);
265-
test_player1.addWheat(3);
266-
test_player1.addWool(3);
265+
test_player1.addOre(4);
266+
test_player1.addWheat(4);
267+
test_player1.addWool(4);
268+
test_player1.buyCard(test_card);
267269
test_player1.buyCard(test_card);
268270
test_player1.buyCard(test_card);
269271
test_player1.buyCard(test_card);
270272

271273
test_board.moveRobber(Coordinate(0,1));
272274

273275
testKnightCard(test_player1, false, test_board, Coordinate(0,4), test_player2, 0);
274-
/**DOES NOT WORK BECAUSE getNeighboringCorners() does not work
275276
test_player2.addWood(1);
276277
test_board.PlaceSettlement(Coordinate(0,3), test_player2);
278+
testKnightCard(test_player1, true, test_board, Coordinate(0,4), test_player1, 0);
277279
testKnightCard(test_player1, true, test_board, Coordinate(0,4), test_player2, 1);
278280

279281
test_player3.addWood(1);
@@ -282,7 +284,6 @@ TEST(DevCardTest, KnightCard){
282284
testKnightCard(test_player1, true, test_board, Coordinate(0,1), test_player3, 1);
283285

284286
testKnightCard(test_player1, true, test_board, Coordinate(0,4), test_player2, 0);
285-
**/
286287

287288
testKnightCard(test_player1, false, test_board, Coordinate(0,4), test_player3, 0);
288289
}
@@ -300,8 +301,3 @@ TEST(DevCardTest, KnightCard){
300301

301302

302303

303-
304-
305-
306-
307-

tests/test_GameBoard.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,20 +338,33 @@ TEST(canRobberRob){
338338
}
339339
**/
340340

341+
TEST(GameBoardTest, canRobberRob){
342+
GameBoard test_board({"tester1", "tester2"});
343+
Player& test_player1 = test_board.getPlayer(0);
344+
Player& test_player2 = test_board.getPlayer(1);
345+
346+
347+
ASSERT_FALSE(test_board.canRobberRob(test_player1, Coordinate(0,1)));
348+
349+
test_board.PlaceSettlement(Coordinate(0,0), test_player1);
350+
ASSERT_TRUE(test_board.canRobberRob(test_player1, Coordinate(0,1)));
351+
}
352+
353+
341354
TEST(GameBoardTest, buyCard){
342355
GameBoard test_board({"tester1"});
343356
Player& test_player = test_board.getPlayer(0);
344357

345-
ASSERT_TRUE(test_player.getDevCardsInHand() == 0);
358+
CHECK(test_player.getDevCardsInHand() == 0);
346359
test_board.buyCard(test_player);
347-
ASSERT_TRUE(test_player.getDevCardsInHand() == 0);
360+
ASSERT_EQ(test_player.getDevCardsInHand(), 0);
348361

349362
test_player.addOre(1);
350363
test_player.addWheat(1);
351364
test_player.addWool(1);
352365

353366
test_board.buyCard(test_player);
354-
ASSERT_TRUE(test_player.getDevCardsInHand() == 1);
367+
ASSERT_EQ(test_player.getDevCardsInHand(), 1);
355368
}
356369

357370

tests/test_Player.cpp

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -229,77 +229,78 @@ TEST(PlayerTest, Buy_DevCard_False){
229229
ASSERT_TRUE(validateResourceAmount(1,1,0,1,1,tp));
230230
}
231231

232-
//VICTORY POINT TESTS HERE
233-
TEST(PlayerTest, PlayerTest, UpdateVictoryPoints_Settlements){
232+
233+
//INSERT VICTORY POINT TESTS HERE
234+
TEST(PlayerTest, UpdateVictoryPoints_Settlements){
234235
GameBoard test_board({"tester"});
235236
Player& test_player = test_board.getPlayer(0);
236237

237-
ASSERT_TRUE(test_player.getVictoryPoints() == 0);
238+
ASSERT_EQ(test_player.getVictoryPoints(), 0);
238239

239240
Coordinate start1(0,0);
240241
test_board.PlaceSettlement(start1, test_player);
241242

242-
ASSERT_TRUE(test_player.getVictoryPoints() == 1);
243+
ASSERT_EQ(test_player.getVictoryPoints(), 1);
243244
}
244245

245246
TEST(PlayerTest, UpdateVictoryPoints_cities){
246247
GameBoard test_board({"tester"});
247248
Player& test_player = test_board.getPlayer(0);
248249

249-
ASSERT_TRUE(test_player.getVictoryPoints() == 0);
250+
ASSERT_EQ(test_player.getVictoryPoints(), 0);
250251

251252
Coordinate start1(0,0);
252253
test_board.PlaceSettlement(start1, test_player);
253254

254-
ASSERT_TRUE(test_player.getVictoryPoints() == 1);
255+
ASSERT_EQ(test_player.getVictoryPoints(), 1);
255256

256257
test_board.UpgradeSettlement(start1);
257-
ASSERT_TRUE(test_player.getVictoryPoints() == 2);
258+
ASSERT_EQ(test_player.getVictoryPoints(), 2);
258259
}
259260

260261
TEST(PlayerTest, UpdateVictoryPoints_longestRoad){
261262
GameBoard test_board({"tester"});
262263
Player& test_player = test_board.getPlayer(0);
263264

264-
ASSERT_TRUE(test_player.getVictoryPoints() == 0);
265+
ASSERT_EQ(test_player.getVictoryPoints(), 0);
265266

266267
Coordinate start1(0,0);
267268
test_board.PlaceSettlement(start1, test_player);
268269

269-
ASSERT_TRUE(test_player.getVictoryPoints() == 1);
270+
ASSERT_EQ(test_player.getVictoryPoints(), 1);
270271

271272
test_board.PlaceRoad(start1, Coordinate(-1,1), test_player);
272273
test_board.PlaceRoad(Coordinate(-1,1), Coordinate(-1,2), test_player);
273274
test_board.PlaceRoad(Coordinate(-1,2), Coordinate(0,2), test_player);
274275
test_board.PlaceRoad(Coordinate(0,2), Coordinate(0,3), test_player);
275276
test_board.PlaceRoad(Coordinate(0,3), Coordinate(1,3), test_player);
276277

277-
ASSERT_TRUE(test_player.getVictoryPoints() == 3);
278+
ASSERT_EQ(test_player.getVictoryPoints(), 3);
278279
}
279280

280281
TEST(PlayerTest, UpdateVictoryPoints_VictoryCards){
281282
GameBoard test_board({"tester"});
282283
Player& test_player = test_board.getPlayer(0);
283284

284-
ASSERT_TRUE(test_player.getVictoryPoints() == 0);
285-
ASSERT_TRUE(test_player.getVictoryPointsWithoutCards() == 0);
285+
ASSERT_EQ(test_player.getVictoryPoints(), 0);
286+
ASSERT_EQ(test_player.getVictoryPointsWithoutCards(), 0);
286287

287288
std::unique_ptr<DevelopmentCard> test_VictoryCard = std::unique_ptr<DevelopmentCard>(new VictoryPointCard());
288289
test_player.addOre(1);
289290
test_player.addWheat(1);
290291
test_player.addWool(1);
291292

292293
test_player.buyCard(test_VictoryCard);
293-
ASSERT_TRUE(test_player.getVictoryPoints() == 1);
294-
ASSERT_TRUE(test_player.getVictoryPointsWithoutCards() == 0);
294+
ASSERT_EQ(test_player.getVictoryPoints(), 1);
295+
ASSERT_EQ(test_player.getVictoryPointsWithoutCards(), 0);
295296
}
296297

297298
TEST(PlayerTest, UpdateVictoryPoints_LargestArmy){
298299
GameBoard test_board({"tester1", "tester2"});
299300
Player& test_player = test_board.getPlayer(0);
300301
Player& opponent = test_board.getPlayer(1);
301302

302-
ASSERT_TRUE(test_player.getVictoryPoints() == 0);
303+
ASSERT_EQ(test_player.getVictoryPoints(), 0);
303304

304305
test_player.addOre(3);
305306
test_player.addWheat(3);
@@ -311,59 +312,59 @@ TEST(PlayerTest, UpdateVictoryPoints_LargestArmy){
311312
test_player.buyCard(test_KnightCard);
312313

313314
test_board.PlaceSettlement(Coordinate(0,0), opponent);
314-
// WILL NOT WORK UNTIL THE KNIGHT WORKS
315-
// test_player.playKnight(Coordinate(0,1), opponent);
316-
// test_player.playKnight(Coordinate(0,1), opponent);
317-
// test_player.playKnight(Coordinate(0,1), opponent);
318-
//
319-
// ASSERT_TRUE(test_player.getVictoryPoints() == 2);
315+
316+
test_player.playKnight(Coordinate(0,1), opponent);
317+
test_player.playKnight(Coordinate(0,1), opponent);
318+
test_player.playKnight(Coordinate(0,1), opponent);
319+
320+
ASSERT_EQ(test_player.getVictoryPoints(), 2);
320321
}
321322

322323
TEST(PlayerTest, UpdateVictoryPoints_all){
323324
GameBoard test_board({"tester", "opponent"});
324325
Player& test_player = test_board.getPlayer(0);
325326
Player& opponent = test_board.getPlayer(1);
326327

327-
ASSERT_TRUE(test_player.getVictoryPoints() == 0);
328+
ASSERT_EQ(test_player.getVictoryPoints(), 0);
328329

329330
Coordinate start1(0,0);
330331

331332
test_board.PlaceSettlement(start1, test_player);
332333

333-
ASSERT_TRUE(test_player.getVictoryPoints() == 1);
334+
ASSERT_EQ(test_player.getVictoryPoints(), 1);
334335

335336
test_board.PlaceRoad(start1, Coordinate(-1,1), test_player);
336337
test_board.PlaceRoad(Coordinate(-1,1), Coordinate(-1,2), test_player);
337338
test_board.PlaceRoad(Coordinate(-1,2), Coordinate(0,2), test_player);
338339
test_board.PlaceRoad(Coordinate(0,2), Coordinate(0,3), test_player);
339340
test_board.PlaceRoad(Coordinate(0,3), Coordinate(1,3), test_player);
340341

341-
ASSERT_TRUE(test_player.getVictoryPoints() == 3);
342+
ASSERT_EQ(test_player.getVictoryPoints(), 3);
342343

343344
test_board.UpgradeSettlement(start1);
344345

345-
ASSERT_TRUE(test_player.getVictoryPoints() == 4);
346+
ASSERT_EQ(test_player.getVictoryPoints(), 4);
346347

347348
std::unique_ptr<DevelopmentCard> test_VictoryCard = std::unique_ptr<DevelopmentCard>(new VictoryPointCard());
348349
test_player.addOre(4);
349350
test_player.addWheat(4);
350351
test_player.addWool(4);
351352

352353
test_player.buyCard(test_VictoryCard);
353-
ASSERT_TRUE(test_player.getVictoryPoints() == 5);
354+
ASSERT_EQ(test_player.getVictoryPoints(), 5);
354355

355356
std::unique_ptr<DevelopmentCard> test_KnightCard = std::unique_ptr<DevelopmentCard>(new KnightCard());
356357
test_player.buyCard(test_KnightCard);
357358
test_player.buyCard(test_KnightCard);
358359
test_player.buyCard(test_KnightCard);
359360

360-
// WILL NOT WORK UNTIL THE KNIGHT WORKS
361-
// test_board.PlaceSettlement(Coordinate(0,6), opponent);
362-
//
363-
// test_player.playKnight(Coordinate(0,5), opponent);
364-
// test_player.playKnight(Coordinate(0,5), opponent);
365-
// test_player.playKnight(Coordinate(0,5), opponent);
366-
//
367-
// ASSERT_TRUE(test_player.getVictoryPoints() == 7);
361+
test_board.PlaceSettlement(Coordinate(0,5), opponent);
362+
363+
test_player.playKnight(Coordinate(0,4), opponent);
364+
test_player.playKnight(Coordinate(0,4), opponent);
365+
test_player.playKnight(Coordinate(0,4), opponent);
366+
367+
ASSERT_EQ(test_player.getVictoryPoints(), 7);
368368
}
369369

370+

0 commit comments

Comments
 (0)