forked from jandelgado/jled
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_mbed_hal.cpp
41 lines (30 loc) · 984 Bytes
/
test_mbed_hal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// JLed Unit tests for the mbed_hal class (run on host).
// Copyright 2020 Jan Delgado [email protected]
#include "catch.hpp"
#include <mbed_hal.h> // NOLINT
#include "mbed.h" // NOLINT
using jled::MbedHal;
TEST_CASE("mbed_hal outputs 0 as 0 to the given pin using PwmOut",
"[mbed_hal]") {
mbedMockInit();
constexpr auto kPin = 5;
auto hal = MbedHal(kPin);
hal.analogWrite(0);
REQUIRE(mbedMockGetPinState(kPin) == 0.);
}
TEST_CASE("mbed_hal outputs 255 as 1.0 to the given pin using PwmOut",
"[mbed_hal]") {
mbedMockInit();
constexpr auto kPin = 5;
auto hal = MbedHal(kPin);
hal.analogWrite(255);
REQUIRE(mbedMockGetPinState(kPin) == 1.);
}
TEST_CASE("mbed_hal writes scaled value to the given pin using PwmOut",
"[mbed_hal]") {
mbedMockInit();
constexpr auto kPin = 5;
auto hal = MbedHal(kPin);
hal.analogWrite(127);
REQUIRE(mbedMockGetPinState(kPin) == Approx(127 / 255.));
}