OpenWalnut  1.4.0
WColor_test.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WCOLOR_TEST_H
00026 #define WCOLOR_TEST_H
00027 
00028 #include <sstream>
00029 #include <string>
00030 
00031 #include <cxxtest/TestSuite.h>
00032 
00033 #include "../WColor.h"
00034 #include "WColorTraits.h"
00035 
00036 /**
00037  * Unit tests the color helping functions
00038  */
00039 class WColorTest : public CxxTest::TestSuite
00040 {
00041 public:
00042     /**
00043      * Red in HSV is ( 0, 1, 1 ) and in RGB ( 1, 0, 0 )
00044      * Green in HSV is ( 0.3, 1, 1 ) and in RGB ( 0, 1, 0 )
00045      * and checks some dark green
00046      */
00047     void testHSVConversion( void )
00048     {
00049         WColor c = convertHSVtoRGBA( 0, 1, 1 );
00050         TS_ASSERT_DELTA( c[0], 1, 0.00001 );
00051         TS_ASSERT_DELTA( c[1], 0, 0.00001 );
00052         TS_ASSERT_DELTA( c[2], 0, 0.00001 );
00053         c = convertHSVtoRGBA( 1, 1, 1 ); // this is also red
00054         TS_ASSERT_DELTA( c[0], 1, 0.00001 );
00055         TS_ASSERT_DELTA( c[1], 0, 0.00001 );
00056         TS_ASSERT_DELTA( c[2], 0, 0.00001 );
00057         c = convertHSVtoRGBA( 1.0 / 3.0, 1, 1 );
00058         TS_ASSERT_DELTA( c[0], 0, 0.00001 );
00059         TS_ASSERT_DELTA( c[1], 1, 0.00001 );
00060         TS_ASSERT_DELTA( c[2], 0, 0.00001 );
00061         c = convertHSVtoRGBA( 0.3, 0.3, 0.3 ); // dark green
00062         TS_ASSERT_DELTA( c[0], 0.2280, 0.0001 );
00063         TS_ASSERT_DELTA( c[1], 0.3, 0.0001 );
00064         TS_ASSERT_DELTA( c[2], 0.2099, 0.0001 );
00065     }
00066 };
00067 
00068 #endif  // WCOLOR_TEST_H