Nux

Merge lp:~michihenning/nux/random-color into lp:nux

Proposed by Michi Henning
Status: Merged
Approved by: Michi Henning
Approved revision: 718
Merged at revision: 719
Proposed branch: lp:~michihenning/nux/random-color
Merge into: lp:nux
Diff against target: 46 lines (+37/-2)
1 file modified
tests/gtest-nuxcore-color.cpp (+37/-2)
To merge this branch: bzr merge lp:~michihenning/nux/random-color
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Pending
Unity Team Pending
Review via email: mp+135835@code.launchpad.net

Commit message

Added unit test for RandomColor().

Description of the change

Added unit test for RandomColor().

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/gtest-nuxcore-color.cpp'
2--- tests/gtest-nuxcore-color.cpp 2012-11-22 02:40:42 +0000
3+++ tests/gtest-nuxcore-color.cpp 2012-11-23 08:16:19 +0000
4@@ -322,5 +322,40 @@
5 EXPECT_EQ(rgb.blue, color.blue);
6 }
7
8-}
9-
10+TEST(TestColor, TestRandomColor)
11+{
12+ float rmin = 1.0f;
13+ float rmax = 0.0f;
14+ float gmin = 1.0f;
15+ float gmax = 0.0f;
16+ float bmin = 1.0f;
17+ float bmax = 0.0f;
18+
19+ for (int i = 0; i < 100; ++i)
20+ {
21+ nux::Color c = nux::color::RandomColor();
22+ EXPECT_EQ(1.0f, c.alpha);
23+ rmin = std::min(rmin, c.red);
24+ rmax = std::max(rmax, c.red);
25+ gmin = std::min(gmin, c.green);
26+ gmax = std::max(gmax, c.green);
27+ bmin = std::min(bmin, c.blue);
28+ bmax = std::max(bmax, c.blue);
29+ }
30+
31+ // Ultra unlikely that we create 100 identical values in a row.
32+ // The universe will end long before this happens.
33+ EXPECT_NE(rmin, rmax);
34+ EXPECT_NE(gmin, gmax);
35+ EXPECT_NE(bmin, bmax);
36+
37+ // Values must have changed from the initial settings
38+ EXPECT_NE(1.0f, rmin);
39+ EXPECT_NE(0.0f, rmax);
40+ EXPECT_NE(1.0f, gmin);
41+ EXPECT_NE(0.0f, gmax);
42+ EXPECT_NE(1.0f, bmin);
43+ EXPECT_NE(0.0f, bmax);
44+}
45+
46+}

Subscribers

People subscribed via source and target branches