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

Function FL_TEST_FILE

tests/fl/sensors/potentiometer.cpp:11–324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#include "fl/stl/move.h"
10
11FL_TEST_FILE(FL_FILEPATH) {
12
13using namespace fl;
14
15FL_TEST_CASE("Potentiometer - raw value reading") {
16 Potentiometer pot(0);
17
18 // Inject test values directly
19 pot.injectTestValue(500);
20 FL_CHECK(pot.raw() == 500);
21
22 pot.injectTestValue(750);
23 FL_CHECK(pot.raw() == 750);
24}
25
26FL_TEST_CASE("Potentiometer - normalized conversion (full range)") {
27 Potentiometer pot(0);
28 // Default calibration: 0-1023 (10-bit ADC on stub platform)
29
30 // Test minimum
31 pot.injectTestValue(0);
32 FL_CHECK(pot.normalized() == 0.0f);
33
34 // Test midpoint
35 pot.injectTestValue(512);
36 FL_CHECK(pot.normalized() == doctest::Approx(512.0f / 1023.0f).epsilon(0.001));
37
38 // Test maximum
39 pot.injectTestValue(1023);
40 FL_CHECK(pot.normalized() == 1.0f);
41}
42
43FL_TEST_CASE("Potentiometer - fractional16 conversion (full range)") {
44 Potentiometer pot(0);
45
46 // Test minimum
47 pot.injectTestValue(0);
48 FL_CHECK(pot.fractional16() == 0);
49
50 // Test midpoint
51 pot.injectTestValue(512);
52 uint16_t expected = (uint32_t(512) * 65535U) / 1023U;
53 FL_CHECK(pot.fractional16() == expected);
54
55 // Test maximum
56 pot.injectTestValue(1023);
57 FL_CHECK(pot.fractional16() == 65535);
58}
59
60FL_TEST_CASE("Potentiometer - calibration range setRange()") {
61 Potentiometer pot(0);
62
63 // Set calibration range: 100-900 maps to [0.0, 1.0]
64 pot.setRange(100, 900);
65
66 // Test below minimum (should clamp to 0.0)
67 pot.injectTestValue(50);
68 FL_CHECK(pot.normalized() == 0.0f);

Callers

nothing calls this directly

Calls 15

injectTestValueMethod · 0.80
normalizedMethod · 0.80
fractional16Method · 0.80
setRangeMethod · 0.80
calibrateMinMethod · 0.80
getRangeMinMethod · 0.80
calibrateMaxMethod · 0.80
getRangeMaxMethod · 0.80
resetCalibrationMethod · 0.80
getHysteresisMethod · 0.80
setHysteresisPercentMethod · 0.80
onChangeMethod · 0.80

Tested by

no test coverage detected