<commit_before>/*===================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.

This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.

See LICENSE.txt or http://www.mitk.org for details.

===================================================================*/

#include <mitkNavigationDataSequentialPlayer.h>
#include <mitkStandardFileLocations.h>
#include "mitkTestingMacros.h"
#include <mitkTestFixture.h>
#include "mitkNavigationDataReaderXML.h"

#include <iostream>
#include <sstream>

//foe exceptions
#include "mitkIGTException.h"
#include "mitkIGTIOException.h"

class mitkNavigationDataSequentialPlayerTestSuite : public mitk::TestFixture
{
  CPPUNIT_TEST_SUITE(mitkNavigationDataSequentialPlayerTestSuite);
  MITK_TEST(TestStandardWorkflow);
  MITK_TEST(TestRestartWithNewNavigationDataSet);
  MITK_TEST(TestGoToSnapshotException);
  MITK_TEST(TestSetXMLStringException);
  MITK_TEST(TestDoubleUpdate);
  CPPUNIT_TEST_SUITE_END();

private:
  /** Members used inside the different test methods. All members are initialized via setUp().*/
  mitk::NavigationDataSet::Pointer NavigationDataSet;
  mitk::NavigationDataSequentialPlayer::Pointer player;

public:

  void setUp(){
    player = mitk::NavigationDataSequentialPlayer::New();
    std::string file = GetTestDataFilePath("IGT-Data/NavigationDataTestData_2ToolsDouble.xml");
    mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New();
    NavigationDataSet =reader->Read(file);
  }

  void tearDown()
  {
  }

  bool runLoop()
  {
    player->Update();
    mitk::NavigationData::Pointer nd0;
    mitk::NavigationData::Pointer nd1;
    for(unsigned int i=0; i<player->GetNumberOfSnapshots(); ++i)
    {
      nd0 = player->GetOutput(0);
      nd1 = player->GetOutput(1);

      // test some values
      if(nd0.IsNull() || nd1.IsNull()) return false;

      if(i==0)
      {
        mitk::NavigationData::Pointer ref0 = NavigationDataSet->GetNavigationDataForIndex(0,0);
        mitk::NavigationData::Pointer ref1 = NavigationDataSet->GetNavigationDataForIndex(0,1);
        if (!(ref0->GetOrientation().as_vector() == nd0->GetOrientation().as_vector())) {return false;}
        if (!(ref1->GetOrientation().as_vector() == nd1->GetOrientation().as_vector())) {return false;}
        if (!(ref0->GetPosition().GetVnlVector() == nd0->GetPosition().GetVnlVector())) {return false;}
        if (!(ref1->GetPosition().GetVnlVector() == nd1->GetPosition().GetVnlVector())) {return false;}
      }
      else if(i==1)
      {
        mitk::NavigationData::Pointer ref0 = NavigationDataSet->GetNavigationDataForIndex(1,0);
        mitk::NavigationData::Pointer ref1 = NavigationDataSet->GetNavigationDataForIndex(1,1);
        if (!(ref0->GetOrientation().as_vector() == nd0->GetOrientation().as_vector())) {return false;}
        if (!(ref1->GetOrientation().as_vector() == nd1->GetOrientation().as_vector())) {return false;}
        if (!(ref0->GetPosition().GetVnlVector() == nd0->GetPosition().GetVnlVector())) {return false;}
        if (!(ref1->GetPosition().GetVnlVector() == nd1->GetPosition().GetVnlVector())) {return false;}
      }
      else if(i==2) // should be repeated
      {
        mitk::NavigationData::Pointer ref0 = NavigationDataSet->GetNavigationDataForIndex(2,0);
        mitk::NavigationData::Pointer ref1 = NavigationDataSet->GetNavigationDataForIndex(2,1);
        if (!(ref0->GetOrientation().as_vector() == nd0->GetOrientation().as_vector())) {return false;}
        if (!(ref1->GetOrientation().as_vector() == nd1->GetOrientation().as_vector())) {return false;}
        if (!(ref0->GetPosition().GetVnlVector() == nd0->GetPosition().GetVnlVector())) {return false;}
        if (!(ref1->GetPosition().GetVnlVector() == nd1->GetPosition().GetVnlVector())) {return false;}
      }

      // Goto next Snapshot
      player->GoToNextSnapshot();
      player->Update();
    }
    return true;
  }

