-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
234 lines (174 loc) · 7.28 KB
/
test.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#include "View/loginwindow.h"
#include <Model/documententity.h>
#include <Model/documentmodel.h>
#include <Model/usermodel.h>
#include <Model/usermodelentity.h>
#include <QApplication>
#include <QDebug>
#include <cassert>
/*!
* \brief Test case 1.
*/
void runtest1()
{
Document *A =
new Book(1, "The godfather", new QList<QString>({"Francis Copolla"}),
new QList<QString>(), "Publisher", 1500, 10, 1970, false);
Document *B =
new Book(2, "The godfather", new QList<QString>({"Francis Copolla"}),
new QList<QString>(), "Publisher", 1500, 10, 1970, false);
// in our system each book has a distinct id (also 2 copies of same books have
// distinct ids as well)
Patron *misha = new FacultyMember(1, "Misha", "Innopolis", "1234");
DocumentModel *librariandata = new DocumentModel();
librariandata->addDocument(A); // we should insert our books into the system
// since we don't haven't got a data base yet.
librariandata->addDocument(B);
A->checkOut(QDate::currentDate(), misha);
// Let's check the effect
// We introduced a function in our data model get by id which returns a book
// specified by id and all information
// et customer name is a function returns the name of customer booking
// document or special string instead
assert(librariandata->getById(1)->getCustomerName() == "Misha" &&
librariandata->getById(2)->isCheckedOut() == false);
qDebug() << "test 1 successful";
delete (librariandata);
}
/*!
* \brief Test case 3.
*/
void runtest3()
{
// faculty member
Patron *alexander = new FacultyMember(1, "Alexander", "innopolis", "123");
// normal non reference non bestseller book
Document *D =
new Book(1, "Intro to C++", new QList<QString>({"Bjarn Strostrup"}),
new QList<QString>(), "Publisher", 9999, 3, 2001, false);
DocumentModel *librariandata = new DocumentModel();
librariandata->addDocument(D);
int ret = D->checkOut(QDate::currentDate(), alexander);
assert(ret == Document::fourWeeks &&
librariandata->getById(1)->getCustomerName() == "Alexander");
qDebug() << "test 3 successful";
}
/*!
* \brief Test case 4.
*/
void runtest4()
{
// a note about test 4
// written in the project description that the liomit for a faculty member
// checking a book is 4 weeks regardless a best seller or not
// in test description written 2 (I assumed it's 4)
Patron *alexander = new FacultyMember(1, "Alexander", "innopolis", "123");
// normal non reference BESTSELLER book specified by last argument
Document *D =
new Book(1, "Intro to C++", new QList<QString>({"Bjarn Strostrup"}),
new QList<QString>(), "Publisher", 9999, 3, 2001, false, true);
DocumentModel *librariandata = new DocumentModel();
librariandata->addDocument(D);
int ret = D->checkOut(QDate::currentDate(), alexander);
assert(ret == Document::fourWeeks &&
librariandata->getById(1)->getCustomerName() == "Alexander");
qDebug() << "test 4 successful";
}
/*!
* \brief Test case 7.
*/
void runtest7()
{
Document *D =
new Book(1, "Intro to C++", new QList<QString>({"Bjarn Strostrup"}),
new QList<QString>(), "Publisher", 9999, 3, 2001, false);
Document *E =
new Book(2, "Intro to C++", new QList<QString>({"Bjarn Strostrup"}),
new QList<QString>(), "Publisher", 9999, 3, 2001, false);
DocumentModel *librariandata = new DocumentModel();
librariandata->addDocument(D);
librariandata->addDocument(E);
Patron *alex = new FacultyMember(1998, "Alex", "innopolis", "123456789");
D->checkOut(QDate::currentDate(), alex);
Patron *misha = new FacultyMember(1998, "Misha", "innopolis", "123456789");
E->checkOut(QDate::currentDate(), misha);
// let's check the effect
// we introduced a function in our data model get by id which returns a book
// specified by id and all information
// get customer name is a function returns the name of customer booking
// document or special string instead
assert(librariandata->getById(1)->getCustomerName() == "Alex" &&
librariandata->getById(2)->getCustomerName() == "Misha");
qDebug() << "test 7 successful";
}
void runtest8()
{
// a patron student misha
Patron *misha = new Student(1, "Misha", "innopolis", "123");
// a normal nonreference non bestseller book
Document *D = new Book(1, "Enter Sandman", new QList<QString>({"Metallica"}),
new QList<QString>({}), "anyone", 1000, 10, 1900);
DocumentModel *librariandata = new DocumentModel();
librariandata->addDocument(D);
int result = D->checkOut(QDate::currentDate(), misha);
// ensure that result is 3 weeks and that the book was checked by misha and
// that's tracked by librarian
assert(result == Document::threeWeeks &&
librariandata->getById(1)->getCustomerName() == "Misha");
qDebug() << "test 8 successful";
}
/*!
* \brief Test case 9.
*/
void runtest9()
{
// a patron student misha
Patron *misha = new Student(1, "Misha", "innopolis", "123");
// a document as a best seller (specified in last argument)
Document *D =
new Book(1, "Blackwater Park", new QList<QString>({"Opeth"}),
new QList<QString>({}), "anyone", 1000, 10, 1900, false, true);
DocumentModel *librariandata = new DocumentModel();
librariandata->addDocument(D);
int result = D->checkOut(QDate::currentDate(), misha);
// ensure that result is 2 weeks and that the book was checked by misha and
// that's tracked by librarian
assert(result == Document::twoWeeks &&
librariandata->getById(1)->getCustomerName() == "Misha");
qDebug() << "test 9 successful";
}
/*!
* \brief Test case 10.
*/
void runtest10()
{
// a student misha
Patron *misha = new Student(1, "Misha", "innopolis", "123");
// a reference book (specified by last parameter)
Document *E = new Book(1, "Ghost Of Perdition", new QList<QString>({"Opeth"}),
new QList<QString>({}), "anyone", 400, 5, 250, true);
// a non reference book
Document *D = new Book(2, "The Trooper", new QList<QString>({"Iron maiden"}),
new QList<QString>({}), "anyone", 231, 8, 100, false);
DocumentModel *librariandata = new DocumentModel();
librariandata->addDocument(D);
librariandata->addDocument(E);
int Dret = D->checkOut(QDate::currentDate(), misha);
int Eret = E->checkOut(QDate::currentDate(), misha);
// qDebug() << Dret << Eret;
assert(Eret == Document::unSuccessful && Dret == Document::threeWeeks);
assert(librariandata->getById(1)->getCustomerName() == "In Library" &&
librariandata->getById(2)->getCustomerName() == "Misha");
qDebug() << "test 10 successful";
}
/*int main(int argc, char *argv[]) {
QApplication a(argc, argv);
runtest1();
runtest3();
runtest4();
runtest7();
runtest8();
runtest9();
runtest10();
return a.exec();
}*/