-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
117 lines (102 loc) · 3.03 KB
/
Copy pathtest.cpp
File metadata and controls
117 lines (102 loc) · 3.03 KB
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
//
// Created by Sammy Timmins on 9/2/20.
//
//#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <cstring>
#include "DSString.h"
using namespace std;
TEST_CASE("String class", "[string")
{
DSString s[10];
s[0] = DSString("testString");
s[1] = DSString("a test string");
s[2] = DSString("");
s[3] = DSString("THIS IS AN UPPERCASE STRING");
s[4] = DSString("this is an uppercase string");
s[5] = DSString("\n");
s[6] = DSString("");
s[7] = DSString(" split split split ");
s[8] = DSString(" ");
s[9] = DSString("testString");
SECTION("Equality operators")
{
REQUIRE((s[0] == DSString("testString")));
REQUIRE((s[0] == s[9]));
REQUIRE((s[2] == ""));
REQUIRE((s[1] == "a test string"));
REQUIRE((!(s[3] == s[4])));
}
SECTION("Assignment operators")
{
DSString str;
str = "a test string";
REQUIRE((str == s[1]));
str = DSString("testString");
REQUIRE((str == s[0]));
str = "";
REQUIRE((str == s[6]));
str = DSString("\n");
REQUIRE((str == s[5]));
}
SECTION("Addition operator")
{
REQUIRE((DSString("testStringtestString") == s[0] + s[9]));
REQUIRE((s[6] + s[6] == ""));
REQUIRE((s[5] + s[6] == DSString("\n")));
REQUIRE((s[0] + s[1] + s[2] == "testStringa test string"));
REQUIRE((s[0] + 's' == "testStrings"));
REQUIRE((s[0] + " testString" == "testString testString"));
}
SECTION("Greater than operator")
{
REQUIRE((s[0] > s[1]));
REQUIRE((s[4] > s[3]));
REQUIRE((s[9] > s[6]));
REQUIRE((s[7] > s[6]));
}
SECTION("[] operator")
{
REQUIRE((s[0][1] == 'e'));
REQUIRE((s[4][4] == ' '));
REQUIRE((s[6][0] == 0));
}
SECTION("Substring function")
{
REQUIRE((s[0].substr(0, 5) == "testS"));
REQUIRE((s[4].substr(0, 4) == "this"));
REQUIRE((s[4].substr(1, 3) == "hi"));
}
SECTION("c_str function")
{
REQUIRE((strcmp(s[0].c_str(), "testString") == 0));
REQUIRE((strcmp(s[9].c_str(), s[0].c_str()) == 0));
REQUIRE((strcmp(s[2].c_str(), "") == 0));
}
SECTION("< operator")
{
REQUIRE((s[1] < s[0]));
REQUIRE((s[3] < s[4]));
REQUIRE((s[6] < s[9]));
REQUIRE((s[6] < s[7]));
}
SECTION("getLength")
{
REQUIRE((s[2].getLength() == 0));
REQUIRE((s[0].getLength() == 10));
REQUIRE((s[5].getLength() == 1));
}
SECTION("getCapacity")
{
REQUIRE((s[2].getCapacity() == 1));
REQUIRE((s[0].getCapacity() == 11));
REQUIRE((s[5].getCapacity() == 2));
}
SECTION("getString")
{
REQUIRE((strcmp(s[0].getString(), "testString") == 0));
REQUIRE((strcmp(s[2].getString(), "") == 0));
REQUIRE((strcmp(s[3].getString(), "THIS IS AN UPPERCASE STRING") == 0));
REQUIRE((strcmp(s[4].getString(), "this is an uppercase string") == 0));
}
}