| 9 | #include "fl/stl/move.h" |
| 10 | |
| 11 | FL_TEST_FILE(FL_FILEPATH) { |
| 12 | |
| 13 | using namespace fl; |
| 14 | |
| 15 | FL_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 | |
| 26 | FL_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 | |
| 43 | FL_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 | |
| 60 | FL_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); |
nothing calls this directly
no test coverage detected