int main () { struct gameState G = generateGameState(); printf("\nUnit Test: int scoreFor(int player, struct gameState *state);\n"); int i; int curseCards[MAX_CARD_COUNT]; int estateCards[MAX_CARD_COUNT]; int duchyCards[MAX_CARD_COUNT]; int provinceCards[MAX_CARD_COUNT]; int mixWithGreatHallCards[MAX_CARD_COUNT] = { curse, estate, duchy, province, great_hall }; int mixWithGardensCards[MAX_CARD_COUNT] = { curse, estate, duchy, province, gardens }; // Initialize cards for (i = 0; i < MAX_CARD_COUNT; i++) { curseCards[i] = curse; estateCards[i] = estate; duchyCards[i] = duchy; provinceCards[i] = province; } testScoreFor(0, "curseCards", curseCards, curseCards, curseCards, &G); testScoreFor(1, "estateCards", estateCards, estateCards, estateCards, &G); testScoreFor(0, "duchyCards", duchyCards, duchyCards, duchyCards, &G); testScoreFor(1, "provinceCards", provinceCards, provinceCards, provinceCards, &G); testScoreFor(0, "mixWithGreatHallCards", mixWithGreatHallCards, mixWithGreatHallCards, mixWithGreatHallCards, &G); testScoreFor(1, "mixWithGardensCards", mixWithGardensCards, mixWithGardensCards, mixWithGardensCards, &G); testScoreFor(0, "estateDuchyProvinceCards", estateCards, duchyCards, provinceCards, &G); testScoreFor(1, "curseGreatHallGardensCards", curseCards, mixWithGreatHallCards, mixWithGardensCards, &G); printf("\nALL TESTS OK\n"); return 0; }
int main() { struct gameState G; printf("\nStarting Test for scoreFor...\n"); SelectStream(2); PutSeed(3); int i, n; int player; for(n = 0; n < 2000; n++) { for(i = 0; i < sizeof(struct gameState); i++) { ((char*)&G)[i] = floor(Random() * 256); } player = floor(Random() * MAX_PLAYERS); G.deckCount[player] = floor(Random() * MAX_DECK); G.discardCount[player] = floor(Random() * MAX_DECK); G.handCount[player] = floor(Random() * MAX_HAND); for (i = 0; i < G.handCount[player]; i++) { G.hand[player][i] = floor(Random() * MAX_DECK); } for (i = 0; i < G.discardCount[player]; i++) { G.discard[player][i] = floor(Random() * MAX_DECK); } for (i = 0; i < G.discardCount[player]; i++) { G.deck[player][i] = floor(Random() * MAX_DECK); } testScoreFor(player, &G); } printf("\nAll Tests PASSED\n\n"); printf("\n\nEnding Test for scoreFor...\n"); return 0; }
int main() { int i; int n; int j; int outCome; int numTests = 1; int gameIterations = 100; //change for the number of test games struct gameState testGame; //display testing message for unittest1 printf ("----------------------------------------\n"); printf ("FUNCTION scoreFor() BEING TESTED...\n"); printf ("RANDOM TESTS...unittest1.c\n\n"); //this is initializing stream for random number generation SelectStream(2); PutSeed(3); //testing for 2000 iterations for(n = 0; n < gameIterations; n++) { for(i = 0; i < sizeof(struct gameState); i++) { ((char*)&testGame)[i] = floor(Random() * 256); } //initializing random number of players up to largest integral value j = floor(Random() * MAX_PLAYERS); //initializing random decks up to the largest integral value testGame.deckCount[j] = floor(Random() * MAX_DECK); //initializing random discards up to the largest integral value testGame.discardCount[j] = floor(Random() * MAX_DECK); //initializing random hands up to the largest integral value testGame.handCount[j] = floor(Random() * MAX_HAND); //initializing random hands for each player for (i = 0; i < testGame.handCount[j]; i++) { testGame.hand[j][i] = floor(Random() * MAX_DECK); } //initializing random discards for each player for (i = 0; i < testGame.discardCount[j]; i++) { testGame.discard[j][i] = floor(Random() * MAX_DECK); } //initializing random deck for each player for (i = 0; i < testGame.discardCount[j]; i++) { testGame.deck[j][i] = floor(Random() * MAX_DECK); } //call to test scoreFor() outCome = testScoreFor(j, &testGame); } if (outCome == 0) { printf("TEST PASSED\n\n"); printf("scoreFor() FAILED %d out of %d TEST\n\n", outCome, numTests); } else { printf("scoreFor() FAILED %d out of %d TEST\n\n", outCome, numTests); } return 0; }
int main() { testScoreFor(); return 0; }