Beispiel #1
0
//tests if folded text can be edited
void QEditorTest::activeFolding(){
	QFETCH(QString, editorText);
	QFETCH(QList<int>, foldAt);
	QFETCH(QList<int>, hiddenLines);
	QFETCH(int, cursorAL);
	QFETCH(int, cursorAC);
	QFETCH(int, cursorL);
	QFETCH(int, cursorC);
	QFETCH(QString, textToInsert);
	QFETCH(QString, newEditorText);
	QFETCH(QList<int>, newHiddenLines);

	editor->setText(editorText, false);

	foreach(const int &i, foldAt)
		editor->document()->collapse(i);
	for (int i=0;i<editor->document()->lines();i++)
		QVERIFY2(editor->document()->line(i).isHidden() == hiddenLines.contains(i),qPrintable(QString::number(i)));
	compareLists(editor->document()->impl()->testGetHiddenLines(), hiddenLines);

	QDocumentCursor editCursor = editor->document()->cursor(cursorAL,cursorAC,cursorL,cursorC);
	editCursor.insertText(textToInsert);

	QEQUAL(editor->document()->text(), newEditorText);
	for (int i=0;i<editor->document()->lines();i++)
		QVERIFY2(editor->document()->line(i).isHidden() == newHiddenLines.contains(i),qPrintable(QString::number(i)));

	compareLists(editor->document()->impl()->testGetHiddenLines(), newHiddenLines);
}
Beispiel #2
0
//checks if collapsing/expanding works
void QEditorTest::passiveFolding(){
	QFETCH(QString, editorText);
	QFETCH(QList<int>, foldAt);
	QFETCH(QList<int>, hiddenLines1);
	QFETCH(QList<int>, unFoldAt);
	QFETCH(QList<int>, hiddenLines2);
	QFETCH(QList<int>, foldAtAgain);
	QFETCH(QList<int>, hiddenLines3);

	editor->setText(editorText, false);

	foreach(const int &i, foldAt)
		editor->document()->collapse(i);
	
	for (int i=0;i<editor->document()->lines();i++)
		QVERIFY2(editor->document()->line(i).isHidden() == hiddenLines1.contains(i),qPrintable(QString::number(i)));

	compareLists(editor->document()->impl()->testGetHiddenLines(), hiddenLines1);
	
	foreach(const int &i, unFoldAt)
		editor->document()->expand(i);
	for (int i=0;i<editor->document()->lines();i++)
		QVERIFY2(editor->document()->line(i).isHidden() == hiddenLines2.contains(i),qPrintable(QString::number(i)));

	compareLists(editor->document()->impl()->testGetHiddenLines(), hiddenLines2);

	foreach(const int &i, foldAtAgain)
		editor->document()->collapse(i);
	for (int i=0;i<editor->document()->lines();i++)
		QVERIFY2(editor->document()->line(i).isHidden() == hiddenLines3.contains(i),qPrintable(QString::number(i)));

	compareLists(editor->document()->impl()->testGetHiddenLines(), hiddenLines3);
}
Beispiel #3
0
//checks if block-commands (e.g indent, comment) work with folded text
void QEditorTest::foldedText(){
	QFETCH(QString, editorText);
	QFETCH(QList<int>, foldAt);
	QFETCH(QList<int>, hiddenLines);
	QFETCH(int, froml);
	QFETCH(int, fromc);
	QFETCH(int, tol);
	QFETCH(int, toc);
	QFETCH(QString, operation);
	QFETCH(QString, newEditorText);
	QFETCH(QList<int>, newHiddenLines);

	editor->setText(editorText, false);
	foreach(const int &i, foldAt)
		editor->document()->collapse(i);
	for (int i=0;i<editor->document()->lines();i++)
		QVERIFY2(editor->document()->line(i).isHidden() == hiddenLines.contains(i),qPrintable(QString::number(i)));
	compareLists(editor->document()->impl()->testGetHiddenLines(), hiddenLines);
	editor->setCursor(editor->document()->cursor(froml,fromc,tol,toc));
	if (operation=="indent") editor->indentSelection();
	else if (operation=="unindent") editor->unindentSelection();
	else if (operation=="comment") editor->commentSelection();
	else if (operation=="uncomment") editor->uncommentSelection();
	else qFatal("invalid operation");
	QEQUAL(editor->document()->text(), newEditorText);
	for (int i=0;i<editor->document()->lines();i++)
		QVERIFY2(editor->document()->line(i).isHidden() == newHiddenLines.contains(i),qPrintable(QString::number(i)));
	compareLists(editor->document()->impl()->testGetHiddenLines(), newHiddenLines);
}
Beispiel #4
0
/* Function to check if given linked list is
  palindrome or not */
