forked from arduino/ArduinoCore-API
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_min.cpp
76 lines (68 loc) · 2.1 KB
/
test_min.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 <Common.h>
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("Calling 'min(a,b)' with a < b", "[min-01]")
{
WHEN("a > 0 and b > 0") REQUIRE(min(1,5) == 1);
WHEN("a < 0 and b > 0") REQUIRE(min(-1,5) == -1);
WHEN("a < 0 and b < 0") REQUIRE(min(-5,-1) == -5);
}
TEST_CASE ("Calling 'min(a,b)' with a > b", "[min-02]")
{
WHEN("a > 0 and b > 0") REQUIRE(min(5,1) == 1);
WHEN("a > 0 and b < 0") REQUIRE(min(5,-1) == -1);
WHEN("a < 0 and b < 0") REQUIRE(min(-1,-5) == -5);
}
TEST_CASE ("Calling 'min(a,b)' with a == b", "[min-03]")
{
WHEN("a = b > 0") REQUIRE(min(5,5) == 5);
WHEN("a = b < 0") REQUIRE(min(-5,-5) == -5);
WHEN("a = b = 0") REQUIRE(min(0,0) == 0);
}
TEST_CASE ("Calling 'min(a,b)' with type(a) != type(b)", "[min-04]")
{
WHEN("type(A) = uint8_t, type(b) = uint16_t")
{
uint8_t const a = 32;
uint16_t const b = 10;
REQUIRE(typeid(min(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(min(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(min(a,b)) == typeid(unsigned long));
}
WHEN("type(A) = int8_t, type(b) = int16_t")
{
int8_t const a = -32;
int16_t const b = -10;
REQUIRE(typeid(min(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(min(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(min(a,b)) == typeid(long));
}
}