-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathtest_indexOf.cpp
100 lines (90 loc) · 2.58 KB
/
test_indexOf.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
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <String.h>
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("Testing String::indexOf(char ch)", "[String-indexOf-01]")
{
WHEN ("str is empty")
{
arduino::String str;
REQUIRE(str.indexOf('a') == -1);
}
WHEN ("str does not contained searched element")
{
arduino::String str("Hello");
REQUIRE(str.indexOf('a') == -1);
}
WHEN ("str does contain searched element")
{
arduino::String str("Hello");
REQUIRE(str.indexOf('l') == 2);
}
}
TEST_CASE ("Testing String::indexOf(char ch, unsigned int fromIndex)", "[String-indexOf-02]")
{
WHEN ("str is empty")
{
arduino::String str;
REQUIRE(str.indexOf('a', 5) == -1);
}
WHEN ("str does not contained searched element")
{
arduino::String str("Hallo");
REQUIRE(str.indexOf('a', 3) == -1);
}
WHEN ("str does contain searched element")
{
arduino::String str("Hello");
REQUIRE(str.indexOf('l', 3) == 3);
}
}
TEST_CASE ("Testing String::indexOf(const String &)", "[String-indexOf-03]")
{
arduino::String const search_str("Arduino");
WHEN ("str is empty")
{
arduino::String str;
REQUIRE(str.indexOf(search_str) == -1);
}
WHEN ("str does not contained searched element")
{
arduino::String str("Hallo");
REQUIRE(str.indexOf(search_str) == -1);
}
WHEN ("str does contain searched element")
{
arduino::String str("Hello Arduino!");
REQUIRE(str.indexOf(search_str) == 6);
}
}
TEST_CASE ("Testing String::indexOf(const String &, unsigned int fromIndex)", "[String-indexOf-04]")
{
arduino::String const search_str("Arduino");
WHEN ("str is empty")
{
arduino::String str;
REQUIRE(str.indexOf(search_str, 3) == -1);
}
WHEN ("str does not contained searched element")
{
arduino::String str("Hallo");
REQUIRE(str.indexOf(search_str, 3) == -1);
}
WHEN ("str does contain searched element and fromIndex is < start of searched element")
{
arduino::String str("Hello Arduino!");
REQUIRE(str.indexOf(search_str, 3) == 6);
}
WHEN ("str does contain searched element and fromIndex is > start of searched element")
{
arduino::String str("Hello Arduino!");
REQUIRE(str.indexOf(search_str, 8) == -1);
}
}