-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathtest_compareTo.cpp
57 lines (47 loc) · 1.49 KB
/
test_compareTo.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
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <String.h>
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("Testing String::compareTo(const String &)", "[String-compareTo-01]")
{
WHEN ("Strings are equal")
{
arduino::String str1("Hello"), str2("Hello");
REQUIRE(str1.compareTo(str2) == 0);
}
WHEN ("str2 is empty")
{
arduino::String str1("Hello"), str2;
REQUIRE(str1.compareTo(str2) == strcmp(str1.c_str(), str2.c_str()));
}
WHEN ("str1 is empty")
{
arduino::String str1, str2("Hello");
REQUIRE(str1.compareTo(str2) == strcmp(str1.c_str(), str2.c_str()));
}
}
TEST_CASE ("Testing String::compareTo(const char *)", "[String-compareTo-02]")
{
WHEN ("Strings are equal")
{
arduino::String str("Hello");
REQUIRE(str.compareTo("Hello") == 0);
}
WHEN ("Passed string is empty")
{
arduino::String str1("Hello"), str2("");
REQUIRE(str1.compareTo("") == strcmp(str1.c_str(), str2.c_str()));
}
WHEN ("Passed string is compared with empty string")
{
arduino::String str1, str2("Hello");
REQUIRE(str1.compareTo("Hello") == strcmp(str1.c_str(), str2.c_str()));
}
}