MCPcopy Create free account
hub / github.com/FastLED/FastLED / FL_TEST_FILE

Function FL_TEST_FILE

tests/fl/math/ease.cpp:11–605  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#include <cmath> // ok include - for math functions
10
11FL_TEST_FILE(FL_FILEPATH) {
12using namespace fl;
13// Common array of easing types with names used across multiple test cases
14static const fl::pair<fl::EaseType, const char*> ALL_EASING_TYPES[10] = {
15 {fl::EaseType::EASE_NONE, "EASE_NONE"},
16 {fl::EaseType::EASE_IN_QUAD, "EASE_IN_QUAD"},
17 {fl::EaseType::EASE_OUT_QUAD, "EASE_OUT_QUAD"},
18 {fl::EaseType::EASE_IN_OUT_QUAD, "EASE_IN_OUT_QUAD"},
19 {fl::EaseType::EASE_IN_CUBIC, "EASE_IN_CUBIC"},
20 {fl::EaseType::EASE_OUT_CUBIC, "EASE_OUT_CUBIC"},
21 {fl::EaseType::EASE_IN_OUT_CUBIC, "EASE_IN_OUT_CUBIC"},
22 {fl::EaseType::EASE_IN_SINE, "EASE_IN_SINE"},
23 {fl::EaseType::EASE_OUT_SINE, "EASE_OUT_SINE"},
24 {fl::EaseType::EASE_IN_OUT_SINE, "EASE_IN_OUT_SINE"}
25};
26static const size_t NUM_EASING_TYPES = sizeof(ALL_EASING_TYPES) / sizeof(ALL_EASING_TYPES[0]);
27
28FL_TEST_CASE("8-bit easing functions") {
29 FL_SUBCASE("easeInOutQuad8") {
30 FL_SUBCASE("boundary values") {
31 FL_CHECK_CLOSE(easeInOutQuad8(0), 0, 1);
32 FL_CHECK_CLOSE(easeInOutQuad8(255), 255, 1);
33 FL_CHECK_CLOSE(easeInOutQuad8(128), 128,
34 1); // midpoint should be unchanged
35 }
36
37 FL_SUBCASE("symmetry") {
38 // ease-in-out should be symmetric around midpoint
39 for (uint8_t i = 0; i < 128; ++i) {
40 uint8_t forward = easeInOutQuad8(i);
41 uint8_t backward = easeInOutQuad8(255 - i);
42 FL_CHECK_CLOSE(forward, 255 - backward, 1);
43 }
44 }
45
46
47
48 FL_SUBCASE("first quarter should be slower than linear") {
49 // ease-in portion should start slower than linear
50 uint8_t quarter = easeInOutQuad8(64); // 64 = 255/4
51 FL_CHECK_LT(quarter, 64); // should be less than linear progression
52 }
53 }
54
55 FL_SUBCASE("easeInOutCubic8") {
56 FL_SUBCASE("boundary values") {
57 FL_CHECK_CLOSE(easeInOutCubic8(0), 0, 1);
58 FL_CHECK_CLOSE(easeInOutCubic8(255), 255, 1);
59 FL_CHECK_CLOSE(easeInOutCubic8(128), 128, 1);
60 }
61
62 FL_SUBCASE("symmetry") {
63 const int kTolerance = 2; // This is too high, come back to this.
64 for (uint8_t i = 0; i < 128; ++i) {
65 uint8_t forward = easeInOutCubic8(i);
66 uint8_t backward = easeInOutCubic8(255 - i);
67 FL_CHECK_CLOSE(forward, 255 - backward, kTolerance);
68 }

Callers

nothing calls this directly

Calls 13

easeInOutQuad8Function · 0.85
easeInOutCubic8Function · 0.85
easeInOutQuad16Function · 0.85
easeInOutCubic16Function · 0.85
map8_to_16Function · 0.85
map16_to_8Function · 0.85
easeInQuad16Function · 0.85
ease8Function · 0.85
ease16Function · 0.85
absFunction · 0.50
getMethod · 0.45
convertMethod · 0.45

Tested by

no test coverage detected