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

Function FL_TEST_FILE

tests/fl/gfx/corkscrew.cpp:25–673  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23#include "hsv2rgb.h"
24
25FL_TEST_FILE(FL_FILEPATH) {
26
27#undef NUM_LEDS // Avoid redefinition in unity builds
28#define NUM_LEDS 288
29
30
31FL_TEST_CASE("Corkscrew Circle10 test") {
32 // Test basic dimensional calculations using Corkscrew objects directly
33
34 // Test simple case: 1 turn, 10 LEDs
35 fl::Corkscrew corkscrew_simple(1.0f, 10);
36 FL_REQUIRE_EQ(corkscrew_simple.cylinderWidth(), 10); // ceil(10 LEDs / 1 turn) = 10
37 FL_REQUIRE_EQ(corkscrew_simple.cylinderHeight(), 1); // ceil(1 turn) = 1
38
39 // Test 2 turns with 20 LEDs (10 LEDs per turn)
40 fl::Corkscrew corkscrew_example(2.0f, 20);
41 FL_REQUIRE_EQ(corkscrew_example.cylinderWidth(), 10); // LEDs per turn
42 FL_REQUIRE_EQ(corkscrew_example.cylinderHeight(), 2); // Number of turns
43
44 // Test default case: 19 turns, 144 LEDs
45 fl::Corkscrew corkscrew_default(19.0f, 144);
46 FL_REQUIRE_EQ(corkscrew_default.cylinderWidth(), 8); // ceil(144/19) = ceil(7.58) = 8
47 FL_REQUIRE_EQ(corkscrew_default.cylinderHeight(), 18); // Optimized: ceil(144/8) = ceil(18) = 18
48
49 // Test FestivalStick case: 19 turns, 288 LEDs
50 fl::Corkscrew corkscrew_festival(19.0f, 288);
51 FL_REQUIRE_EQ(corkscrew_festival.cylinderWidth(), 16); // ceil(288/19) = ceil(15.16) = 16
52 FL_REQUIRE_EQ(corkscrew_festival.cylinderHeight(), 18); // ceil(288/16) = ceil(18) = 18 (optimized!)
53
54 // Verify grid size matches LED count
55 FL_REQUIRE_EQ(corkscrew_festival.cylinderWidth() * corkscrew_festival.cylinderHeight(), 288);
56
57 // Check LED distribution - find max height position actually used
58 float max_height = 0.0f;
59 float min_height = 999.0f;
60 for (uint16_t i = 0; i < corkscrew_festival.size(); ++i) {
61 fl::vec2f pos = corkscrew_festival.at_no_wrap(i);
62 max_height = fl::max(max_height, pos.y);
63 min_height = fl::min(min_height, pos.y);
64 }
65
66 // LEDs should span from 0 to height-1
67 FL_REQUIRE(min_height >= 0.0f);
68 FL_REQUIRE(max_height <= 18.0f); // height-1 = 18-1 = 17
69}
70
71FL_TEST_CASE("Corkscrew LED distribution test") {
72 // Test if LEDs actually reach the top row
73 fl::Corkscrew corkscrew(19.0f, 288); // FestivalStick case
74
75 // Count how many LEDs map to each row
76 fl::vector<int> row_counts(corkscrew.cylinderHeight(), 0);
77 for (uint16_t i = 0; i < corkscrew.size(); ++i) {
78 fl::vec2f pos = corkscrew.at_no_wrap(i);
79 int row = static_cast<int>(pos.y);
80 if (row >= 0 && row < corkscrew.cylinderHeight()) {
81 row_counts[row]++;
82 }

Callers

nothing calls this directly

Calls 15

maxFunction · 0.85
calculateCorkscrewWidthFunction · 0.85
calculateCorkscrewHeightFunction · 0.85
GapClass · 0.85
almost_equalFunction · 0.85
cylinderWidthMethod · 0.80
cylinderHeightMethod · 0.80
at_no_wrapMethod · 0.80
fillInputSurfaceMethod · 0.80
getDiameterMethod · 0.80
at_exactMethod · 0.80
getBoundsMethod · 0.80

Tested by

no test coverage detected