forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hsv_tests.cpp
66 lines (56 loc) · 1.93 KB
/
hsv_tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Aseprite Gfx Library
// Copyright (C) 2001-2013 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gtest/gtest.h>
#include "gfx/hsv.h"
#include "gfx/rgb.h"
using namespace gfx;
using namespace std;
namespace gfx {
ostream& operator<<(ostream& os, const Hsv& hsv)
{
return os << "("
<< hsv.hueInt() << ", "
<< hsv.saturationInt() << ", "
<< hsv.valueInt() << "); real: ("
<< hsv.hue() << ", "
<< hsv.saturation() << ", "
<< hsv.value() << ")";
}
}
TEST(Hsv, Ctor)
{
EXPECT_EQ(35.0, Hsv(35.0, 0.50, 0.75).hue());
EXPECT_EQ(0.50, Hsv(35.0, 0.50, 0.75).saturation());
EXPECT_EQ(0.75, Hsv(35.0, 0.50, 0.75).value());
EXPECT_EQ(35, Hsv(35.0, 0.50, 0.75).hueInt());
EXPECT_EQ(50, Hsv(35.0, 0.50, 0.75).saturationInt());
EXPECT_EQ(75, Hsv(35.0, 0.50, 0.75).valueInt());
EXPECT_EQ(Hsv(0, 0, 0), Hsv());
}
TEST(Hsv, FromRgb)
{
EXPECT_EQ(Hsv( 0.0, 0.00, 0.00), Hsv(Rgb( 0, 0, 0)));
EXPECT_EQ(Hsv( 0.0, 1.00, 0.01), Hsv(Rgb( 3, 0, 0)));
EXPECT_EQ(Hsv( 0.0, 1.00, 0.99), Hsv(Rgb(252, 0, 0)));
EXPECT_EQ(Hsv( 0.0, 1.00, 1.00), Hsv(Rgb(255, 0, 0)));
EXPECT_EQ(Hsv( 60.0, 1.00, 0.75), Hsv(Rgb(191, 191, 0)));
EXPECT_EQ(Hsv(120.0, 1.00, 0.50), Hsv(Rgb( 0, 128, 0)));
EXPECT_EQ(Hsv(120.0, 1.00, 1.00), Hsv(Rgb( 0, 255, 0)));
EXPECT_EQ(Hsv(180.0, 0.50, 1.00), Hsv(Rgb(128, 255, 255)));
EXPECT_EQ(Hsv(240.0, 0.50, 1.00), Hsv(Rgb(128, 128, 255)));
EXPECT_EQ(Hsv(240.0, 1.00, 1.00), Hsv(Rgb( 0, 0, 255)));
EXPECT_EQ(Hsv(300.0, 0.66, 0.75), Hsv(Rgb(191, 64, 191)));
EXPECT_EQ(Hsv(360.0, 1.00, 0.99), Hsv(Rgb(252, 0, 0)));
EXPECT_EQ(Hsv(360.0, 1.00, 1.00), Hsv(Rgb(255, 0, 0)));
}
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}