Esempio n. 1
0
static void gen_xpnd04_2(DisasContext *ctx)
{
    switch (opc4(ctx->opcode)) {
    case 4:
        gen_bcdctz(ctx);
        break;
    case 6:
        gen_bcdcfz(ctx);
        break;
    case 7:
        gen_bcdcfn(ctx);
        break;
    default:
        gen_invalid(ctx);
        break;
    }
}
int main(int argc, char *argv[])
{
    srand(time(NULL));
    int num_errors = 0;
    printf("Starting test of initializeGame...\n");
    for(int i = 0; i < NUMBER_ITERATIONS; i++ )
    {
        printf("\n\n*************************************************\n\nStarting Test# %d\n", i);

        struct gameState myState;
        int shouldFail = 0;// Keeps track of whether the function should fail under given inputs
        int randomSeed = rand();
        int numPlayers = rand() % 4 + 1;//function should accept 2 to MAX_PLAYERS, so going 1 outside bounds to check.
        int temp_num_errors = 0;

        if(numPlayers > MAX_PLAYERS || numPlayers < 2 )
        {
            //printf("Adding invalid number of players.\n");
            shouldFail = 1;
        }

        int myKingdomCards[10];
        if( rand() % 5 == 0 )//Give potentially invalid set of cards 20% of time
        {
            if( gen_invalid(myKingdomCards) )
            {
                shouldFail = 1;
                //printf("Added repeated KingdomCards\n");
            }
        }
        else//Give valid set of cards
        {
            gen_valid_KC(myKingdomCards);
        }

        if(initializeGame(numPlayers, myKingdomCards, randomSeed, &myState ) == -1)
        {
            if(shouldFail)
            {
                //printf("SUCCESS: Returned -1 on invalid input.\n");
            }
            else
            {
                printf("FAILURE: Returned -1 on valid input.\n");
                temp_num_errors++;
            }
        }
        else
        {
            temp_num_errors += check_state(numPlayers, myKingdomCards, myState);
        }
        if( temp_num_errors > 1 || VERBOSE )
        {
            printf("numPlayers: %d\n", numPlayers);
            display_KC(myKingdomCards);
            printf("randomSeed: %d\n", randomSeed);
        }
        num_errors += temp_num_errors;
    }

    printf("\nFound %d errors.\n", num_errors);

    return 1;
}