~ubuntu-branches/ubuntu/precise/openwalnut/precise

« back to all changes in this revision

Viewing changes to src/core/common/test/WColor_test.h

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Eichelbaum
  • Date: 2011-06-21 10:26:54 UTC
  • Revision ID: james.westby@ubuntu.com-20110621102654-rq0zf436q949biih
Tags: upstream-1.2.5
ImportĀ upstreamĀ versionĀ 1.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//---------------------------------------------------------------------------
 
2
//
 
3
// Project: OpenWalnut ( http://www.openwalnut.org )
 
4
//
 
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
 
6
// For more information see http://www.openwalnut.org/copying
 
7
//
 
8
// This file is part of OpenWalnut.
 
9
//
 
10
// OpenWalnut is free software: you can redistribute it and/or modify
 
11
// it under the terms of the GNU Lesser General Public License as published by
 
12
// the Free Software Foundation, either version 3 of the License, or
 
13
// (at your option) any later version.
 
14
//
 
15
// OpenWalnut is distributed in the hope that it will be useful,
 
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
// GNU Lesser General Public License for more details.
 
19
//
 
20
// You should have received a copy of the GNU Lesser General Public License
 
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
 
22
//
 
23
//---------------------------------------------------------------------------
 
24
 
 
25
#ifndef WCOLOR_TEST_H
 
26
#define WCOLOR_TEST_H
 
27
 
 
28
#include <sstream>
 
29
#include <string>
 
30
 
 
31
#include <cxxtest/TestSuite.h>
 
32
 
 
33
#include "../WColor.h"
 
34
#include "WColorTraits.h"
 
35
 
 
36
/**
 
37
 * Unit tests the color helping functions
 
38
 */
 
39
class WColorTest : public CxxTest::TestSuite
 
40
{
 
41
public:
 
42
 
 
43
    /**
 
44
     * Red in HSV is ( 0, 1, 1 ) and in RGB ( 1, 0, 0 )
 
45
     * Green in HSV is ( 0.3, 1, 1 ) and in RGB ( 0, 1, 0 )
 
46
     * and checks some dark green
 
47
     */
 
48
    void testHSVConversion( void )
 
49
    {
 
50
        WColor c = convertHSVtoRGBA( 0, 1, 1 );
 
51
        TS_ASSERT_DELTA( c[0], 1, 0.00001 );
 
52
        TS_ASSERT_DELTA( c[1], 0, 0.00001 );
 
53
        TS_ASSERT_DELTA( c[2], 0, 0.00001 );
 
54
        c = convertHSVtoRGBA( 1, 1, 1 ); // this is also red
 
55
        TS_ASSERT_DELTA( c[0], 1, 0.00001 );
 
56
        TS_ASSERT_DELTA( c[1], 0, 0.00001 );
 
57
        TS_ASSERT_DELTA( c[2], 0, 0.00001 );
 
58
        c = convertHSVtoRGBA( 1.0 / 3.0, 1, 1 );
 
59
        TS_ASSERT_DELTA( c[0], 0, 0.00001 );
 
60
        TS_ASSERT_DELTA( c[1], 1, 0.00001 );
 
61
        TS_ASSERT_DELTA( c[2], 0, 0.00001 );
 
62
        c = convertHSVtoRGBA( 0.3, 0.3, 0.3 ); // dark green
 
63
        TS_ASSERT_DELTA( c[0], 0.2280, 0.0001 );
 
64
        TS_ASSERT_DELTA( c[1], 0.3, 0.0001 );
 
65
        TS_ASSERT_DELTA( c[2], 0.2099, 0.0001 );
 
66
    }
 
67
};
 
68
 
 
69
#endif  // WCOLOR_TEST_H