  void TestStandardWorkflow()
  {
    // Set NavigationDatas for player
    player->SetNavigationDataSet(NavigationDataSet);

    MITK_TEST_CONDITION(player->GetNumberOfSnapshots() == 3,"Testing method SetXMLString with 3 navigation datas.");
    MITK_TEST_CONDITION(player->GetNumberOfIndexedOutputs() == 2,"Testing number of outputs");

    //rest repeat
    player->SetRepeat(true);

    MITK_TEST_CONDITION(runLoop(),"Testing first run.");
    MITK_TEST_CONDITION(runLoop(),"Testing second run."); //repeat is on should work a second time

    // now test the go to snapshot function
    player->GoToSnapshot(2);
    mitk::NavigationData::Pointer nd1 = player->GetOutput(1);
    mitk::NavigationData::Pointer ref1 = NavigationDataSet->GetNavigationDataForIndex(2,1);
    MITK_TEST_CONDITION(ref1->GetPosition().GetVnlVector() == nd1->GetPosition().GetVnlVector(),
      "Testing GoToSnapshot() [1]");

    //MITK_TEST_OUTPUT( << "Reference:" << ref1->GetPosition().GetVnlVector() << "\tObserved: " << nd1->GetPosition().GetVnlVector());

    player->GoToSnapshot(0);
    mitk::NavigationData::Pointer nd0 = player->GetOutput();
    mitk::NavigationData::Pointer ref0 = NavigationDataSet->GetNavigationDataForIndex(0,0);
    MITK_TEST_CONDITION(ref0->GetOrientation().as_vector() == nd0->GetOrientation().as_vector(),
      "Testing GoToSnapshot() [2]");

    //MITK_TEST_OUTPUT( << "Reference" << ref0->GetPosition().GetVnlVector() << "\tObserved:" <<nd0->GetOrientation().as_vector() );
  }

