labs-edaf30/lab3/UserTableTest.cc

43 lines
1.3 KiB
C++
Raw Permalink Normal View History

2024-11-27 17:14:47 +01:00
#include "UserTable.h"
#include "User.h"
#include <cassert>
int main() {
2024-12-05 12:32:27 +01:00
{ /* User Related Tests */
// Two identical users
User u1 = User(1234, "Name Nameson");
User u2 = User(1234, "Name Nameson");
2024-11-27 17:14:47 +01:00
2024-12-05 12:32:27 +01:00
assert(u1.getName() == u2.getName());
assert(u1.getCardNbr() == u2.getCardNbr());
2024-11-27 17:14:47 +01:00
2024-12-05 12:32:27 +01:00
// Two different users
User u3 = User(1200, "Name Surname");
User u4 = User(1201, "Name Nameson");
2024-11-27 17:14:47 +01:00
2024-12-05 12:32:27 +01:00
assert(u3.getName() != u4.getName());
assert(u3.getCardNbr() != u4.getCardNbr());
}
{ /* Table Related Tests */
UserTable tbl1 = UserTable();
assert(tbl1.find("Jens Holmgren") == UserTable::user_not_found);
tbl1.addUser(User(1200, "Table Yes"));
assert(tbl1.getNbrUsers() == 1);
}
{
// Assumes 'users.txt' is present, containing
// line separated records formatted as:
// "89524 Adam Abrahamsson"
UserTable tbl = UserTable("users.txt");
assert(tbl.getNbrUsers() > 0);
assert(tbl.find("Jens Holmgren") != UserTable::user_not_found);
2024-11-27 17:14:47 +01:00
2024-12-05 12:32:27 +01:00
tbl.addUser(User(1200, "Name Surname"));
User ufind1 = tbl.find(1200);
assert(ufind1 != UserTable::user_not_found);
2024-12-05 12:02:17 +01:00
2024-12-05 12:32:27 +01:00
User ufind2 = tbl.find("Name Surname");
assert(ufind2 != UserTable::user_not_found);
}
2024-11-27 17:14:47 +01:00
}