Debian Codegraph @

xmpp-vala/tests/color.vala

raw
1 using Xmpp.Xep;
2
3 namespace Xmpp.Test {
4
5 class ColorTest : Gee.TestCase {
6
7 public ColorTest() {
8 base("color");
9
10 add_test("xep-vectors-angle", () => { text_xep_vectors_angle(); });
11 add_test("xep-vectors-rgbf", () => { test_xep_vectors_rgbf(); });
12 add_test("rgb-to-angle", () => { test_rgb_to_angle(); });
13 }
14
15 public void text_xep_vectors_angle() {
16 fail_if_not_eq_double(ConsistentColor.string_to_angle("Romeo"), 327.255249);
17 fail_if_not_eq_double(ConsistentColor.string_to_angle("[email protected]"), 209.410400);
18 fail_if_not_eq_double(ConsistentColor.string_to_angle("😺"), 331.199341);
19 fail_if_not_eq_double(ConsistentColor.string_to_angle("council"), 359.994507);
20 fail_if_not_eq_double(ConsistentColor.string_to_angle("Board"), 171.430664);
21 }
22
23 private bool fail_if_not_eq_rgbf(float[] left, float[] right) {
24 bool failed = false;
25 for (int i = 0; i < 3; i++) {
26 failed = fail_if_not_eq_float(left[i], right[i]) || failed;
27 }
28 return failed;
29 }
30
31 public void test_xep_vectors_rgbf() {
32 fail_if_not_eq_rgbf(ConsistentColor.string_to_rgbf("Romeo"), {0.865f,0.000f,0.686f});
33 fail_if_not_eq_rgbf(ConsistentColor.string_to_rgbf("[email protected]"), {0.000f,0.515f,0.573f});
34 fail_if_not_eq_rgbf(ConsistentColor.string_to_rgbf("😺"), {0.872f,0.000f,0.659f});
35 fail_if_not_eq_rgbf(ConsistentColor.string_to_rgbf("council"), {0.918f,0.000f,0.394f});
36 fail_if_not_eq_rgbf(ConsistentColor.string_to_rgbf("Board"), {0.000f,0.527f,0.457f});
37 }
38
39 public void test_rgb_to_angle() {
40 string[] colors = {"e57373", "f06292", "ba68c8", "9575cd", "7986cb", "64b5f6", "4fc3f7", "4dd0e1", "4db6ac", "81c784", "aed581", "dce775", "fff176", "ffd54f", "ffb74d", "ff8a65"};
41 foreach(string hex_color in colors) {
42 uint8 r = (uint8) ((double) hex_color.substring(0, 2).to_long(null, 16));
43 uint8 g = (uint8) ((double) hex_color.substring(2, 2).to_long(null, 16));
44 uint8 b = (uint8) ((double) hex_color.substring(4, 2).to_long(null, 16));
45 //print(@"$hex_color, $r, $g, $b, $(ConsistentColor.rgb_to_angle(r, g, b))\n");
46 }
47 }
48 }
49
50 }