Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 // Testing
18 #include "mitkTestFixture.h"
19 #include "mitkTestingMacros.h"
20 
21 // std includes
22 #include <limits>
23 
24 // MITK includes
26 
27 // VTK includes
28 #include <vtkDebugLeaks.h>
29 
30 class mitkColorSequenceRainbowTestSuite : public mitk::TestFixture
31 {
32  CPPUNIT_TEST_SUITE(mitkColorSequenceRainbowTestSuite);
33 
34  MITK_TEST(GetNextColor_ReturnsADifferentColor);
35  MITK_TEST(GoToBegin_NextCallReturnsSameColorAsFirstCall);
36  MITK_TEST(GetNextColor_CanWrapAroundWithoutCrashing);
37  CPPUNIT_TEST_SUITE_END();
38 
39 
40 public:
45  void setUp() override
46  {
47  }
48 
49  void tearDown() override
50  {
51  }
52 
53  void GetNextColor_ReturnsADifferentColor()
54  {
55  mitk::ColorSequenceRainbow rainbowColorSequence;
56  mitk::Color color1 = rainbowColorSequence.GetNextColor();
57  mitk::Color color2 = rainbowColorSequence.GetNextColor();
58 
59  CPPUNIT_ASSERT_MESSAGE("Two consecutive colors are not equal.", color1 != color2);
60  }
61 
62  void GoToBegin_NextCallReturnsSameColorAsFirstCall()
63  {
64  mitk::ColorSequenceRainbow rainbowColorSequence;
65  mitk::Color color1 = rainbowColorSequence.GetNextColor();
66  rainbowColorSequence.GoToBegin();
67  mitk::Color color2 = rainbowColorSequence.GetNextColor();
68 
69  CPPUNIT_ASSERT_MESSAGE("GoToBegin is identical to beginning.", color1 == color2);
70  }
71 
72  void GetNextColor_CanWrapAroundWithoutCrashing()
73  {
74  int counter = 0;
75  try
76  {
77  mitk::ColorSequenceRainbow rainbowColorSequence;
78  mitk::Color color1 = rainbowColorSequence.GetNextColor();
79  mitk::Color color2 = rainbowColorSequence.GetNextColor();
80 
81  while (color1 != color2 && counter < std::numeric_limits<int>::max())
82  {
83  color2 = rainbowColorSequence.GetNextColor();
84  ++counter;
85  }
86  }
87  catch (...)
88  {
89  CPPUNIT_FAIL("Exception during rainbow color sequence color generation");
90  }
91  CPPUNIT_ASSERT_MESSAGE("Error free wraparound achieved.", counter < std::numeric_limits<int>::max());
92  }
93 };
94 
95 MITK_TEST_SUITE_REGISTRATION(mitkColorSequenceRainbow)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
virtual Color GetNextColor() override
method to return another color
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
virtual 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:70
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)