generated from sfuad001/Project-CS180
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunittest.cpp
169 lines (138 loc) · 4.67 KB
/
unittest.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
158
159
160
161
162
163
164
165
166
167
168
169
#include "gtest/gtest.h"
#include "src/csvtojson.h"
#include "rapidjson/include/rapidjson/document.h"
#include "src/csvtojson.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include "src/json.h"
#include "src/LinkedList.h"
/*
//TEST(s) goes above main
TEST(csvtojson, withoutextension){
csvtojson c;
stringstream ss;
c.printcsv("test1", 3, ss);
// EXPECT_EQ(ss, "JohnBluetrueBobRedfalseJhonnyGreentrue");
}
TEST(csvtojson, withextension){
csvtojson c;
stringstream ss;
c.printcsv("test1.csv", 3,ss);
//EXPECT_EQ(ss, "JohnBluetrueBobRedfalseJhonnyGreentrue");
}
*/
/*TEST(JsonTest, ParseErrorTest) {
// Create a file with a JSON syntax error
std::ofstream file("data.json");
file << "{ \"name\": \"John\", \"age\": 30, }"; // Syntax error: trailing comma
file.close();
// Call the function being tested
Json json;
json.parseError();
// Check that the function output contains the expected error message
testing::internal::CaptureStdout();
json.parseError();
std::string output = testing::internal::GetCapturedStdout();
bool hasError = output.find("Error(offset ") != std::string::npos;
bool hasMissingNameError = output.find("Missing a name") != std::string::npos;
EXPECT_TRUE(hasError && hasMissingNameError);
// Remove the test file
std::remove("data.json");
}*/
/*TEST(JsonTest, WriteJsonTest) {
Json json;
json.writeJson();
// Read the contents of the output file
std::ifstream inputFile("output.json");
std::stringstream buffer;
buffer << inputFile.rdbuf();
std::string fileContents = buffer.str();
// Remove tabs from the file contents
fileContents.erase(std::remove(fileContents.begin(), fileContents.end(), '\t'), fileContents.end());
// Check that the output file has the right JSON data
std::string expectedOutput = "{\n\"people\": [{\n\"id\": \"9873e87e879ueid\",\n\"name\": \"Farnaz\",\n\"age\": 23,\n\"college\": \"UC Riverside\"\n}, {\n\"id\": \"98e89r8983009id\",\n\"name\": \"Golnaz\",\n\"age\": 27,\n\"college\": \"UC Berkely\"\n}, {\n\"id\": \"9898378747382id\",\n\"name\": \"Niloofar\",\n\"age\": 30,\n\"college\": \"UCLA\"\n}, {\n\"id\": \"959067fs9d798id\",\n\"name\": \"Muneeb\",\n\"age\": 23,\n\"college\": \"UC Riverside\"\n}]\n}";
EXPECT_EQ(fileContents, expectedOutput);
}*/
/*TEST(JsonTest, InitializeEMPTYjsonTest) {
Json json;
std::string collectionName = "myCollection";
std::string jsonName = "myJson";
json.intiializeEMPTYjson(collectionName, jsonName);
// Check that the file is created
std::string directory = "Database/" + collectionName + jsonName;
std::ifstream inputFile(directory);
bool fileExists = inputFile.good();
inputFile.close();
EXPECT_TRUE(fileExists);
}*/
TEST(LinkedList, CheckEmptyList) {
LinkedList* list = new LinkedList();
EXPECT_EQ(list->size(), 0);
}
TEST(LinkedList, CorrectListSize) {
LinkedList* list = new LinkedList();
pair t = make_pair("Age", "20");
pair t2 = make_pair("Age", "77");
pair t3 = make_pair("Age", "13");
vector<pair<string,string>> vec1;
vector<pair<string,string>> vec2;
vector<pair<string,string>> vec3;
vec1.push_back(t);
vec2.push_back(t2);
vec3.push_back(t3);
list->insertToRear(vec1);
list->insertToRear(vec2);
list->insertToRear(vec3);
EXPECT_EQ(list->size(), 3);
}
TEST(LinkedList, getCorrectVector) {
LinkedList* list = new LinkedList();
pair t = make_pair("Age", "20");
pair t2 = make_pair("Age", "77");
pair t3 = make_pair("Age", "13");
vector<pair<string,string>> vec1;
vector<pair<string,string>> vec2;
vector<pair<string,string>> vec3;
vec1.push_back(t);
vec2.push_back(t2);
vec3.push_back(t3);
list->insertToRear(vec1);
list->insertToRear(vec2);
list->insertToRear(vec3);
vector<pair<string,string>> result = list->get(1);
EXPECT_EQ(result[0].second, "77");
}
TEST(LinkedList, correctDelete) {
LinkedList* list = new LinkedList();
pair t = make_pair("Age", "20");
pair t2 = make_pair("Age", "77");
pair t3 = make_pair("Age", "13");
vector<pair<string,string>> vec1;
vector<pair<string,string>> vec2;
vector<pair<string,string>> vec3;
vec1.push_back(t);
vec2.push_back(t2);
vec3.push_back(t3);
list->insertToRear(vec1);
list->insertToRear(vec2);
list->insertToRear(vec3);
list->deleteNode(1);
EXPECT_EQ(list->size(), 2);
}
// TEST(JSON, Filter)
// {
// Json* n = new Json("Collection_1", "Data.json");
// n->filterFunc("Age", {"30"});
// EXPECT_EQ(n->getResult()->size(), 1);
// }
// TEST(JSON, Sort)
// {
// Json* n = new Json("Collection_1", "Data.json");
// //n->sortFunc("Age", 1);
// //EXPECT_EQ(n->getResult()->get(0)[2].second, "23");
// }
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}