forked from arduino/ArduinoCore-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_max.cpp
76 lines (68 loc) · 2.11 KB
/
test_max.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <api/Common.h>
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("Calling 'max(a,b)' with a < b", "[max-01]")
{
WHEN("a > 0 and b > 0") REQUIRE(max(1,5) == 5);
WHEN("a < 0 and b > 0") REQUIRE(max(-1,5) == 5);
WHEN("a < 0 and b < 0") REQUIRE(max(-5,-1) == -1);
}
TEST_CASE ("Calling 'max(a,b)' with a > b", "[max-02]")
{
WHEN("a > 0 and b > 0") REQUIRE(max(5,1) == 5);
WHEN("a > 0 and b < 0") REQUIRE(max(5,-1) == 5);
WHEN("a < 0 and b < 0") REQUIRE(max(-1,-5) == -1);
}
TEST_CASE ("Calling 'max(a,b)' with a == b", "[max-03]")
{
WHEN("a = b > 0") REQUIRE(max(5,5) == 5);
WHEN("a = b < 0") REQUIRE(max(-5,-5) == -5);
WHEN("a = b = 0") REQUIRE(max(0,0) == 0);
}
TEST_CASE ("Calling 'max(a,b)' with type(a) != type(b)", "[max-04]")
{
WHEN("type(A) = uint8_t, type(b) = uint16_t")
{
uint8_t const a = 32;
uint16_t const b = 10;
REQUIRE(typeid(max(a,b)) == typeid(int));
}
WHEN("type(A) = uint16_t, type(b) = uint32_t")
{
uint16_t const a = 32;
uint32_t const b = 10;
REQUIRE(typeid(max(a,b)) == typeid(unsigned int));
}
WHEN("type(A) = uint32_t, type(b) = uint64_t")
{
uint32_t const a = 32;
uint64_t const b = 10;
REQUIRE(typeid(max(a,b)) == typeid(uint64_t));
}
WHEN("type(A) = int8_t, type(b) = int16_t")
{
int8_t const a = -32;
int16_t const b = -10;
REQUIRE(typeid(max(a,b)) == typeid(int));
}
WHEN("type(A) = int16_t, type(b) = int32_t")
{
int16_t const a = -32;
int32_t const b = -10;
REQUIRE(typeid(max(a,b)) == typeid(int));
}
WHEN("type(A) = int32_t, type(b) = int64_t")
{
int32_t const a = -32;
int64_t const b = -10;
REQUIRE(typeid(max(a,b)) == typeid(int64_t));
}
}