Skip to content

Commit a1655d5

Browse files
committed
Added tests for victory points and the buyCard function
1 parent 5545a84 commit a1655d5

File tree

2 files changed

+146
-3
lines changed

2 files changed

+146
-3
lines changed

tests/test_GameBoard.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,21 @@ TEST(canRobberRob){
338338
}
339339
**/
340340

341+
TEST(GameBoardTest, buyCard){
342+
GameBoard test_board({"tester1"});
343+
Player& test_player = test_board.getPlayer(0);
344+
345+
ASSERT_TRUE(test_player.getDevCardsInHand() == 0);
346+
test_board.buyCard(test_player);
347+
ASSERT_TRUE(test_player.getDevCardsInHand() == 0);
348+
349+
test_player.addOre(1);
350+
test_player.addWheat(1);
351+
test_player.addWool(1);
352+
353+
test_board.buyCard(test_player);
354+
ASSERT_TRUE(test_player.getDevCardsInHand() == 1);
355+
}
341356

342357

343358

tests/test_Player.cpp

Lines changed: 131 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,141 @@ 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){
234+
GameBoard test_board({"tester"});
235+
Player& test_player = test_board.getPlayer(0);
232236

233-
//INSERT VICTORY POINT TESTS HERE
237+
ASSERT_TRUE(test_player.getVictoryPoints() == 0);
234238

239+
Coordinate start1(0,0);
240+
test_board.PlaceSettlement(start1, test_player);
235241

236-
//INSERT DEV CARD TESTS HERE
242+
ASSERT_TRUE(test_player.getVictoryPoints() == 1);
243+
}
244+
245+
TEST(PlayerTest, UpdateVictoryPoints_cities){
246+
GameBoard test_board({"tester"});
247+
Player& test_player = test_board.getPlayer(0);
248+
249+
ASSERT_TRUE(test_player.getVictoryPoints() == 0);
250+
251+
Coordinate start1(0,0);
252+
test_board.PlaceSettlement(start1, test_player);
253+
254+
ASSERT_TRUE(test_player.getVictoryPoints() == 1);
255+
256+
test_board.UpgradeSettlement(start1);
257+
ASSERT_TRUE(test_player.getVictoryPoints() == 2);
258+
}
259+
260+
TEST(PlayerTest, UpdateVictoryPoints_longestRoad){
261+
GameBoard test_board({"tester"});
262+
Player& test_player = test_board.getPlayer(0);
263+
264+
ASSERT_TRUE(test_player.getVictoryPoints() == 0);
265+
266+
Coordinate start1(0,0);
267+
test_board.PlaceSettlement(start1, test_player);
268+
269+
ASSERT_TRUE(test_player.getVictoryPoints() == 1);
270+
271+
test_board.PlaceRoad(start1, Coordinate(-1,1), test_player);
272+
test_board.PlaceRoad(Coordinate(-1,1), Coordinate(-1,2), test_player);
273+
test_board.PlaceRoad(Coordinate(-1,2), Coordinate(0,2), test_player);
274+
test_board.PlaceRoad(Coordinate(0,2), Coordinate(0,3), test_player);
275+
test_board.PlaceRoad(Coordinate(0,3), Coordinate(1,3), test_player);
276+
277+
ASSERT_TRUE(test_player.getVictoryPoints() == 3);
278+
}
279+
280+
TEST(PlayerTest, UpdateVictoryPoints_VictoryCards){
281+
GameBoard test_board({"tester"});
282+
Player& test_player = test_board.getPlayer(0);
283+
284+
ASSERT_TRUE(test_player.getVictoryPoints() == 0);
285+
ASSERT_TRUE(test_player.getVictoryPointsWithoutCards() == 0);
237286

287+
std::unique_ptr<DevelopmentCard> test_VictoryCard = std::unique_ptr<DevelopmentCard>(new VictoryPointCard());
288+
test_player.addOre(1);
289+
test_player.addWheat(1);
290+
test_player.addWool(1);
238291

239-
//INSERT TRADING TESTS HERE
292+
test_player.buyCard(test_VictoryCard);
293+
ASSERT_TRUE(test_player.getVictoryPoints() == 1);
294+
ASSERT_TRUE(test_player.getVictoryPointsWithoutCards() == 0);
295+
}
296+
297+
TEST(PlayerTest, UpdateVictoryPoints_LargestArmy){
298+
GameBoard test_board({"tester1", "tester2"});
299+
Player& test_player = test_board.getPlayer(0);
300+
Player& opponent = test_board.getPlayer(1);
301+
302+
ASSERT_TRUE(test_player.getVictoryPoints() == 0);
303+
304+
test_player.addOre(3);
305+
test_player.addWheat(3);
306+
test_player.addWool(3);
307+
308+
std::unique_ptr<DevelopmentCard> test_KnightCard = std::unique_ptr<DevelopmentCard>(new KnightCard());
309+
test_player.buyCard(test_KnightCard);
310+
test_player.buyCard(test_KnightCard);
311+
test_player.buyCard(test_KnightCard);
312+
313+
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);
320+
}
321+
322+
TEST(PlayerTest, UpdateVictoryPoints_all){
323+
GameBoard test_board({"tester", "opponent"});
324+
Player& test_player = test_board.getPlayer(0);
325+
Player& opponent = test_board.getPlayer(1);
326+
327+
ASSERT_TRUE(test_player.getVictoryPoints() == 0);
328+
329+
Coordinate start1(0,0);
330+
331+
test_board.PlaceSettlement(start1, test_player);
332+
333+
ASSERT_TRUE(test_player.getVictoryPoints() == 1);
240334

335+
test_board.PlaceRoad(start1, Coordinate(-1,1), test_player);
336+
test_board.PlaceRoad(Coordinate(-1,1), Coordinate(-1,2), test_player);
337+
test_board.PlaceRoad(Coordinate(-1,2), Coordinate(0,2), test_player);
338+
test_board.PlaceRoad(Coordinate(0,2), Coordinate(0,3), test_player);
339+
test_board.PlaceRoad(Coordinate(0,3), Coordinate(1,3), test_player);
340+
341+
ASSERT_TRUE(test_player.getVictoryPoints() == 3);
342+
343+
test_board.UpgradeSettlement(start1);
344+
345+
ASSERT_TRUE(test_player.getVictoryPoints() == 4);
346+
347+
std::unique_ptr<DevelopmentCard> test_VictoryCard = std::unique_ptr<DevelopmentCard>(new VictoryPointCard());
348+
test_player.addOre(4);
349+
test_player.addWheat(4);
350+
test_player.addWool(4);
351+
352+
test_player.buyCard(test_VictoryCard);
353+
ASSERT_TRUE(test_player.getVictoryPoints() == 5);
354+
355+
std::unique_ptr<DevelopmentCard> test_KnightCard = std::unique_ptr<DevelopmentCard>(new KnightCard());
356+
test_player.buyCard(test_KnightCard);
357+
test_player.buyCard(test_KnightCard);
358+
test_player.buyCard(test_KnightCard);
359+
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);
368+
}
241369

0 commit comments

Comments
 (0)