Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5bd28b7

Browse files
committed
Adding test code for Common::map
1 parent23ef4ce commit5bd28b7

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

‎test/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ set(TEST_TARGET ${CMAKE_PROJECT_NAME})
2626

2727
set(TEST_SRCS
2828
src/Common/test_makeWord.cpp
29+
src/Common/test_map.cpp
2930
src/Common/test_max.cpp
3031
src/Common/test_min.cpp
3132
src/IPAddress/test_fromString.cpp

‎test/src/Common/test_map.cpp‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp