aboutsummaryrefslogtreecommitdiff
path: root/tests/functional/sokol_color_test.c
blob: c3c134517a0dd17c13a0f8b0018f713ba3685909 (plain)
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
67
68
69
70
//------------------------------------------------------------------------------
//  sokol_color_test.c
//------------------------------------------------------------------------------
#include "sokol_gfx.h"
#define SOKOL_COLOR_IMPL
#include "sokol_color.h"
#include "utest.h"
#include <math.h>

#define T(b) EXPECT_TRUE(b)
#define TFLT(f0,f1,epsilon) {T(fabs((f0)-(f1))<=(epsilon));}

UTEST(sokol_color, make_color) {
    const sg_color c0 = sg_make_color_4b(255, 127, 0, 255);
    TFLT(c0.r, 1.0f, 0.01f);
    TFLT(c0.g, 0.5f, 0.01f);
    TFLT(c0.b, 0.0f, 0.01f);
    TFLT(c0.a, 1.0f, 0.01f);
    const sg_color c1 = sg_make_color_1i(SG_BLACK_RGBA32);
    TFLT(c1.r, 0.0f, 0.01f);
    TFLT(c1.g, 0.0f, 0.01f);
    TFLT(c1.b, 0.0f, 0.01f);
    TFLT(c1.a, 1.0f, 0.01f);
    const sg_color c2 = sg_make_color_1i(SG_GREEN_RGBA32);
    TFLT(c2.r, 0.0f, 0.01f);
    TFLT(c2.g, 1.0f, 0.01f);
    TFLT(c2.b, 0.0f, 0.01f);
    TFLT(c2.a, 1.0f, 0.01f);
    const sg_color c3 = sg_make_color_1i(SG_RED_RGBA32);
    TFLT(c3.r, 1.0f, 0.01f);
    TFLT(c3.g, 0.0f, 0.01f);
    TFLT(c3.b, 0.0f, 0.01f);
    TFLT(c3.a, 1.0f, 0.01f);
    const sg_color c4 = sg_make_color_1i(SG_BLUE_RGBA32);
    TFLT(c4.r, 0.0f, 0.01f);
    TFLT(c4.g, 0.0f, 0.01f);
    TFLT(c4.b, 1.0f, 0.01f);
    TFLT(c4.a, 1.0f, 0.01f);
}

UTEST(sokol_color, lerp) {
    const sg_color c0 = sg_color_lerp(&sg_red, &sg_green, 0.5f);
    TFLT(c0.r, 0.5f, 0.001f);
    TFLT(c0.g, 0.5f, 0.001f);
    TFLT(c0.b, 0.0f, 0.001f);
    TFLT(c0.a, 1.0f, 0.001f);
    const sg_color c1 = sg_color_lerp_precise(&sg_red, &sg_green, 0.5f);
    TFLT(c1.r, 0.5f, 0.001f);
    TFLT(c1.g, 0.5f, 0.001f);
    TFLT(c1.b, 0.0f, 0.001f);
    TFLT(c1.a, 1.0f, 0.001f);
}

UTEST(sokol_color, multiply) {
    const sg_color c0 = sg_color_multiply(&sg_red, 0.5f);
    TFLT(c0.r, 0.5f, 0.001f);
    TFLT(c0.g, 0.0f, 0.001f);
    TFLT(c0.b, 0.0f, 0.001f);
    TFLT(c0.a, 0.5f, 0.001f);
    const sg_color c1 = sg_color_multiply(&sg_green, 0.5f);
    TFLT(c1.r, 0.0f, 0.001f);
    TFLT(c1.g, 0.5f, 0.001f);
    TFLT(c1.b, 0.0f, 0.001f);
    TFLT(c1.a, 0.5f, 0.001f);
    const sg_color c2 = sg_color_multiply(&sg_blue, 0.5f);
    TFLT(c2.r, 0.0f, 0.001f);
    TFLT(c2.g, 0.0f, 0.001f);
    TFLT(c2.b, 0.5f, 0.001f);
    TFLT(c2.a, 0.5f, 0.001f);
}