diff --git a/dominion/AssertCustom.c b/dominion/AssertCustom.c new file mode 100644 index 00000000..587578f7 --- /dev/null +++ b/dominion/AssertCustom.c @@ -0,0 +1,64 @@ +// +// Created by Yuning on 2019/07/21. +// +#include "dominion.h" +#include "dominion_helpers.h" +#include +#include +#include +#include "rngs.h" +#include "assertCustom.h" +#include + +#define TRUE 1 +#define FALSE 0 +#define NUM_CARDS 27 + + +void assertCustom(int boolean, char * message) { + + if (boolean == TRUE) { + + printf("TEST PASSED: %s\n", message); + } + if (boolean == FALSE) { + + printf("TEST FAILED: %s\n", message); + + + } + +} + +void assertGameState(int player, struct gameState * oldG, struct gameState * newG) { + int failed = FALSE; + if (oldG->handCount[player] != newG->handCount[player]) { + printf("TEST FAILED: Hand Count for non-action player Changed\n"); + failed = TRUE; + } + if (oldG->numPlayers != newG->numPlayers) { + printf("TEST FAILED: Number of Players in Game Changed\n"); + failed = TRUE; + } + if (oldG->deckCount[player] != newG->deckCount[player]) { + printf("TEST FAILED: Deck Count for non-action player Changed\n"); + failed = TRUE; + } + int i; + for (i = curse; i < NUM_CARDS; i++) { + if (oldG->supplyCount[i] != newG->supplyCount[i]) { + printf("TEST FAILED Card %d Supply Count Changed\n", i); + failed = TRUE; + } + if (oldG->embargoTokens[i] != newG->embargoTokens[i]) { + printf("TEST FAILED Embargo Token on Card %d Changed\n", i); + failed = TRUE; + + } + } + if (!failed) { + printf("TEST PASSED: Game State Invariants\n"); + } + +} + diff --git a/dominion/AssertCustom.h b/dominion/AssertCustom.h new file mode 100644 index 00000000..39c5b4d2 --- /dev/null +++ b/dominion/AssertCustom.h @@ -0,0 +1,15 @@ +// +// Created by Yuning on 2019/07/21 +// + + + + +#ifndef DOMINION_ASSERTCUSTOM_H +#define DOMINION_ASSERTCUSTOM_H + +void assertCustom(int boolean, char * message); + +void assertGameState(int player, struct gameState * oldG, struct gameState * newG); + +#endif //DOMINION_ASSERTCUSTOM_H \ No newline at end of file diff --git a/dominion/CardTest1.c b/dominion/CardTest1.c new file mode 100644 index 00000000..f796e8d7 --- /dev/null +++ b/dominion/CardTest1.c @@ -0,0 +1,58 @@ +// +// Created by Yuning 2019/07/21 +// + +#include "dominion.h" +#include "dominion_helpers.h" +#include +#include +#include +#include "rngs.h" +#include "assertCustom.h" +#include + +#define TESTCARD "ambassador" + + + + +int main() { + int newCards = 0; + int discarded = 1; + int xtraCoins = 0; + int shuffledCards = 0; + int numBuys = 0; + int numActions = 0; + + int handpos = 0, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0; + int seed = 1000; + int numPlayers = 2; + int thisPlayer = 0; + struct gameState G, testG; + int k[5] = { minion, ambassador, tribute, mine, baron }; + + // initialize a game state and player cards + initializeGame(numPlayers, k, seed, &G); + printf("----------------- Testing Ambassador Card: %s ----------------\n", TESTCARD); + //ambassador should receive exactly 3-cards + //copy game state + memcpy(&testG, &G, sizeof(struct gameState)); + + cardEffect(ambassador, choice1, choice2, choice3, &testG, handpos, &bonus); + newCards = 3; + xtraCoins = 0; + + + assertCustom(testG.handCount[thisPlayer] == G.handCount[thisPlayer] + newCards - discarded, "Receives 3 cards"); + assertCustom(testG.deckCount[thisPlayer] == G.deckCount[thisPlayer] - newCards + shuffledCards, "Deck has 3 less Cards"); + assertCustom(testG.coins == G.coins + xtraCoins, "No extra coins received"); + assertCustom(testG.whoseTurn == G.whoseTurn, "Same Players Turn"); + assertCustom(testG.numActions == G.numActions, "Number of actions"); + assertCustom(testG.numBuys == G.numBuys, "Number of Buys"); + assertCustom(testG.playedCardCount == G.playedCardCount + discarded, "Number of Cards Discarded"); + assertGameState(thisPlayer + 1, &G, &testG); + + + + return 0; +} \ No newline at end of file diff --git a/dominion/CardTest2.c b/dominion/CardTest2.c new file mode 100644 index 00000000..e6205066 --- /dev/null +++ b/dominion/CardTest2.c @@ -0,0 +1,62 @@ +// +// Created by Yuning 2019/07/21 +// + + +#include "dominion.h" +#include "dominion_helpers.h" +#include +#include +#include +#include "rngs.h" +#include "assertCustom.h" +#include + +#define TESTCARD "tribute" + + + + +int main() { + int newCards = 0; + int discarded = 1; + int xtraCoins = 0; + int shuffledCards = 0; + int numBuys = 0; + int numActions = 0; + + int i, j, m; + int handpos = 0, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0; + int remove1, remove2; + int seed = 1000; + int numPlayers = 2; + int thisPlayer = 0; + struct gameState G, testG; + int k[5] = { minion, ambassador, tribute, mine, baron }; + + // initialize a game state and player cards + initializeGame(numPlayers, k, seed, &G); + printf("----------------- Testing tribute Card: %s ----------------\n", TESTCARD); + //Tribute should receive one card and one action + //copy game state + memcpy(&testG, &G, sizeof(struct gameState)); + + cardEffect(tribute, choice1, choice2, choice3, &testG, handpos, &bonus); + newCards = 1; + xtraCoins = 0; + numActions = 1; + + + assertCustom(testG.handCount[thisPlayer] == G.handCount[thisPlayer] + newCards - discarded, "Receives 1 cards"); + assertCustom(testG.deckCount[thisPlayer] == G.deckCount[thisPlayer] - newCards + shuffledCards, "Deck has 1 less Cards"); + assertCustom(testG.coins == G.coins + xtraCoins, "No extra coins received"); + assertCustom(testG.whoseTurn == G.whoseTurn, "Same Player's Turn"); + assertCustom(testG.numActions == G.numActions + numActions, "Number of actions"); + assertCustom(testG.numBuys == G.numBuys + numBuys, "Number of Buys"); + assertCustom(testG.playedCardCount == G.playedCardCount + discarded, "Number of Cards Discarded"); + assertGameState(thisPlayer + 1, &G, &testG); + + + + return 0; +} \ No newline at end of file diff --git a/dominion/CardTest3.c b/dominion/CardTest3.c new file mode 100644 index 00000000..22f0f7f9 --- /dev/null +++ b/dominion/CardTest3.c @@ -0,0 +1,58 @@ +// +// Created by Yuning 2019/07/21 +// + +#include "dominion.h" +#include "dominion_helpers.h" +#include +#include +#include +#include "rngs.h" +#include "assertCustom.h" +#include + +#define TESTCARD "mine" + + + + +int main() { + int newCards = 0; + int discarded = 1; + int xtraCoins = 0; + int shuffledCards = 0; + int numBuys = 0; + int numActions = 0; + + int handpos = 0, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0; + int seed = 1000; + int numPlayers = 2; + int thisPlayer = 0; + struct gameState G, testG; + int k[5] = { minion, ambassador, tribute, mine, baron }; + + // initialize a game state and player cards + initializeGame(numPlayers, k, seed, &G); + printf("----------------- Testing Mine Card: %s ----------------\n", TESTCARD); + //mine should receive exactly 3-cards + //copy game state + memcpy(&testG, &G, sizeof(struct gameState)); + + cardEffect(mine, choice1, choice2, choice3, &testG, handpos, &bonus); + newCards = 3; + xtraCoins = 0; + + + assertCustom(testG.handCount[thisPlayer] == G.handCount[thisPlayer] + newCards - discarded, "Receives 3 cards"); + assertCustom(testG.deckCount[thisPlayer] == G.deckCount[thisPlayer] - newCards + shuffledCards, "Deck has 3 less Cards"); + assertCustom(testG.coins == G.coins + xtraCoins, "No extra coins received"); + assertCustom(testG.whoseTurn == G.whoseTurn, "Same Players Turn"); + assertCustom(testG.numActions == G.numActions, "Number of actions"); + assertCustom(testG.numBuys == G.numBuys, "Number of Buys"); + assertCustom(testG.playedCardCount == G.playedCardCount + discarded, "Number of Cards Discarded"); + assertGameState(thisPlayer + 1, &G, &testG); + + + + return 0; +} \ No newline at end of file diff --git a/dominion/CardTest4.c b/dominion/CardTest4.c new file mode 100644 index 00000000..090082b1 --- /dev/null +++ b/dominion/CardTest4.c @@ -0,0 +1,119 @@ +// +// Created by Yuning 2019/07/21 +// + +#include "dominion.h" +#include "dominion_helpers.h" +#include +#include +#include +#include "rngs.h" +#include "assertCustom.h" +#include + +#define TESTCARD "baron" + + + + +int main() { + int newCards = 0; + int discarded = 1; + int xtraCoins = 0; + int shuffledCards = 0; + int numBuys = 0; + int numActions = 0; + int handCount; + int deckcount; + int newDeckCount; + int i, j, m; + int handpos = 0, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0; + int remove1, remove2; + int seed = 1000; + int numPlayers = 2; + int thisPlayer = 0; + int nextPlayer = 1; + struct gameState G, testG; + int k[5] = { minion, ambassador, tribute, mine, baron }; + + // initialize a game state and player cards + initializeGame(numPlayers, k, seed, &G); + printf("----------------- Testing Baron Card State: %s ----------------\n", TESTCARD); + //Great Hall should receive one card and one action + //copy game state + memcpy(&testG, &G, sizeof(struct gameState)); + + deckcount = testG.deckCount[thisPlayer]; + + + int newDeck1[] = { copper, copper, gold }; + newDeckCount = 3; + + for (i = 0; i < newDeckCount; i++) { + testG.deck[thisPlayer][--deckcount] = newDeck1[i]; + } + + + + cardEffect(baron, choice1, choice2, choice3, &testG, handpos, &bonus); + newCards = 2; + xtraCoins = 0; + numBuys = 0; + handCount = testG.handCount[thisPlayer]; + + + assertCustom(testG.handCount[thisPlayer] == G.handCount[thisPlayer] + newCards - discarded, "Receives 2 cards"); + assertCustom(testG.hand[thisPlayer][--handCount] == copper, "First Treasure is Copper"); + assertCustom(testG.hand[thisPlayer][--handCount] == copper, "Second Treasure is Copper"); + assertCustom(testG.deckCount[thisPlayer] == G.deckCount[thisPlayer] - newCards + shuffledCards, "Deck has 2 less Cards"); + assertCustom(testG.coins == G.coins + xtraCoins, "No extra coins received"); + assertCustom(testG.whoseTurn == G.whoseTurn, "Same Player's Turn"); + assertCustom(testG.numActions == G.numActions, "Number of actions"); + assertCustom(testG.numBuys == G.numBuys + numBuys, "Number of Buys"); + assertCustom(testG.playedCardCount == G.playedCardCount + discarded, "Number of Cards Discarded"); + + assertGameState(nextPlayer, &G, &testG); + + + + memcpy(&testG, &G, sizeof(struct gameState)); + + deckcount = testG.deckCount[thisPlayer]; + + + printf("--------------------Test Case Gold, Province, Silver ------------"); + int newDeck2[] = { silver, province, gold }; + newDeckCount = 3; + + for (i = 0; i < newDeckCount; i++) { + testG.deck[thisPlayer][--deckcount] = newDeck2[i]; + } + + cardEffect(baron, choice1, choice2, choice3, &testG, handpos, &bonus); + newCards = 2; + xtraCoins = 0; + numActions = 0; + numBuys = 0; + handCount = testG.handCount[thisPlayer]; + discarded = 1; + //TODO FIX Council_ROOM Messages + assertCustom(testG.handCount[thisPlayer] == G.handCount[thisPlayer] + newCards - discarded, "Receives 2 cards"); + assertCustom(testG.hand[thisPlayer][--handCount] == gold, "First Treasure is Gold"); + assertCustom(testG.hand[thisPlayer][--handCount] == silver, "Second Treasure is Silver"); + assertCustom(testG.deckCount[thisPlayer] == G.deckCount[thisPlayer] - newCards - 1 + shuffledCards, "Deck has 3 less Cards"); + assertCustom(testG.coins == G.coins + xtraCoins, "No extra coins received"); + assertCustom(testG.whoseTurn == G.whoseTurn, "Same Player's Turn"); + assertCustom(testG.numActions == G.numActions, "Number of actions"); + assertCustom(testG.numBuys == G.numBuys + numBuys, "Number of Buys"); + assertCustom(testG.playedCardCount == G.playedCardCount + discarded + 1, "Number of Cards Discarded"); + + + + + assertGameState(nextPlayer, &G, &testG); + + + + + return 0; +} \ No newline at end of file diff --git a/dominion/unitest1.c b/dominion/unitest1.c new file mode 100644 index 00000000..c6f6f06c --- /dev/null +++ b/dominion/unitest1.c @@ -0,0 +1,61 @@ +// +// Created by Yuning 2019/07/21 +// + +#include "dominion.h" +#include "dominion_helpers.h" +#include +#include +#include +#include "rngs.h" +#include "assertCustom.h" +#include + +int main() { + int newCards = 0; + int discarded = 1; + int xtraCoins = 0; + int shuffledCards = 0; + int numBuys = 0; + int numActions = 0; + int handCount; + int handpos = 0; + int i; + int seed = 1000; + int numPlayers = 2; + int thisPlayer = 0; + int bonus = 0; + struct gameState G, testG; + int k[10] = { adventurer, embargo, village, minion, mine, cutpurse, + sea_hag, tribute, smithy, council_room }; + + // initialize a game state and player cards + initializeGame(numPlayers, k, seed, &G); + printf("----------------- Testing UpdateCoins----------------\n"); + //Smithy should receive exactly 3-cards + //copy game state + memcpy(&testG, &G, sizeof(struct gameState)); + + int coins[] = { gold, silver, copper }; + newCards = 3; + for (i = 0; i < newCards; i++) { + testG.hand[thisPlayer][testG.handCount[thisPlayer]++] = coins[i]; + } + + xtraCoins = 6; + + updateCoins(thisPlayer, &testG, bonus); + + assertCustom(testG.handCount[thisPlayer] == G.handCount[thisPlayer] + newCards, "Receives 3 cards"); + assertCustom(testG.deckCount[thisPlayer] == G.deckCount[thisPlayer], "Deck has the same number of cards"); + assertCustom(testG.coins == G.coins + xtraCoins, "Six extra coins received"); + assertCustom(testG.whoseTurn == G.whoseTurn, "Same Players Turn"); + assertCustom(testG.numActions == G.numActions, "Number of actions"); + assertCustom(testG.numBuys == G.numBuys, "Number of Buys"); + assertCustom(testG.playedCardCount == G.playedCardCount, "Number of Cards Discarded"); + assertGameState(thisPlayer + 1, &G, &testG); + + + + return 0; +} \ No newline at end of file diff --git a/dominion/unitest2.c b/dominion/unitest2.c new file mode 100644 index 00000000..1e0deade --- /dev/null +++ b/dominion/unitest2.c @@ -0,0 +1,30 @@ +// +// Created by Yuning 2019/07/21 +// + +#include "dominion.h" +#include "dominion_helpers.h" +#include +#include +#include +#include "rngs.h" +#include "assertCustom.h" +#include +#define NO_CARDS 0 +#define TRUE 1 +#define FALSE 0 + +void invariant_tests(int thisPlayer, struct gameState G, struct gameState testG) { + + assertCustom(testG.handCount[thisPlayer] == G.handCount[thisPlayer], "Receives No cards"); + assertCustom(testG.deckCount[thisPlayer] == G.deckCount[thisPlayer], "Deck has the same number of cards"); + assertCustom(testG.coins == G.coins, "No extra coins received"); + assertCustom(testG.whoseTurn == G.whoseTurn, "Same Players Turn"); + assertCustom(testG.numActions == G.numActions, "Number of actions"); + assertCustom(testG.numBuys == G.numBuys, "Number of Buys"); + assertCustom(testG.playedCardCount == G.playedCardCount, "Number of Cards Discarded"); + assertGameState(thisPlayer + 1, &G, &testG); + + + +} \ No newline at end of file diff --git a/dominion/unitest3.c b/dominion/unitest3.c new file mode 100644 index 00000000..80f36a17 --- /dev/null +++ b/dominion/unitest3.c @@ -0,0 +1,54 @@ +// +// Created by Yuning 2019/07/21 +// + + +#include "dominion.h" +#include "dominion_helpers.h" +#include +#include +#include +#include "rngs.h" +#include "assertCustom.h" +#include +#define NO_CARDS 0 +#define TRUE 1 +#define FALSE 0 + + +int main() { + + int discarded; + + int seed = 1000; + int numPlayers = 2; + int thisPlayer = 0; + int nextPlayer = 1; + + struct gameState G, testG; + int k[10] = { adventurer, embargo, village, minion, mine, cutpurse, + sea_hag, tribute, smithy, council_room }; + + // initialize a game state and player cards + initializeGame(numPlayers, k, seed, &G); + printf("----------------- Testing endTurn----------------\n"); + //current player discards all of his cards + //state is reset for next player + //player is then dealt 5 cards + //copy game state + memcpy(&testG, &G, sizeof(struct gameState)); + discarded = 5; + int drawn = 5; + endTurn(&testG); + assertCustom(testG.whoseTurn == G.whoseTurn + 1, "Next Player Turn"); + assertCustom(testG.discardCount[thisPlayer] == G.discardCount[thisPlayer] + discarded, "Discard Pile has 5 more cards"); + assertCustom(testG.handCount[thisPlayer] == G.handCount[thisPlayer] - discarded, "Old Player has nom more cards"); + assertCustom(testG.handCount[nextPlayer] == G.handCount[nextPlayer] + drawn, "New player has five cards"); + assertCustom(testG.outpostPlayed == 0, "Number of outposts reset"); + assertCustom(testG.phase == 0, "Phase Reset"); + assertCustom(testG.numActions == 1, "1 Buys"); + assertCustom(testG.playedCardCount = 0, "No Played Cards"); + assertCustom(testG.coins <= 15, "No impossible number of coins"); + + return 0; +} \ No newline at end of file diff --git a/dominion/unitest4.c b/dominion/unitest4.c new file mode 100644 index 00000000..573684e8 --- /dev/null +++ b/dominion/unitest4.c @@ -0,0 +1,62 @@ +// +// Created by Yuning 2019/07/21 +// + + +#include "dominion.h" +#include "dominion_helpers.h" +#include +#include +#include +#include "rngs.h" +#include "assertCustom.h" +#include +#define NO_CARDS 0 +#define TRUE 1 +#define FALSE 0 + +void invariant_tests(int thisPlayer, struct gameState G, struct gameState testG) { + + + assertCustom(testG.deckCount[thisPlayer] == G.deckCount[thisPlayer], "Deck has the same number of cards"); + assertCustom(testG.coins == G.coins, "No extra coins received"); + assertCustom(testG.whoseTurn == G.whoseTurn, "Same Players Turn"); + assertCustom(testG.numActions == G.numActions, "Number of actions"); + assertCustom(testG.numBuys == G.numBuys, "Number of Buys"); + assertCustom(testG.playedCardCount == G.playedCardCount, "Number of Cards Discarded"); + assertGameState(thisPlayer + 1, &G, &testG); + + + +} + + + +int main() { + + int seed = 1000; + int numPlayers = 2; + int thisPlayer = 0; + int bonus = 0; + struct gameState G, testG; + int k[10] = { adventurer, embargo, village, minion, mine, cutpurse, + sea_hag, tribute, smithy, council_room }; + + // initialize a game state and player cards + initializeGame(numPlayers, k, seed, &G); + printf("----------------- Testing numHandCards----------------\n"); + + //copy game state + memcpy(&testG, &G, sizeof(struct gameState)); + assertCustom(numHandCards(&testG) == testG.handCount[thisPlayer], "Five Cards in Hand at Start of State"); + invariant_tests(thisPlayer, G, testG); + testG.handCount[thisPlayer]++; + assertCustom(numHandCards(&testG) == testG.handCount[thisPlayer], "Six Cards in Hand"); + invariant_tests(thisPlayer, G, testG); + + testG.handCount[thisPlayer]--; + assertCustom(numHandCards(&testG) == testG.handCount[thisPlayer], "Five Cards in Hand"); + invariant_tests(thisPlayer, G, testG); + + return 0; +} \ No newline at end of file