int main() { srand(time(NULL)); struct gameState G; struct gameState Gcopy; struct infosStruct infos; int k[] = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; int numPlayers = 4; int handCountBefore, handCountAfter; int deckCountBefore, deckCountAfter; int curPlayer, p1 = 0, p2 = 1, p3 = 2, p4 = 3; int i; G.numPlayers = numPlayers; G.whoseTurn = 0; infos.currentPlayer = 0; infos.handPos = 4; int handCount = 5; int deckCount = MAX_DECK - handCount; createRandomHand(G.hand[p1], handCount); createRandomHand(G.hand[p2], handCount); createRandomHand(G.hand[p3], handCount); createRandomHand(G.hand[p4], handCount); G.handCount[p1] = handCount; G.handCount[p2] = handCount; G.handCount[p3] = handCount; G.handCount[p4] = handCount; createRandomDeck(G.deck[p1], deckCount); createRandomDeck(G.deck[p2], deckCount); createRandomDeck(G.deck[p3], deckCount); createRandomDeck(G.deck[p4], deckCount); G.deckCount[p1] = deckCount; G.deckCount[p2] = deckCount; G.deckCount[p3] = deckCount; G.deckCount[p4] = deckCount; printf("handCount: %d\n", G.deckCount[p2]); setDiscardDeck(G.discard[p1], MAX_DECK); setDiscardDeck(G.discard[p2], MAX_DECK); setDiscardDeck(G.discard[p3], MAX_DECK); setDiscardDeck(G.discard[p4], MAX_DECK); G.discardCount[p1] = 0; G.discardCount[p2] = 0; G.discardCount[p3] = 0; G.discardCount[p4] = 0; memcpy (&Gcopy, &G, sizeof(G) ); curPlayer = p1; int nextPlayer = 1; printf("handCount: %d\n", G.handCount[0]); //check handCount and deckCount of current player handCountBefore = G.handCount[curPlayer]; deckCountBefore = G.deckCount[curPlayer]; effectCouncil(&G, &infos); handCountAfter = G.handCount[curPlayer]; deckCountAfter = G.deckCount[curPlayer]; //check state of other player(s) // printf("size: %d\n", G.deckCount[p1]); assert((Gcopy.deckCount[p1]-4) == G.deckCount[p1]); assert(Gcopy.deckCount[p2] == G.deckCount[p2]); assert(Gcopy.deckCount[p3] == G.deckCount[p3]); assert(Gcopy.deckCount[p4] == G.deckCount[p4]); printf("TEST: player 2 deck is unchanged\n"); for(i = 0; i < G.deckCount[p2]; i++) { assert(Gcopy.deck[p2][i] == G.deck[p2][i]); } printf("PASS"); printf("TEST: player 3 deck is unchanged\n"); for(i = 0; i < G.deckCount[p3]; i++) { assert(Gcopy.deck[p3][i] == G.deck[p3][i]); } printf("TEST: player 4 deck is unchanged\n"); for(i = 0; i < G.deckCount[p4]; i++) { assert(Gcopy.deck[p4][i] == G.deck[p4][i]); } printf("TEST: player 2 hand is unchanged\n"); for(i = 0; i < G.handCount[p2]; i++) { assert(Gcopy.hand[p2][i] == G.hand[p2][i]); } printf("TEST: player 3 hand is unchanged\n"); for(i = 0; i < G.handCount[p3]; i++) { assert(Gcopy.hand[p3][i] == G.hand[p3][i]); } printf("TEST: player 4 hand is unchanged\n"); for(i = 0; i < G.handCount[p4]; i++) { assert(Gcopy.hand[p4][i] == G.hand[p4][i]); } return 0; }
int main() { srand(time(NULL)); struct gameState G; struct infosStruct infos; int k[] = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; int numPlayers = 4; int handCountBefore, handCountAfter; int deckCountBefore, deckCountAfter; int curPlayer, p1 = 0, p2 = 1, p3 = 2, p4 = 3; int i; int seed = 1000; initializeGame(numPlayers, k, seed, &G); G.numPlayers = numPlayers; G.whoseTurn = 0; infos.currentPlayer = 0; infos.handPos = 4; int numActions1, numActions2; int numCards1, numCards2; int numDeck1, numDeck2; int numHand1, numHand2; int handCount = 5; int deckCount = MAX_DECK - handCount; createRandomHand(G.hand[p1], handCount); createRandomHand(G.hand[p2], handCount); createRandomHand(G.hand[p3], handCount); createRandomHand(G.hand[p4], handCount); G.handCount[p1] = handCount; G.handCount[p2] = handCount; G.handCount[p3] = handCount; G.handCount[p4] = handCount; createRandomDeck(G.deck[p1], deckCount); createRandomDeck(G.deck[p2], deckCount); createRandomDeck(G.deck[p3], deckCount); createRandomDeck(G.deck[p4], deckCount); G.deckCount[p1] = deckCount; G.deckCount[p2] = deckCount; G.deckCount[p3] = deckCount; G.deckCount[p4] = deckCount; setDiscardDeck(G.discard[p1], MAX_DECK); setDiscardDeck(G.discard[p2], MAX_DECK); setDiscardDeck(G.discard[p3], MAX_DECK); setDiscardDeck(G.discard[p4], MAX_DECK); G.discardCount[p1] = 0; G.discardCount[p2] = 0; G.discardCount[p3] = 0; G.discardCount[p4] = 0; //testing current player numActions1 = G.numActions; numHand1 = G.handCount[p1]; numDeck1 = G.deckCount[p1]; effectVillage(&G, &infos); numHand2 = G.handCount[p1]; numDeck2 = G.deckCount[p1]; numActions2 = G.numActions; assert(numActions1 +2 == numActions2); assert(numDeck1 -1 == numDeck2); //assert(numHand1 +1 == numHand2); endTurn(&G); assert(G.numActions == numActions1); //testing for player 2 infos.currentPlayer = 0; numHand1 = G.handCount[p2]; numDeck1 = G.deckCount[p2]; effectVillage(&G, &infos); numHand2 = G.handCount[p2]; numDeck2 = G.deckCount[p2]; assert(numDeck1 == numDeck2); assert(numHand1 == numHand2); //testing for player 3 infos.currentPlayer = 0; numHand1 = G.handCount[p3]; numDeck1 = G.deckCount[p3]; effectVillage(&G, &infos); numHand2 = G.handCount[p3]; numDeck2 = G.deckCount[p3]; assert(numDeck1 == numDeck2); assert(numHand1 == numHand2); //testing for player 4 infos.currentPlayer = 0; numHand1 = G.handCount[p4]; numDeck1 = G.deckCount[p4]; effectVillage(&G, &infos); numHand2 = G.handCount[p4]; numDeck2 = G.deckCount[p4]; assert(numDeck1 == numDeck2); assert(numHand1 == numHand2); return 0; }
int main (){ int seed = 1000; int numPlayer = 2; int flag; //0=no cards in deck, int r; int result = 0; bool pass = true; int p=0; int k[10] = { adventurer, council_room, feast, gardens, mine , remodel, smithy, village, baron, great_hall }; struct gameState G; memset(&G, 23, sizeof(struct gameState)); // clear the game state r = initializeGame(numPlayer, k, seed, &G); // initialize a new game printf("TESTING DRAW CARD\n"); for(p=0; p<numPlayer; p++){ printf("Testing for player %d\n", p+1); /*EDGE CASES*/ //CHECK for 0 cards in deck printf("Testing for no cards in deck\n"); flag = 0; G.deckCount[p] = 0; setDiscardDeck(p, &G); result = checkDrawCard(p, &G, flag); if (result == -1){ pass = false; } //check for neg cards in deck printf("Testing for neg cards in deck\n"); flag = 0; G.deckCount[p] = -5; setDiscardDeck(p, &G); result = checkDrawCard(p, &G, flag); if (result == -1){ pass = false; } //testing for max cards in deck printf("Testing for max cards in deck\n"); flag = 1; G.deckCount[p] = MAX_DECK; setDeck(p, &G); result = checkDrawCard(p, &G, flag); if (result == -1){ pass = false; } /**NORMAL CASES**/ printf("Testing for 10 cards in deck\n"); flag = 1; G.deckCount[p] = 10; setDiscardDeck(p, &G); result = checkDrawCard(p, &G, flag); if (result == -1){ pass = false; } //check for 0 cards in hand printf("Testing for 0 cards in hand\n"); flag = 1; G.deckCount[p] = 10; G.handCount[p] =0; setDiscardDeck(p, &G); result = checkDrawCard(p, &G, flag); if (result == -1){ pass = false; } if (pass == true){ printf("ALL TESTS PASSED!\n"); }else{ printf("FAILURES\n"); } } return 0; }