Skip to content

Commit 3541f60

Browse files
committed
Adding test code for 'min'
1 parent 7639c5c commit 3541f60

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ set(TEST_TARGET ${CMAKE_PROJECT_NAME})
2525

2626
set(TEST_SRCS
2727
src/Common/test_max.cpp
28+
src/Common/test_min.cpp
2829
src/WCharacter/test_isHexadecimalDigit.cpp
2930
src/WCharacter/test_isSpace.cpp
3031
src/WCharacter/test_isUpperCase.cpp

test/src/Common/test_min.cpp

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 ("Calling 'min(a,b)' with a < b", "[min-01]")
18+
{
19+
WHEN("a > 0 and b > 0") REQUIRE(min(1,5) == 1);
20+
WHEN("a < 0 and b > 0") REQUIRE(min(-1,5) == -1);
21+
WHEN("a < 0 and b < 0") REQUIRE(min(-5,-1) == -5);
22+
}
23+
24+
TEST_CASE ("Calling 'min(a,b)' with a > b", "[min-02]")
25+
{
26+
WHEN("a > 0 and b > 0") REQUIRE(min(5,1) == 1);
27+
WHEN("a > 0 and b < 0") REQUIRE(min(5,-1) == -1);
28+
WHEN("a < 0 and b < 0") REQUIRE(min(-1,-5) == -5);
29+
}
30+
31+
TEST_CASE ("Calling 'min(a,b)' with a == b", "[min-03]")
32+
{
33+
WHEN("a = b > 0") REQUIRE(min(5,5) == 5);
34+
WHEN("a = b < 0") REQUIRE(min(-5,-5) == -5);
35+
WHEN("a = b = 0") REQUIRE(min(0,0) == 0);
36+
}
37+
38+
TEST_CASE ("Calling 'min(a,b)' with type(a) != type(b)", "[min-04]")
39+
{
40+
WHEN("type(A) = uint8_t, type(b) = uint16_t")
41+
{
42+
uint8_t const a = 32;
43+
uint16_t const b = 10;
44+
REQUIRE(typeid(min(a,b)) == typeid(int));
45+
}
46+
WHEN("type(A) = uint16_t, type(b) = uint32_t")
47+
{
48+
uint16_t const a = 32;
49+
uint32_t const b = 10;
50+
REQUIRE(typeid(min(a,b)) == typeid(unsigned int));
51+
}
52+
WHEN("type(A) = uint32_t, type(b) = uint64_t")
53+
{
54+
uint32_t const a = 32;
55+
uint64_t const b = 10;
56+
REQUIRE(typeid(min(a,b)) == typeid(unsigned long));
57+
}
58+
WHEN("type(A) = int8_t, type(b) = int16_t")
59+
{
60+
int8_t const a = -32;
61+
int16_t const b = -10;
62+
REQUIRE(typeid(min(a,b)) == typeid(int));
63+
}
64+
WHEN("type(A) = int16_t, type(b) = int32_t")
65+
{
66+
int16_t const a = -32;
67+
int32_t const b = -10;
68+
REQUIRE(typeid(min(a,b)) == typeid(int));
69+
}
70+
WHEN("type(A) = int32_t, type(b) = int64_t")
71+
{
72+
int32_t const a = -32;
73+
int64_t const b = -10;
74+
REQUIRE(typeid(min(a,b)) == typeid(long));
75+
}
76+
}

0 commit comments

Comments
 (0)