int printDiffList(diffNode *pRoot){
    int sum;
    if(pRoot == NULL){
        return 0;
    }
    sum = printDiffList(pRoot->pLeft);
    printf("%d\t\t\t%d\n", pRoot->iDiff, pRoot->iRuns);
    sum = sum + printDiffList(pRoot->pRight);
    return sum + pRoot->iRuns;
}
/*********** MAIN FUNCTIION ***************/
int main(int argc, char *argv[]){
    //variables used for for-loop and to store total runs
    int i, iTotalRuns;

    //establish root for diffNode to store run info
    diffNode *pDiffRoot = NULL;

    //establish seed for random number generatore
    srand(time(NULL));

    //generate list of random numbers 50 times;
    for(i = 0; i<50; i++){
        node *pRoot = NULL;
        generateList(&pRoot, &pDiffRoot);
        //free tree after each iteration
        freeList(pRoot);
    }

    //print level differences and number of runs
    printf("\nSUMMARY\n");
    printf("Level Difference\t# Runs\n");
    iTotalRuns = printDiffList(pDiffRoot);
    printf("\t\t\t__\nTotal Runs:\t\t%d\n", iTotalRuns);
    printf("\nNote: Only level differences with at least 1 qualifying run are shown.\n");

    //free diffTree
    freeDiffList(pDiffRoot);

    return 0;
}
Пример #3
0
bool runTest(QString file1, QString file2, QString file3, QString expectedResultFile, QString actualResultFile, int maxLength)
{
   Options options;
   Diff3LineList actualDiff3LineList, expectedDiff3LineList;
   QTextCodec *p_codec = QTextCodec::codecForName("UTF-8");
   QTextStream out(stdout);

   options.m_bIgnoreCase = false;
   options.m_bDiff3AlignBC = true;

   m_pOptions = &options;

   SourceData m_sd1, m_sd2, m_sd3;

   QString msgprefix = "Running test with ";
   QString filepattern = QString(file1).replace("_base.", "_*.");
   QString msgsuffix = QString("...%1").arg("", maxLength - filepattern.length());
   out << msgprefix << filepattern << msgsuffix;
   out.flush();

   m_sd1.setOptions(&options);
   m_sd1.setFilename(file1);
   m_sd1.readAndPreprocess(p_codec, false);

   m_sd2.setOptions(&options);
   m_sd2.setFilename(file2);
   m_sd2.readAndPreprocess(p_codec, false);

   m_sd3.setOptions(&options);
   m_sd3.setFilename(file3);
   m_sd3.readAndPreprocess(p_codec, false);

   determineFileAlignment(m_sd1, m_sd2, m_sd3, actualDiff3LineList);

   loadExpectedAlignmentFile(expectedResultFile, expectedDiff3LineList);

   Diff3LineList::iterator p_actual = actualDiff3LineList.begin();
   Diff3LineList::iterator p_expected = expectedDiff3LineList.begin();
   bool equal = true;

   equal = (actualDiff3LineList.size() == expectedDiff3LineList.size());

   while(equal && (p_actual != actualDiff3LineList.end()))
   {
      equal = (p_actual->lineA == p_expected->lineA) &&
              (p_actual->lineB == p_expected->lineB) &&
              (p_actual->lineC == p_expected->lineC);
      p_actual++;
      p_expected++;
   }

   if(equal)
   {
      out << "OK" << endl;
   }
   else
   {
      out << "NOK" << endl;

      writeActualAlignmentFile(actualResultFile, actualDiff3LineList);

      out << "Actual result (written to " << actualResultFile << "):" << endl;
      out << "----------------------------------------------------------------------------------------------" << endl;
      printDiffList(actualDiff3LineList, m_sd1, m_sd2, m_sd3);
      out << "----------------------------------------------------------------------------------------------" << endl;
      out << "Expected result:" << endl;
      out << "----------------------------------------------------------------------------------------------" << endl;
      printDiffList(expectedDiff3LineList, m_sd1, m_sd2, m_sd3);
      out << "----------------------------------------------------------------------------------------------" << endl;
   }

   return equal;
}