Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkColorSequenceRainbowTest.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 // Testing
14 #include "mitkTestFixture.h"
15 #include "mitkTestingMacros.h"
16 
17 // std includes
18 #include <limits>
19 
20 // MITK includes
22 
23 // VTK includes
24 #include <vtkDebugLeaks.h>
25 
26 class mitkColorSequenceRainbowTestSuite : public mitk::TestFixture
27 {
28  CPPUNIT_TEST_SUITE(mitkColorSequenceRainbowTestSuite);
29 
30  MITK_TEST(GetNextColor_ReturnsADifferentColor);
31  MITK_TEST(GoToBegin_NextCallReturnsSameColorAsFirstCall);
32  MITK_TEST(GetNextColor_CanWrapAroundWithoutCrashing);
33  CPPUNIT_TEST_SUITE_END();
34 
35 
36 public:
41  void setUp() override
42  {
43  }
44 
45  void tearDown() override
46  {
47  }
48 
49  void GetNextColor_ReturnsADifferentColor()
50  {
51  mitk::ColorSequenceRainbow rainbowColorSequence;
52  mitk::Color color1 = rainbowColorSequence.GetNextColor();
53  mitk::Color color2 = rainbowColorSequence.GetNextColor();
54 
55  CPPUNIT_ASSERT_MESSAGE("Two consecutive colors are not equal.", color1 != color2);
56  }
57 
58  void GoToBegin_NextCallReturnsSameColorAsFirstCall()
59  {
60  mitk::ColorSequenceRainbow rainbowColorSequence;
61  mitk::Color color1 = rainbowColorSequence.GetNextColor();
62  rainbowColorSequence.GoToBegin();
63  mitk::Color color2 = rainbowColorSequence.GetNextColor();
64 
65  CPPUNIT_ASSERT_MESSAGE("GoToBegin is identical to beginning.", color1 == color2);
66  }
67 
68  void GetNextColor_CanWrapAroundWithoutCrashing()
69  {
70  int counter = 0;
71  try
72  {
73  mitk::ColorSequenceRainbow rainbowColorSequence;
74  mitk::Color color1 = rainbowColorSequence.GetNextColor();
75  mitk::Color color2 = rainbowColorSequence.GetNextColor();
76 
77  while (color1 != color2 && counter < std::numeric_limits<int>::max())
78  {
79  color2 = rainbowColorSequence.GetNextColor();
80  ++counter;
81  }
82  }
83  catch (...)
84  {
85  CPPUNIT_FAIL("Exception during rainbow color sequence color generation");
86  }
87  CPPUNIT_ASSERT_MESSAGE("Error free wraparound achieved.", counter < std::numeric_limits<int>::max());
88  }
89 };
90 
91 MITK_TEST_SUITE_REGISTRATION(mitkColorSequenceRainbow)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
Color GetNextColor() override
method to return another color
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
void GoToBegin() override
method to set the color-index to begin again
Test fixture for parameterized tests.
static T max(T x, T y)
Definition: svm.cpp:56
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)