Exemplo n.º 1
0
int main() {
    int seed = 1000;
    int numPlayer = 2;
    int maxBonus = 10;
    int p, r, handCount;
    int bonus;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    int maxHandCount = 5;

    printf ("TESTING updateCoins():\n");
    for (p = 0; p < numPlayer; p++)
    {
        for (handCount = 1; handCount <= maxHandCount; handCount++)
        {
            for (bonus = 0; bonus <= maxBonus; bonus++)
            {
                #if (NOISY_TEST == 1)
                printf("Test player %d with %d treasure card(s) and %d bonus.\n", p, handCount, bonus);
                #endif
                memset(&G, 23, sizeof(struct gameState));   // clear the game state
                r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
                G.handCount[p] = handCount;                 // set the number of cards on hand
                printf("function call \n");
                //Call function
                unitTest(&G);

            }
        }
    }
    printf("All tests passed!\n");

    return 0;
}
int registerWebHistory(JNIEnv* env)
{
    // Get notified of all changes to history items.
    WebCore::notifyHistoryItemChanged = historyItemChanged;
#ifdef UNIT_TEST
    unitTest();
#endif
    // Find WebHistoryItemClassic, its constructor, and the update method.
    jclass clazz = env->FindClass("android/webkit/WebHistoryItemClassic");
    ALOG_ASSERT(clazz, "Unable to find class android/webkit/WebHistoryItemClassic");
    gWebHistoryItemClassic.mInit = env->GetMethodID(clazz, "<init>", "(I)V");
    ALOG_ASSERT(gWebHistoryItemClassic.mInit, "Could not find WebHistoryItemClassic constructor");
    env->DeleteLocalRef(clazz);

    // Find the WebBackForwardListClassic object and method.
    clazz = env->FindClass("android/webkit/WebBackForwardListClassic");
    ALOG_ASSERT(clazz, "Unable to find class android/webkit/WebBackForwardListClassic");
    gWebBackForwardListClassic.mAddHistoryItem = env->GetMethodID(clazz, "addHistoryItem",
            "(Landroid/webkit/WebHistoryItem;)V");
    ALOG_ASSERT(gWebBackForwardListClassic.mAddHistoryItem, "Could not find method addHistoryItem");
    gWebBackForwardListClassic.mRemoveHistoryItem = env->GetMethodID(clazz, "removeHistoryItem",
            "(I)V");
    ALOG_ASSERT(gWebBackForwardListClassic.mRemoveHistoryItem, "Could not find method removeHistoryItem");
    gWebBackForwardListClassic.mSetCurrentIndex = env->GetMethodID(clazz, "setCurrentIndex", "(I)V");
    ALOG_ASSERT(gWebBackForwardListClassic.mSetCurrentIndex, "Could not find method setCurrentIndex");
    env->DeleteLocalRef(clazz);

    int result = jniRegisterNativeMethods(env, "android/webkit/WebBackForwardListClassic",
            gWebBackForwardListClassicMethods, NELEM(gWebBackForwardListClassicMethods));
    return (result < 0) ? result : jniRegisterNativeMethods(env, "android/webkit/WebHistoryItemClassic",
            gWebHistoryItemClassicMethods, NELEM(gWebHistoryItemClassicMethods));
}
Exemplo n.º 3
0
int main( int argc, char *argv[] ) {

  //Should print out errors and ok = true if unitTest() passes
  bool ok = unitTest();

  if(argc > 1){
    if(!strcmp(argv[1], "a") && argc == 5){
      appendStringToFile(argv[3], argv[4], argv[2][0]);
    }
    else if (!strcmp(argv[1], "g") && argc == 4){
      char* str = getStringAtIndexInFile(atoi(argv[2]), argv[3]);
      if(str){
        printf("%s", str);
        delete str;
      }
    }
    else if(strcmp( argv[1], "g") &&  strcmp( argv[1], "a")){
      printf("You have entered an invald opperation\n");
    }
    else{
      printf("You hve not provided the necessary arguments, halting execution\n");
    }
  }
  else{
    printf("Program arguments:\nUse 'a' to append to a file, provide filename and delimiter (s, t, n)\n"
        "Use 'g' to retrieve from a file, provide index and filename\n"
        "Exiting...\n");
  }

  return 0;
}
Exemplo n.º 4
0
int main () {
  //define variables  
  int i, n, r, p, error,errorA,errorB,errorC;
  errorA=0;
  errorB=0;
  errorC=0;
  //define a gamestate
  struct gameState G;

  printf ("Testing full deck count.\n");

  printf ("RANDOM TESTS.\n");
  //create random seed
  SelectStream(2);
  PutSeed(3);
  //for 2000 test cases
  for (n = 0; n < 2000; n++) {
    for (i = 0; i < sizeof(struct gameState); i++) {
      //fill gamestate with random bits between 0-256 using ofset
      ((char*)&G)[i] = floor(Random() * 256);
    }
    p = floor(Random() * 2);
    G.deckCount[p] = floor(Random() * MAX_DECK);
    G.discardCount[p] = floor(Random() * MAX_DECK);
    G.handCount[p] = floor(Random() * MAX_HAND);
    //call function with test input
    error=unitTest(p,&G);

    if (error > 0){
        if(error == 1){
            errorA++;
        }else if(error == 2){
            errorB++;
        }else if(error == 3){
            errorC++;
        }
    }

  }

  printf ("ALL TESTS OK\n");
  printf ("ALL Random TESTS Complete\n");
  printf ("Errors type 1: %d ",errorA);
  printf ("Error in end turn function.\n");
  printf ("Errors type 2: %d ",errorB);
  printf ("Error in full deck function.\n");
  printf ("Errors type 3: %d ",errorC);
  printf ("Memory size different.\n");

  return 0;
}
Exemplo n.º 5
0
int main () {
  //define variables  
  int i, n, r, p,error,errorA,errorB;
  errorA =0;
  errorB =0;
  //define a array of cards

  //define a gamestate
  struct gameState G;

  printf ("Testing Feast Card.\n");

  printf ("RANDOM TESTS.\n");
  //create random seed
  SelectStream(2);
  PutSeed(3);
  //for 2000 test cases
  for (n = 0; n < 2000; n++) {
    for (i = 0; i < sizeof(struct gameState); i++) {
      //fill gamestate with random bits between 0-256 using ofset
      ((char*)&G)[i] = floor(Random() * 256);
    }
    p = floor(Random() * 2);
    G.deckCount[p] = floor(Random() * MAX_DECK);
    G.discardCount[p] = floor(Random() * MAX_DECK);
    G.handCount[p] = floor(Random() * MAX_HAND);
    G.numPlayers = floor(Random()* MAX_PLAYERS);
    int choice= floor(Random() *MAX_DECK); 
   //call function with test input
    error=unitTest(G.numPlayers,&G,choice);

    if (error > 0){
        if(error == 1){
            errorA++;
        }else if(error > 1){
            errorB++;
        }
    }
  }
  printf ("ALL Random TESTS Complete\n");
  printf ("Errors type 1: %d ",errorA);
  printf ("memory not same size \n");
  printf ("Errors type 2: %d ",errorB);
  printf("hand count not incrimented \n");

  return 0;
}
Exemplo n.º 6
0
int main () {
  //define variables  
  int i, n, r, p, error,errorA,errorB;
  errorA=0;
  errorB=0;
  //define a gamestate
  struct gameState G;

  printf ("Testing end turn function.\n");

  printf ("RANDOM TESTS.\n");
  //create random seed
  SelectStream(2);
  PutSeed(3);
  //for 2000 test cases
  for (n = 0; n < 2000; n++) {
    for (i = 0; i < sizeof(struct gameState); i++) {
      //fill gamestate with random bits between 0-256 using ofset
      ((char*)&G)[i] = floor(Random() * 256);
    }
    p = floor(Random() * 2);
    G.deckCount[p] = floor(Random() * MAX_DECK);
    G.discardCount[p] = floor(Random() * MAX_DECK);
    G.handCount[p] = floor(Random() * MAX_HAND);
    G.numPlayers = floor(Random() * MAX_PLAYERS);
    G.whoseTurn = floor(Random() * MAX_PLAYERS);
    //call function with test input
    error=unitTest(&G);

    if (error > 0){
        if(error == 1){
            errorA++;
        }else if(error > 1){
            errorB++;
        }
    }
  }

  printf ("ALL TESTS complete\n");
   printf ("Errors type 1: %d ",errorA);
  printf ("Current player has not been changed at end of turn.\n");
  printf ("Errors type 2: %d ",errorB);
  printf("function received bad input/found a error returned a 1 \n");

  return 0;
}
Exemplo n.º 7
0
int main() {
   int p, r, p2,
       seed, numPlayer,
       handPos;

   seed = 1000;
   numPlayer = 2;
   handPos = 4;

   int k[10] = {adventurer, great_hall, cutpurse, gardens, mine,
                remodel, smithy, village, sea_hag, embargo};

   struct gameState G;
   p = whoseTurn(&G);
   p2 = 1;

   // clear game state and initialize game
   memset(&G, 23, sizeof(struct gameState));
   r = initializeGame(numPlayer, k, seed, &G);


   printf ("TESTING Village Card:\n\n");

   // stacking deck with copper (card 4)
   stackDeck(&G, p, 0, G.deckCount[p], copper);

   // stacking hand with silver (card 5)
   stackHand(&G, p, 0, G.handCount[p], silver);

   G.discardCount[p] = 2;
   G.discard[p][0] = copper;
   G.discard[p][1] = silver;
  // run test
  r = unitTest(handPos, &G, p);

  passOrFail(r);



return 0;
}
Exemplo n.º 8
0
/* Creates a list and appends three values to it, then prints the appended
    values in order

*/
int main(){
	GList* list = NULL;
    list = g_list_append(list, "Nathan!");
    if (list == NULL)
    {
        fprintf(stderr, "%s\n", "append failed");
        exit(1);
    }
    list = g_list_append(list, "Mikey!");
    if (list == NULL)
    {
        fprintf(stderr, "%s\n", "append failed");
        exit(1);
    }
    list = g_list_append(list, "Hello World!");
    if (list == NULL)
    {
        fprintf(stderr, "%s\n", "append failed");
        exit(1);
    }
    
    GList* currentList = NULL;
    currentList = g_list_first(list);
    if (currentList == NULL)
    {
        fprintf(stderr, "%s\n", "g_list_first failed");
        exit(1);
    }
    int i=0;
    while (currentList)
    {
    	printf("Item %d: %s\n", i++, currentList->data);
    	currentList = g_list_next(currentList);
    }

    unitTest(list);

	return 0;
}
Exemplo n.º 9
0
int main(int argc, const char * argv[])
{
    VoxelTree myTree;

    qInstallMessageHandler(sharedMessageHandler);
    
    unitTest(&myTree);
    
    
    const char* GET_OCTCODE = "--getOctCode";
    const char* octcodeParams = getCmdOption(argc, argv, GET_OCTCODE);
    if (octcodeParams) {

        QString octcodeParamsString(octcodeParams);
        QStringList octcodeParamsList = octcodeParamsString.split(QString(","));

        enum { X_AT, Y_AT, Z_AT, S_AT, EXPECTED_PARAMS };
        if (octcodeParamsList.size() == EXPECTED_PARAMS) {
            QString xStr = octcodeParamsList.at(X_AT);
            QString yStr = octcodeParamsList.at(Y_AT);
            QString zStr = octcodeParamsList.at(Z_AT);
            QString sStr = octcodeParamsList.at(S_AT);

            float x = xStr.toFloat()/TREE_SCALE; // 0.14745788574219;
            float y = yStr.toFloat()/TREE_SCALE; // 0.01502178955078;
            float z = zStr.toFloat()/TREE_SCALE; // 0.56540045166016;
            float s = sStr.toFloat()/TREE_SCALE; // 0.015625;

            qDebug() << "Get Octal Code for:\n";
            qDebug() << "    x:" << xStr << " [" << x << "] \n";
            qDebug() << "    y:" << yStr << " [" << y << "] \n";
            qDebug() << "    z:" << zStr << " [" << z << "] \n";
            qDebug() << "    s:" << sStr << " [" << s << "] \n";

            unsigned char* octalCode = pointToVoxel(x, y, z, s);
            QString octalCodeStr = octalCodeToHexString(octalCode);
            qDebug() << "octal code: " << octalCodeStr << "\n";

        } else {
            qDebug() << "Unexpected number of parameters for getOctCode\n";
        }
        return 0;
    }
    
    const char* DECODE_OCTCODE = "--decodeOctCode";
    const char* decodeParam = getCmdOption(argc, argv, DECODE_OCTCODE);
    if (decodeParam) {

        QString decodeParamsString(decodeParam);
        unsigned char* octalCodeToDecode = hexStringToOctalCode(decodeParamsString);

        VoxelPositionSize details;
        voxelDetailsForCode(octalCodeToDecode, details);
        
        delete[] octalCodeToDecode;

        qDebug() << "octal code to decode: " << decodeParamsString << "\n";
        qDebug() << "Details for Octal Code:\n";
        qDebug() << "    x:" << details.x << "[" << details.x * TREE_SCALE << "]" << "\n";
        qDebug() << "    y:" << details.y << "[" << details.y * TREE_SCALE << "]" << "\n";
        qDebug() << "    z:" << details.z << "[" << details.z * TREE_SCALE << "]" << "\n";
        qDebug() << "    s:" << details.s << "[" << details.s * TREE_SCALE << "]" << "\n";
        return 0;
    }    
    

    // Handles taking and SVO and splitting it into multiple SVOs based on
    // jurisdiction details
    const char* SPLIT_SVO = "--splitSVO";
    const char* splitSVOFile = getCmdOption(argc, argv, SPLIT_SVO);
    const char* SPLIT_JURISDICTION_ROOT = "--splitJurisdictionRoot";
    const char* SPLIT_JURISDICTION_ENDNODES = "--splitJurisdictionEndNodes";
    const char* splitJurisdictionRoot = getCmdOption(argc, argv, SPLIT_JURISDICTION_ROOT);
    const char* splitJurisdictionEndNodes = getCmdOption(argc, argv, SPLIT_JURISDICTION_ENDNODES);
    if (splitSVOFile && splitJurisdictionRoot && splitJurisdictionEndNodes) {
        processSplitSVOFile(splitSVOFile, splitJurisdictionRoot, splitJurisdictionEndNodes);
        return 0;
    }


    // Handles taking an SVO and filling in the empty space below the voxels to make it solid.
    const char* FILL_SVO = "--fillSVO";
    const char* fillSVOFile = getCmdOption(argc, argv, FILL_SVO);
    if (fillSVOFile) {
        processFillSVOFile(fillSVOFile);
        return 0;
    }
    
    const char* DONT_CREATE_FILE = "--dontCreateSceneFile";
    bool dontCreateFile = cmdOptionExists(argc, argv, DONT_CREATE_FILE);

    if (dontCreateFile) {
        printf("You asked us not to create a scene file, so we will not.\n");
    } else {
        printf("Creating Scene File...\n");
    
        const char* RUN_TUTORIAL = "--runTutorial";
        if (cmdOptionExists(argc, argv, RUN_TUTORIAL)) {
            voxelTutorial(&myTree);
        }

        const char* ADD_CORNERS_AND_AXIS_LINES = "--addCornersAndAxisLines";
        if (cmdOptionExists(argc, argv, ADD_CORNERS_AND_AXIS_LINES)) {
            addCornersAndAxisLines(&myTree);
        }

        const char* ADD_SPHERE_SCENE = "--addSphereScene";
        if (cmdOptionExists(argc, argv, ADD_SPHERE_SCENE)) {
            addSphereScene(&myTree);
        }

        const char* ADD_SURFACE_SCENE = "--addSurfaceScene";
        if (cmdOptionExists(argc, argv, ADD_SURFACE_SCENE)) {
            addSurfaceScene(&myTree);
        }

        unsigned long nodeCount = myTree.getOctreeElementsCount();
        printf("Nodes after adding scenes: %ld nodes\n", nodeCount);

        myTree.writeToSVOFile("voxels.svo");
    }
    return 0;
}
Exemplo n.º 10
0
int main (int argc, char** argv)
{
    U32 seed, startTestNb=0, pause=0, totalTest = FUZ_NB_TESTS;
    int argNb;

    seed = FUZ_GetMilliStart() % 10000;
    DISPLAYLEVEL (1, "FSE (%2i bits) automated test\n", (int)sizeof(void*)*8);
    for (argNb=1; argNb<argc; argNb++)
    {
        char* argument = argv[argNb];
        if (argument[0]=='-')
        {
            argument++;
            while (argument[0]!=0)
            {
                switch (argument[0])
                {
                /* seed setting */
                case 's':
                    argument++;
                    seed=0;
                    while ((*argument>='0') && (*argument<='9'))
                    {
                        seed *= 10;
                        seed += *argument - '0';
                        argument++;
                    }
                    break;

                /* total tests */
                case 'i':
                    argument++;
                    totalTest=0;
                    while ((*argument>='0') && (*argument<='9'))
                    {
                        totalTest *= 10;
                        totalTest += *argument - '0';
                        argument++;
                    }
                    break;

                /* jump to test nb */
                case 't':
                    argument++;
                    startTestNb=0;
                    while ((*argument>='0') && (*argument<='9'))
                    {
                        startTestNb *= 10;
                        startTestNb += *argument - '0';
                        argument++;
                    }
                    break;

                /* verbose mode */
                case 'v':
                    argument++;
                    displayLevel=4;
                    break;

                /* pause (hidden) */
                case 'p':
                    argument++;
                    pause=1;
                    break;

                default:
                    return badUsage(argv[0]);
                }
            }
        }
    }

    if (startTestNb == 0) unitTest();

    DISPLAY("Fuzzer seed : %u \n", seed);
    FUZ_tests (seed, totalTest, startTestNb);

    DISPLAY ("\rAll %u tests passed               \n", totalTest);
    if (pause)
    {
        int unused;
        DISPLAY("press enter ...\n");
        unused = getchar();
        (void)unused;
    }
    return 0;
}
Exemplo n.º 11
0
int main () {
  //define variables  
  int i, n, r, p,error,errorA,errorB,errorC,errorD,errorE,errorF;
  errorA =0;
  errorB =0;
  errorC =0;
  errorD =0;
  errorE =0;
  errorF =0;

  //define a gamestate
  struct gameState G;

  printf ("Testing village Card.\n");

  printf ("RANDOM TESTS.\n");
  //create random seed
  SelectStream(2);
  PutSeed(3);
  //for 2000 test cases
  for (n = 0; n < 2000; n++) {
    for (i = 0; i < sizeof(struct gameState); i++) {
      //fill gamestate with random bits between 0-256 using ofset
      ((char*)&G)[i] = floor(Random() * 256);
    }
    p = floor(Random() * 2);
    G.handCount[p] = floor(Random() * MAX_HAND);
    G.numPlayers= floor(Random() * MAX_PLAYERS);
    G.numBuys = floor(Random() * MAX_HAND);//NEW
    G.coins = floor(Random() * MAX_DECK);//NEW
    //intialize arrays to 0
    for (int i =0; i< G.numPlayers +1; i++){
    	G.deckCount[i] = floor(Random() * MAX_DECK);
    	G.discardCount[i] = floor(Random() * MAX_DECK);
    	G.supplyCount[i]=floor(Random() * MAX_DECK);
        G.discard[i][ G.discardCount[i] ] = floor(Random() * MAX_DECK);
        G.discardCount[i]= floor(Random() * MAX_DECK);
    }
    int choice1 = floor(Random() * 2);//boolean true or false
    //call function with test input
    error=unitTest(G.numPlayers,&G,choice1);

    //Fixed Tests needed for
    //G.hand[currentPlayer][p] == estate need fixed test
    //if (state->hand[currentPlayer][p] == estate)

    if (error > 0){
        if(error == 1){
            errorA++;
        }else if(error == 2){
            errorB++;
        }else if(error == 3){
            errorC++;
        }else if(error == 4){
            errorD++;
        }else if(error == 5){
            errorE++;
        }else if(error == 6){
            errorF++;
        }

    }
  }
  printf ("ALL Random TESTS Complete\n");
  printf ("Errors type 1: %d memory mismatch \n",errorA);
  printf ("Errors type 3: %d player didn't receive extra buy\n",errorB);
  printf ("Errors type 3: %d discarded but didn't receive coins\n",errorC);

  printf ("Errors type 4: %d estate not discarded\n",errorC);
  printf ("Errors type 5: %d choice doesn't match action\n",errorD);
  printf ("Errors type 6: %d didn't gain estate\n",errorE);

  return 0;
}
Exemplo n.º 12
0
	namespace path
	{
		bool unitTest()
		{
			char dest[255];

			//normalize("//", dest);
			//OX_ASSERT(strcmp(dest, "/") == 0);

			normalize("/../", dest);
			OX_ASSERT(strcmp(dest, "../") == 0);

			normalize("../c\\", dest);
			OX_ASSERT(strcmp(dest, "../c/") == 0);

			normalize("a//", dest);
			OX_ASSERT(strcmp(dest, "a/") == 0);


			normalize("\\/\\///\\/", dest);// \n
			OX_ASSERT(strcmp(dest, "") == 0);

			normalize("a/b/..\\//..///\\/../c\\\\/", dest);
			OX_ASSERT(strcmp(dest, "../c/") == 0);

			normalize("a/../c", dest);
			OX_ASSERT(strcmp(dest, "c") == 0);

			normalize("a/b/../../../c", dest);
			OX_ASSERT(strcmp(dest, "../c") == 0);

			normalize("..a/b/..\\//..///\\/../c\\\\/", dest);
			OX_ASSERT(strcmp(dest, "../c/") == 0);

			return true;
		}

#ifdef OX_DEBUG
		bool b = unitTest();
#endif

		void reverse(char *str)
		{
			int len = strlen(str);
			int half = len/2;
			for (int i = 0; i < half; ++i)
			{
				std::swap(str[i], str[len - i - 1]);
			}
		}

		void split(const char *src, char *destHead, char *destTail)
		{
			OX_ASSERT(src != destHead);
			OX_ASSERT(src != destTail);

			destHead[0] = 0;
			destTail[0] = 0;

			int i = 0;
			int len = strlen(src);
			while (len)
			{
				char c = src[len-1];
				if (c == '\\' || c == '/')
				{
					break;
				}

				destTail[i] = c;
				++i;
				--len;
			}
			destTail[i] = 0;
			reverse(destTail);

			memcpy(destHead, src, len);
			destHead[len] = 0;
		}

		void splitExt(const char *src, char *destHead, char *destTail)
		{
			OX_ASSERT(src != destHead);
			OX_ASSERT(src != destTail);

			destHead[0] = 0;
			destTail[0] = 0;

			int len = strlen(src);
			int i = 0;
			for (i = len - 1; i >= 0; --i)
			{
				if (src[i] == '.')
					break;
			}

			if (i == -1)
				i = len;
			memcpy(destHead, src, i);
			destHead[i] = 0;

			int n = len - i;
			memcpy(destTail, src + i, n);
			destTail[n] = 0;
		}

		void normalize(const char *src, char *dest)
		{
			char *copy = dest;
			OX_ASSERT(src != dest);

			char last = 0;
			

			*dest = 0;
			while(*src)
			{
				char c = *src;
				char last =  dest - 1 >= copy? *(dest - 1) : '/';
				char last_last =  dest - 2 >= copy ? *(dest - 2) : '/';

				if (c == '\\')
					c = '/';
				if (c == '/' && last == '.' && last_last == '.' && dest > copy + 2)
				{
					dest -= 3;
					while (dest > copy)
					{
						--dest;
						if (*dest == '/')
							break;						
					}

					++src;
					continue;
				}
				if (last == c && c == '/')
				{
					++src;
					continue;
				}				

				*dest = c;	

				//*(dest + 1) = 0;
				//log::message(copy);

				++src;
				++dest;
				
			}
			*dest = 0;
			int q=0;
		}
	}
Exemplo n.º 13
0
int main(int argc, char** argv) {
  DBG("[Lesson 1]: Arrays: Solutions 6");
  unitTest();
  DBG("[Lesson 1]: Arrays: Solutions 6 [END]");
  return 0;
}
Exemplo n.º 14
0
//-----------------------------------------------------------------------------
int main(int argc, char** argv) {
  DBG("[Lesson 1]: Sortings: Binary search");
  unitTest();
  DBG("[Lesson 1]: Sortings: Binary search [END]");
  return 0;
}
Exemplo n.º 15
0
int main(){
   int testVal = unitTest();
   printf("Outcome: %i\n", testVal);
   return 0;
}