-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathtest_mbed_hal.cpp
42 lines (31 loc) · 1.03 KB
/
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
42
// JLed Unit tests for the mbed_hal class (run on host).
// Copyright 2020 Jan Delgado jdelgado@gmx.net
#include "catch2/catch_amalgamated.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_THAT(mbedMockGetPinState(kPin),
Catch::Matchers::WithinAbs(127 / 255., 0.0001));
}