  void TestRestartWithNewNavigationDataSet()
  {
    player->SetNavigationDataSet(NavigationDataSet);
    mitk::NavigationData::PositionType nd1 = player->GetOutput(0)->GetPosition();
    player->SetNavigationDataSet(NavigationDataSet);
    player->Update();
    mitk::NavigationData::PositionType nd2 = player->GetOutput(0)->GetPosition();
<commit_msg>Another TEst Case fixed for Sequential DataPlayer<commit_after>/*===================================================================

The Medical Imaging Interaction Toolkit (MITK)

Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.

This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.

See LICENSE.txt or http://www.mitk.org for details.

===================================================================*/

#include <mitkNavigationDataSequentialPlayer.h>
#include <mitkStandardFileLocations.h>
#include "mitkTestingMacros.h"
#include <mitkTestFixture.h>
#include "mitkNavigationDataReaderXML.h"

#include <iostream>
#include <sstream>

//foe exceptions
#include "mitkIGTException.h"
#include "mitkIGTIOException.h"

class mitkNavigationDataSequentialPlayerTestSuite : public mitk::TestFixture
{
  CPPUNIT_TEST_SUITE(mitkNavigationDataSequentialPlayerTestSuite);
  MITK_TEST(TestStandardWorkflow);
  MITK_TEST(TestRestartWithNewNavigationDataSet);
  MITK_TEST(TestGoToSnapshotException);
  MITK_TEST(TestSetXMLStringException);
  MITK_TEST(TestDoubleUpdate);
  CPPUNIT_TEST_SUITE_END();

private:
  /** Members used inside the different test methods. All members are initialized via setUp().*/
  mitk::NavigationDataSet::Pointer NavigationDataSet;
  mitk::NavigationDataSequentialPlayer::Pointer player;

public:

  void setUp(){
    player = mitk::NavigationDataSequentialPlayer::New();
    std::string file = GetTestDataFilePath("IGT-Data/NavigationDataTestData_2ToolsDouble.xml");
    mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New();
    NavigationDataSet =reader->Read(file);
  }

  void tearDown()
  {
  }

  bool runLoop()
  {
    player->Update();
    mitk::NavigationData::Pointer nd0;
    mitk::NavigationData::Pointer nd1;
    for(unsigned int i=0; i<player->GetNumberOfSnapshots(); ++i)
    {
      nd0 = player->GetOutput(0);
      nd1 = player->GetOutput(1);

      // test some values
      if(nd0.IsNull() || nd1.IsNull()) return false;

      if(i==0)
      {
        mitk::NavigationData::Pointer ref0 = NavigationDataSet->GetNavigationDataForIndex(0,0);
        mitk::NavigationData::Pointer ref1 = NavigationDataSet->GetNavigationDataForIndex(0,1);
        if (!(ref0->GetOrientation().as_vector() == nd0->GetOrientation().as_vector())) {return false;}
        if (!(ref1->GetOrientation().as_vector() == nd1->GetOrientation().as_vector())) {return false;}
        if (!(ref0->GetPosition().GetVnlVector() == nd0->GetPosition().GetVnlVector())) {return false;}
        if (!(ref1->GetPosition().GetVnlVector() == nd1->GetPosition().GetVnlVector())) {return false;}
      }
      else if(i==1)
      {
        mitk::NavigationData::Pointer ref0 = NavigationDataSet->GetNavigationDataForIndex(1,0);
        mitk::NavigationData::Pointer ref1 = NavigationDataSet->GetNavigationDataForIndex(1,1);
        if (!(ref0->GetOrientation().as_vector() == nd0->GetOrientation().as_vector())) {return false;}
        if (!(ref1->GetOrientation().as_vector() == nd1->GetOrientation().as_vector())) {return false;}
        if (!(ref0->GetPosition().GetVnlVector() == nd0->GetPosition().GetVnlVector())) {return false;}
        if (!(ref1->GetPosition().GetVnlVector() == nd1->GetPosition().GetVnlVector())) {return false;}
      }
      else if(i==2) // should be repeated
      {
        mitk::NavigationData::Pointer ref0 = NavigationDataSet->GetNavigationDataForIndex(2,0);
        mitk::NavigationData::Pointer ref1 = NavigationDataSet->GetNavigationDataForIndex(2,1);
        if (!(ref0->GetOrientation().as_vector() == nd0->GetOrientation().as_vector())) {return false;}
        if (!(ref1->GetOrientation().as_vector() == nd1->GetOrientation().as_vector())) {return false;}
        if (!(ref0->GetPosition().GetVnlVector() == nd0->GetPosition().GetVnlVector())) {return false;}
        if (!(ref1->GetPosition().GetVnlVector() == nd1->GetPosition().GetVnlVector())) {return false;}
      }

      // Goto next Snapshot
      player->GoToNextSnapshot();
      player->Update();
    }
    return true;
  }

  void TestStandardWorkflow()
  {
    // Set NavigationDatas for player
    player->SetNavigationDataSet(NavigationDataSet);

    MITK_TEST_CONDITION(player->GetNumberOfSnapshots() == 3,"Testing method SetXMLString with 3 navigation datas.");
    MITK_TEST_CONDITION(player->GetNumberOfIndexedOutputs() == 2,"Testing number of outputs");

    //rest repeat
    player->SetRepeat(true);

    MITK_TEST_CONDITION(runLoop(),"Testing first run.");
    MITK_TEST_CONDITION(runLoop(),"Testing second run."); //repeat is on should work a second time

    // now test the go to snapshot function
    player->GoToSnapshot(2);
    mitk::NavigationData::Pointer nd1 = player->GetOutput(1);
    mitk::NavigationData::Pointer ref1 = NavigationDataSet->GetNavigationDataForIndex(2,1);
    MITK_TEST_CONDITION(ref1->GetPosition().GetVnlVector() == nd1->GetPosition().GetVnlVector(),
      "Testing GoToSnapshot() [1]");

    //MITK_TEST_OUTPUT( << "Reference:" << ref1->GetPosition().GetVnlVector() << "\tObserved: " << nd1->GetPosition().GetVnlVector());

    player->GoToSnapshot(0);
    mitk::NavigationData::Pointer nd0 = player->GetOutput();
    mitk::NavigationData::Pointer ref0 = NavigationDataSet->GetNavigationDataForIndex(0,0);
    MITK_TEST_CONDITION(ref0->GetOrientation().as_vector() == nd0->GetOrientation().as_vector(),
      "Testing GoToSnapshot() [2]");

    //MITK_TEST_OUTPUT( << "Reference" << ref0->GetPosition().GetVnlVector() << "\tObserved:" <<nd0->GetOrientation().as_vector() );
  }

  void TestRestartWithNewNavigationDataSet()
  {
    player->SetNavigationDataSet(NavigationDataSet);
    mitk::NavigationData::PositionType nd1 = player->GetOutput(0)->GetPosition();
    player->SetNavigationDataSet(NavigationDataSet);
    mitk::NavigationData::PositionType nd2 = player->GetOutput(0)->GetPosition();

{'fraction_non_alphanumeric': 0.16758059155865737, 'fraction_numerical': 0.013791957460950481, 'mean_word_length': 5.04570567553993, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 136, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1371172', 'n_tokens_mistral': 3561, 'n_tokens_neox': 3485, 'n_words': 639}