bool isPalindrome(struct node *head)
{
   struct node *slow_ptr = head;
   struct node *fast_ptr = head;
   struct node *second_half;
   struct node *prev_of_slow_ptr = head;
   char res;

   if(head!=NULL)
   {
       /* Get the middle of the list. Move slow_ptr by 1
         and fast_ptrr by 2, slow_ptr will have the |_n/2_|th
         node */
       while((fast_ptr->next)!=NULL &&
               (fast_ptr->next->next)!=NULL)
       {
          fast_ptr = fast_ptr->next->next;

          /*We need previous of the slow_ptr for
           linked lists  with odd elements */
          prev_of_slow_ptr = slow_ptr;
          slow_ptr = slow_ptr->next;
       }

       /* Case where we have even no of elements */
       if(fast_ptr->next != NULL)
       {
         second_half = slow_ptr->next;
         reverse(&second_half);
         slow_ptr->next = NULL;
         res = compareLists(head, second_half);

         /*construct the original list back*/
         reverse(&second_half);
         slow_ptr->next = second_half;
       }

       /* Case where we have odd no. of elements. Neither first
          nor second list should have the middle element */
       else
       {
          second_half = slow_ptr->next;
          prev_of_slow_ptr->next = NULL;
          reverse(&second_half);
          res = compareLists(head, second_half);

         /*construct the original list back*/
         reverse(&second_half);
         prev_of_slow_ptr->next = slow_ptr;
         slow_ptr->next = second_half;
       }

       return res;
   }
}
void ParamCompareDialog::loadParameterFile()
{
    ui->compareTableWidget->setRowCount(0);

    QString homeDir = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
    QDir parameterDir = QDir(QGC::parameterDirectory());

    if(!parameterDir.exists())
        parameterDir.mkdir(parameterDir.path());

    QString filename = QFileDialog::getOpenFileName(this,tr("Open File To Compare"),
                                                    QGC::parameterDirectory(), "*.param");

    if(filename.length() == 0) {
        return;
    }

    QFile file(filename);
    if (!file.open(QIODevice::ReadOnly))
    {
        QMessageBox::information(this,"Error","Unable to open the file.");
        return;
    }

    QString filestring = file.readAll();
    file.close();

    populateParamListFromString(filestring, m_newList);

    compareLists();
}
void tester(int n) {
	int i;
	for (i = 0; i < n; i++) {
		struct node * list = createList(cases[i].list, cases[i].n);
		sort(list);
		if (compareLists(list, createList(cases[i].r, cases[i].rSize)))
			printf("PASS\n");
		else
			printf("FAIL\n");
	}
}
Beispiel #7
0
/* Function to check if given linked list is
  palindrome or not */
bool isPalindrome(struct node *head)
{
    struct node *slow_ptr = head, *fast_ptr = head;
    struct node *second_half, *prev_of_slow_ptr = head;
    struct node *midnode = NULL;  // To handle odd size list
    bool res = true; // initialize result

    if (head!=NULL && head->next!=NULL)
    {
        /* Get the middle of the list. Move slow_ptr by 1
          and fast_ptrr by 2, slow_ptr will have the middle
          node */
        while (fast_ptr != NULL && fast_ptr->next != NULL)
        {
            fast_ptr = fast_ptr->next->next;

            /*We need previous of the slow_ptr for
             linked lists  with odd elements */
            prev_of_slow_ptr = slow_ptr;
            slow_ptr = slow_ptr->next;
        }


        /* fast_ptr would become NULL when there are even elements in list.
           And not NULL for odd elements. We need to skip the middle node
           for odd case and store it somewhere so that we can restore the
           original list*/
        if (fast_ptr != NULL)
        {
            midnode = slow_ptr;
            slow_ptr = slow_ptr->next;
        }

        // Now reverse the second half and compare it with first half
        second_half = slow_ptr;
        prev_of_slow_ptr->next = NULL; // NULL terminate first half
        reverse(&second_half);  // Reverse the second half
        res = compareLists(head, second_half); // compare

        /* Construct the original list back */
         reverse(&second_half); // Reverse the second half again
         if (midnode != NULL)  // If there was a mid node (odd size case) which
                               // was not part of either first half or second half.
         {
            prev_of_slow_ptr->next = midnode;
            midnode->next = second_half;
         }
         else  prev_of_slow_ptr->next = second_half;
    }
    return res;
}
void ParamCompareDialog::loadParameterFile(const QString &filename)
{
    QFile file(filename);
    if (!file.open(QIODevice::ReadOnly))
    {
        QMessageBox::information(this,"Error","Unable to open the file.");
        return;
    }

    QString filestring = file.readAll();
    file.close();

    populateParamListFromString(filestring, m_newList, this);

    compareLists();
}
bool isPalindrome(struct node* head)
{
  struct node * slow_ptr = head;
  struct node* fast_ptr = head;
  struct node* second_half;
  struct node* prev_of_slow_ptr = head;
  struct node* midnode = NULL; // To handle odd size list
  bool res = true; //initialize result

  if (head != NULL && head->next != NULL)
    {
      //travel through the list
      while (fast_ptr != NULL && fast_ptr->next != NULL)
	{
	  fast_ptr = fast_ptr->next->next;

	  prev_of_slow_ptr = slow_ptr;
	  slow_ptr = slow_ptr->next;
	}
      
      //odd elements in the LL
      if (fast_ptr != NULL)
	{
	  midnode = slow_ptr;
	  slow_ptr = slow_ptr->next;
	}

      //reverse the second half;
      second_half = slow_ptr;
      prev_of_slow_ptr->next = NULL;
      reverse(&second_half);
      //by now both head and second half lists should be at the same length
      res = compareLists(head, second_half);

      //recover the list
      reverse(&second_half);
      //odd elements case
      if (midnode != NULL)
	{
	  prev_of_slow_ptr->next = midnode;
	  midnode->next = second_half;
	}
      //even elements case
      else prev_of_slow_ptr->next = second_half;
    }
  return res;
}
        // Fetch the validators from a source and process the result
        //
        void fetchAndProcessSource (SourceInfo& sourceInfo)
        {
            Array <Validator::Info> newInfo = sourceInfo.source->fetch ();

            if (newInfo.size () != 0)
            {
                sourceInfo.status = SourceInfo::statusFetched;

                sourceInfo.whenToFetch = Time::getCurrentTime () +
                    RelativeTime (hoursBetweenFetches * 60.0 * 60.0);

                Validator::List::Ptr newList (createListFromInfo (newInfo));

                compareLists (*sourceInfo.list, *newList, *this);

                sourceInfo.list = newList;
            }
            else
            {
                // Failed to fetch, don't update fetch time
                sourceInfo.status = SourceInfo::statusFailed;
                sourceInfo.numberOfFailures++;
            }
        }