|
| 1 | +/* |
| 2 | + * Copyright (c) 2020 Arduino. All rights reserved. |
| 3 | + */ |
| 4 | + |
| 5 | +/************************************************************************************** |
| 6 | + * INCLUDE |
| 7 | + **************************************************************************************/ |
| 8 | + |
| 9 | +#include <catch.hpp> |
| 10 | + |
| 11 | +#include <Common.h> |
| 12 | + |
| 13 | +/************************************************************************************** |
| 14 | + * TEST CODE |
| 15 | + **************************************************************************************/ |
| 16 | + |
| 17 | +TEST_CASE ("Testing 'map(val, fromLow, fromHigh, toLow, toHigh)' usage with reduction of output", "[map-01]") |
| 18 | +{ |
| 19 | + REQUIRE(map(50, 0, 100, 0, 10) == 5); |
| 20 | +} |
| 21 | + |
| 22 | +TEST_CASE ("Testing 'map(val, fromLow, fromHigh, toLow, toHigh)' usage with increase of output", "[map-02]") |
| 23 | +{ |
| 24 | + REQUIRE(map(5, 0, 10, 0, 100) == 50); |
| 25 | +} |
| 26 | + |
| 27 | +TEST_CASE ("Testing 'map(val, fromLow, fromHigh, toLow, toHigh)' where output is reduced to a value < 0", "[map-03]") |
| 28 | +{ |
| 29 | + REQUIRE(map(1, 0, 100, 0, 10) == 0); /* Would be 0.1 if we'd be using floating point. */ |
| 30 | +} |
| 31 | + |
| 32 | +TEST_CASE ("Testing 'map(val, fromLow, fromHigh, toLow, toHigh)' default usage with negative values", "[map-04]") |
| 33 | +{ |
| 34 | + WHEN ("Negative 'from' values") |
| 35 | + { |
| 36 | + REQUIRE(map(0, 0, -256, 0, 1024) == 0); |
| 37 | + REQUIRE(map(-256, 0, -256, 0, 1024) == 1024); |
| 38 | + REQUIRE(map(-128, 0, -256, 0, 1024) == 512); |
| 39 | + } |
| 40 | + WHEN ("Negative 'to' values") |
| 41 | + { |
| 42 | + REQUIRE(map(0, 0, 256, 0, -1024) == 0); |
| 43 | + REQUIRE(map(256, 0, 256, 0, -1024) == -1024); |
| 44 | + REQUIRE(map(128, 0, 256, 0, -1024) == -512); |
| 45 | + } |
| 46 | +} |
0 commit comments