-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathtest_comparisonFunc.cpp
157 lines (134 loc) · 4.51 KB
/
test_comparisonFunc.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <String.h>
#include "StringPrinter.h"
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("Testing String::equals(const String &) with exit status PASS", "[String-equals-01]")
{
arduino::String str1("Hello"), str2("Hello");
REQUIRE(str1.equals(str2) == 1);
}
TEST_CASE ("Testing String::operator==(const String &) with exit status PASS", "[String-equals-01]")
{
arduino::String str1("Hello"), str2("Hello");
REQUIRE(str1 == str2);
}
TEST_CASE ("Testing String::operator!=(const String &) with exit status FAIL", "[String-equals-01]")
{
arduino::String str1("Hello"), str2("Hello");
REQUIRE_FALSE(str1 != str2);
}
TEST_CASE ("Testing String::equals(const String &) with exit status FAIL", "[String-equals-02]")
{
arduino::String str1("Hello"), str2("World");
REQUIRE(str1.equals(str2) == 0);
}
TEST_CASE ("Testing String::operator==(const String &) with exit status FAIL", "[String-equals-02]")
{
arduino::String str1("Hello"), str2("World");
REQUIRE_FALSE(str1 == str2);
}
TEST_CASE ("Testing String::operator !=(const String &) with exit status PASS", "[String-equals-02]")
{
arduino::String str1("Hello"), str2("World");
REQUIRE(str1 != str2);
}
TEST_CASE ("Testing String::equals(const char *) with exit status PASS", "[String-equals-03]")
{
arduino::String str1("Hello");
REQUIRE(str1.equals("Hello") == 1);
}
TEST_CASE ("Testing String::operator ==(const char *) with exit status PASS", "[String-equals-03]")
{
arduino::String str1("Hello");
REQUIRE(str1 == "Hello");
}
TEST_CASE ("Testing String::operator !=(const char *) with exit status FAIL", "[String-equals-03]")
{
arduino::String str1("Hello");
REQUIRE_FALSE(str1 != "Hello");
}
TEST_CASE ("Testing String::equals(const char *) with exit status FAIL", "[String-equals-04]")
{
arduino::String str1("Hello");
REQUIRE(str1.equals("World") == 0);
}
TEST_CASE ("Testing String::operator ==(const char *) with exit status FAIL", "[String-equals-04]")
{
arduino::String str1("Hello");
REQUIRE_FALSE(str1 == "World");
}
TEST_CASE ("Testing String::operator !=(const char *) with exit status PASS", "[String-equals-04]")
{
arduino::String str1("Hello");
REQUIRE(str1 != "World");
}
TEST_CASE ("Testing String::equalsIgnoreCase(const String &) PASS with NON-empty string", "[String-equalsIgnoreCase-05]")
{
arduino::String str1("Hello"), str2("Hello");
REQUIRE(str1.equalsIgnoreCase(str2) == 1);
}
TEST_CASE ("Testing String::equalsIgnoreCase(const String &) FAIL with NON-empty string", "[String-equalsIgnoreCase-06]")
{
arduino::String str1("Hello"), str2("Hel");
REQUIRE(str1.equalsIgnoreCase(str2) == 0);
}
TEST_CASE ("Testing String::equalsIgnoreCase(const String &) FAIL with different strings", "[String-equalsIgnoreCase-07]")
{
arduino::String str1("Hello"), str2("World");
REQUIRE(str1.equalsIgnoreCase(str2) == 0);
}
TEST_CASE ("Testing String::equalsIgnoreCase(const String &) PASS with same string", "[String-equalsIgnoreCase-08]")
{
arduino::String str1("Hello");
REQUIRE(str1.equalsIgnoreCase(str1) == 1);
}
TEST_CASE ("Testing String::startsWith(const String &)", "[String-startsWith-09]")
{
WHEN ("str2 is larger than str1")
{
arduino::String str1("Hello");
arduino::String str2("Hello World");
REQUIRE(str1.startsWith(str2) == 0);
}
WHEN ("str1 starts with str2")
{
arduino::String str1("Hello World");
arduino::String str2("Hello");
REQUIRE(str1.startsWith(str2) == 1);
}
WHEN ("str1 does NOT start with str2")
{
arduino::String str1("Hello World");
arduino::String str2("Helo");
REQUIRE(str1.startsWith(str2) == 0);
}
}
TEST_CASE ("Testing String::endsWith(const String &)", "[String-endsWith-10]")
{
WHEN ("str2 is larger than str1")
{
arduino::String str1("Hello");
arduino::String str2("Hello World");
REQUIRE(str1.endsWith(str2) == 0);
}
WHEN ("str1 ends with str2")
{
arduino::String str1("Hello World");
arduino::String str2("World");
REQUIRE(str1.endsWith(str2) == 1);
}
WHEN ("str1 does NOT end with str2")
{
arduino::String str1("Hello World");
arduino::String str2("Helo");
REQUIRE(str1.endsWith(str2) == 0);
}
}