There can be only one (filename convention)
[mussa.git] / alg / test / test_color.cpp
1 #include <boost/test/auto_unit_test.hpp>
2 #include <boost/test/floating_point_comparison.hpp>
3 #include <string>
4
5 #include "alg/color.hpp"
6
7 using namespace std;
8
9 BOOST_AUTO_TEST_CASE ( color )
10 {
11   const float tolerance = 1e-6;
12   const float zero = 0.0;
13   const float dotone = 0.1;
14   const float dottwo = 0.2;
15   const float dotthree = 0.3;
16   const float dotfour = 0.4;
17   Color c1;
18   BOOST_CHECK_CLOSE (c1.r(), zero, tolerance );
19   BOOST_CHECK_CLOSE (c1.g(), zero, tolerance );
20   BOOST_CHECK_CLOSE (c1.b(), zero, tolerance );
21   BOOST_CHECK_CLOSE (c1.a(), zero, tolerance );
22
23   Color c2(dotone, dottwo, dotthree, dotfour);
24   BOOST_CHECK_CLOSE (c2.r(), dotone, tolerance );
25   BOOST_CHECK_CLOSE (c2.g(), dottwo, tolerance );
26   BOOST_CHECK_CLOSE (c2.b(), dotthree, tolerance );
27   BOOST_CHECK_CLOSE (c2.a(), dotfour, tolerance );
28
29   Color c3(c2);
30   BOOST_CHECK_CLOSE (c3.r(), dotone, tolerance );
31   BOOST_CHECK_CLOSE (c3.g(), dottwo, tolerance );
32   BOOST_CHECK_CLOSE (c3.b(), dotthree, tolerance );
33   BOOST_CHECK_CLOSE (c3.a(), dotfour, tolerance );
34   BOOST_CHECK_EQUAL ( c2, c3 );
35
36   const float *colors = c3.get();
37   BOOST_CHECK_CLOSE (colors[Color::RedChannel   ], dotone, tolerance );
38   BOOST_CHECK_CLOSE (colors[Color::GreenChannel ], dottwo, tolerance );
39   BOOST_CHECK_CLOSE (colors[Color::BlueChannel  ], dotthree, tolerance );
40   BOOST_CHECK_CLOSE (colors[Color::AlphaChannel ], dotfour, tolerance );
41 }
42
43