コード例 #1
0
int main() 
{
	int discard = 0;
	int shuffleCard = 0;
	int handpos = 0;
	int choice1 = 0;
	int choice2 = 0;
	int choice3 = 0;
	int bonus = 0;

	int seed;
	struct gameState game;
	struct gameState testGame;
	int k[10] = { adventurer, steward, village, minion, smithy, great_hall, baron, salvager, cutpurse, council_room };
	
	int i, j;

	printf("Starting randomtestadventurer.c for: %s \n", "Adventurer");

	printf("Random Tests\n");

	for (i = 0; i < TEST_NUM; i++)
	{
		seed = rand();

		for (j = 0; j < sizeof(struct gameState); j++)	//initialize struct using random data
		{
			((char*)&game)[j] = floor(Random() * 256);
		}
		
		initializeGame(PLAYER_NUMBER, k, seed++, &game);		//initialize game

		randomizeGameState(&game);	//set random state

		memcpy(&testGame, &game, sizeof(struct gameState));				// make copy of game state

		cardEffect(adventurer, choice1, choice2, choice3, &testGame, handpos, &bonus);		//use adventurer card

		randomCardTest(&game, &testGame, shuffleCard, discard);		// check game state using tests
	}

	printf("Tests completed!\n");

	return 0;
}
コード例 #2
0
ファイル: asrandomtestcard.c プロジェクト: cr8zd/cs362w16
int main() {
    int newCards = 0;
    int discarded = 1;
    int xtraCoins = 0;
    int shuffledCards = 0;
    int drawnCard1 = 0;
    int drawnCard2 = 0;
    srand(time(NULL));

    int i = 0;
    int failed = 0;
    int handpos = 0, choice1 = 0, choice2 = 0, choice3 = 0, bonus = 0;
    int remove1, remove2;
    int seed = 645;
    int numPlayers = 4;
    int thisPlayer = 0;
    int player2 = 1;
    int player3 = 2;
    int player4 = 3;
    int playerArray[4] = {thisPlayer, player2, player3, player4};
    struct gameState G, testG, oracleG, beforeG;
    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 Card: %s ----------------\n", TESTCARD);

    // ----------- TEST 1: choice1 = 1 = +2 cards --------------
    printf("RANDOM TEST : = Play sea_hag\n\n\n");

    for (i = 0; i < 1000000; ++i)
    {

        // copy a blank gamestate to testG
        memcpy(&testG, &G, sizeof(struct gameState));


        randomizeGameState(&testG, playerArray);

        //Set oracleG to values after randomizing gameState
        memcpy(&oracleG, &testG, sizeof(struct gameState));

        //This is so the original state can be printed if there is an error.
        memcpy(&beforeG, &testG, sizeof(struct gameState));

        setOracle(&testG, &oracleG, playerArray, thisPlayer);

        //Perform the test...
        cardEffect(sea_hag, choice1, choice2, choice3, &testG, handpos, &bonus);

        if(!checkOracle(&testG, &oracleG, playerArray)) {
            printErrorReport(&testG, &oracleG, &beforeG, playerArray, i + 1);
            failed++;
        } 
    }
    printf("The test ran %d times and resulted in %d failures.\n", i, failed);

    printf("\n >>>>> SUCCESS: Testing complete %s <<<<<\n\n", TESTCARD);


    return 0;
}