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

Function FL_TEST_FILE

tests/fl/math/transform.cpp:12–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include "fl/math/math.h"
11
12FL_TEST_FILE(FL_FILEPATH) {
13
14
15
16FL_TEST_CASE("Transform16::ToBounds(max_value)") {
17 // fl::Transform16 tx = fl::Transform16::ToBounds(255);
18
19 FL_SUBCASE("Check bounds at 128") {
20 // known bad at i == 128
21 fl::Transform16 tx = fl::Transform16::ToBounds(255);
22 fl::alpha16 i16 = fl::map8_to_16(128);
23 fl::vec2<fl::alpha16> xy_input = fl::vec2<fl::alpha16>(i16, i16);
24 fl::vec2<fl::alpha16> xy = tx.transform(xy_input);
25 FL_DINFO("i = " << 128);
26 FL_REQUIRE_EQ(128, (uint16_t)xy.x);
27 FL_REQUIRE_EQ(128, (uint16_t)xy.y);
28 }
29
30 FL_SUBCASE("Check identity from 8 -> 16") {
31 fl::Transform16 tx = fl::Transform16::ToBounds(255);
32 for (uint16_t i = 0; i < 256; i++) {
33 fl::alpha16 i16 = fl::map8_to_16(i);
34 fl::vec2<fl::alpha16> xy_input = fl::vec2<fl::alpha16>(i16, i16);
35 fl::vec2<fl::alpha16> xy = tx.transform(xy_input);
36 FL_DINFO("i = " << i);
37 FL_REQUIRE_EQ(i, (uint16_t)xy.x);
38 FL_REQUIRE_EQ(i, (uint16_t)xy.y);
39 }
40 }
41
42 FL_SUBCASE("Check all bounds are in 255") {
43 fl::Transform16 tx = fl::Transform16::ToBounds(255);
44 uint32_t smallest = ~0;
45 uint32_t largest = 0;
46 for (uint16_t i = 0; i < 256; i++) {
47 fl::alpha16 i16 = fl::map8_to_16(i);
48 fl::vec2<fl::alpha16> xy_input = fl::vec2<fl::alpha16>(i16, i16);
49 fl::vec2<fl::alpha16> xy = tx.transform(xy_input);
50 FL_DINFO("i = " << i);
51 FL_REQUIRE_LE((uint16_t)xy.x, 255);
52 FL_REQUIRE_LE((uint16_t)xy.y, 255);
53 smallest = fl::min(smallest, (uint32_t)(uint16_t)xy.x);
54 largest = fl::max(largest, (uint32_t)(uint16_t)xy.x);
55 }
56
57 FL_REQUIRE_EQ(0, smallest);
58 FL_REQUIRE_EQ(255, largest);
59 }
60}
61
62FL_TEST_CASE("Transform16::ToBounds(min, max)") {
63 FL_SUBCASE("Check bounds at 128") {
64 fl::alpha16 low = 127;
65 fl::alpha16 high = 255 + 127;
66 fl::vec2<fl::alpha16> min = fl::vec2<fl::alpha16>(low, low);
67 fl::vec2<fl::alpha16> max = fl::vec2<fl::alpha16>(high, high);
68 fl::Transform16 tx = fl::Transform16::ToBounds(min, max);
69 auto t1 = tx.transform(fl::vec2<fl::alpha16>(0, 0));

Callers

nothing calls this directly

Calls 3

map8_to_16Function · 0.85
maxFunction · 0.85
transformMethod · 0.45

Tested by

no test coverage detected