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

Function FL_TEST_FILE

tests/fl/fx/1d/perlin_particle_punch.cpp:9–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7#include "fl/fx/1d/perlin_particle_punch.h"
8
9FL_TEST_FILE(FL_FILEPATH) {
10
11using namespace fl;
12
13// Helper: count non-black LEDs in the buffer
14static int countLitLeds(const CRGB *leds, u16 count) {
15 int lit = 0;
16 for (u16 i = 0; i < count; ++i) {
17 if (leds[i].r > 0 || leds[i].g > 0 || leds[i].b > 0)
18 lit++;
19 }
20 return lit;
21}
22
23// Helper: check if any LEDs in a range are lit
24static bool anyLitInRange(const CRGB *leds, int start, int end, u16 count) {
25 if (start < 0) start = 0;
26 if (end > (int)count) end = (int)count;
27 for (int i = start; i < end; ++i) {
28 if (leds[i].r > 0 || leds[i].g > 0 || leds[i].b > 0)
29 return true;
30 }
31 return false;
32}
33
34FL_TEST_CASE("PerlinParticlePunch: ambient particles spawn at position 0") {
35 constexpr u16 NUM_LEDS = 50;
36 CRGB leds[NUM_LEDS];
37 PerlinParticlePunch fx(NUM_LEDS);
38
39 // Spawn ambient particles
40 for (int i = 0; i < 5; i++) {
41 fx.spawnAmbient(0.8f);
42 }
43
44 // Draw first frame — particles should be near position 0
45 Fx::DrawContext ctx(1000, leds);
46 fx.draw(ctx);
47
48 // LEDs near position 0 should be lit (particles + noise)
49 FL_CHECK(anyLitInRange(leds, 0, 10, NUM_LEDS));
50}
51
52FL_TEST_CASE("PerlinParticlePunch: ambient particles move forward over frames") {
53 constexpr u16 NUM_LEDS = 50;
54 CRGB leds[NUM_LEDS];
55 PerlinParticlePunch fx(NUM_LEDS);
56 fx.setSpeed(2.0f);
57
58 // Spawn several ambient particles
59 for (int i = 0; i < 10; i++) {
60 fx.spawnAmbient(1.0f);
61 }
62
63 // Run many frames to let particles travel
64 for (u32 t = 1000; t < 1100; t += 1) {
65 Fx::DrawContext ctx(t, leds);
66 fx.draw(ctx);

Callers

nothing calls this directly

Calls 8

anyLitInRangeFunction · 0.85
countLitLedsFunction · 0.85
spawnAmbientMethod · 0.80
spawnMeteorMethod · 0.80
setNoisePaletteMethod · 0.80
drawMethod · 0.45
setSpeedMethod · 0.45

Tested by

no test coverage detected