Use UnitTest-Cpp library for testing

This commit is contained in:
Ilusha 2024-03-15 16:03:33 +03:00 committed by Ilya Shurupov
parent 79d018ffb4
commit b8bcf58a29
53 changed files with 1046 additions and 1383 deletions

View file

@ -1,129 +1,124 @@
#include "Archiver.hpp"
#include "Map.hpp"
#include "Testing.hpp"
#include "Tests.hpp"
using namespace tp;
TEST_DEF_STATIC(SimpleReference) {
tp::Map<tp::ualni, TestClass, tp::HeapAlloc> map;
SUITE(HashTable) {
TEST(SimpleReference) {
tp::Map<tp::ualni, TestClass, tp::HeapAlloc> map;
for (auto i : Range(1000, 100000)) {
map.put(i, TestClass(i));
for (auto i : Range(1000, 100000)) {
map.put(i, TestClass(i));
}
for (auto i : Range(1000, 100000)) {
CHECK(map.presents(i));
CHECK_EQUAL((tp::ualni) map.get(i).getVal(), (tp::ualni) i);
}
for (auto i : Range(1000, 100000)) {
map.put(i, TestClass(i));
}
for (auto i : Range(1000, 2000)) {
CHECK(map.presents(i));
map.remove(i);
CHECK(!map.presents(i));
}
for (auto i : Range(2000, 100000)) {
CHECK(map.presents(i));
CHECK_EQUAL((tp::ualni) map.get(i).getVal(), (tp::ualni) i);
}
for (auto i : map) {
i->val.setVal(3);
}
map.removeAll();
}
for (auto i : Range(1000, 100000)) {
TEST(map.presents(i));
TEST_EQUAL(map.get(i).getVal(), i);
TEST(SimplePointer) {
tp::Map<tp::ualni, TestClass*, tp::HeapAlloc> map;
for (auto i : Range(1000)) {
map.put(i, new TestClass(i));
}
for (auto i : Range(1000)) {
CHECK(map.presents(i));
CHECK_EQUAL((tp::ualni) map.get(i)->getVal(), (tp::ualni) i);
}
for (auto i : Range(1000)) {
auto del = map.get(i);
map.put(i, new TestClass(i));
delete del;
}
for (auto i : Range(900, 1000)) {
CHECK(map.presents(i));
delete map.get(i);
map.remove(i);
CHECK(!map.presents(i));
}
for (auto i : Range(900)) {
CHECK(map.presents(i));
CHECK_EQUAL((tp::ualni) map.get(i)->getVal(), (tp::ualni) i);
}
for (auto i : map) {
i->val->setVal(3);
delete i->val;
}
map.removeAll();
}
for (auto i : Range(1000, 100000)) {
map.put(i, TestClass(i));
TEST(Copy) {
tp::Map<tp::ualni, TestClass, tp::HeapAlloc> map;
for (auto i : Range(10)) {
map.put(i, TestClass(i));
}
tp::Map<tp::ualni, TestClass, tp::HeapAlloc> map2 = map;
CHECK(map == map2);
map.removeAll();
map2.removeAll();
}
for (auto i : Range(1000, 2000)) {
TEST(map.presents(i));
map.remove(i);
TEST(!map.presents(i));
TEST(SaveLoad) {
tp::Map<tp::ualni, TestClass, tp::HeapAlloc> map;
for (auto i : Range(10)) {
map.put(i, TestClass(i));
}
ArchiverExample<1024, false> write;
ArchiverExample<1024, true> read;
write % map;
map.removeAll();
CHECK(map.size() == 0);
memCopy(read.mBuff, write.mBuff, sizeof(write.mBuff));
read % map;
CHECK(map.size() == 10);
for (auto i : Range(10)) {
CHECK(map.presents(i));
CHECK_EQUAL(map.get(i).getVal(), i);
}
map.removeAll();
}
for (auto i : Range(2000, 100000)) {
TEST(map.presents(i));
TEST_EQUAL(map.get(i).getVal(), i);
}
for (auto i : map) {
i->val.setVal(3);
}
map.removeAll();
}
TEST_DEF_STATIC(SimplePointer) {
tp::Map<tp::ualni, TestClass*, tp::HeapAlloc> map;
for (auto i : Range(1000)) {
map.put(i, new TestClass(i));
}
for (auto i : Range(1000)) {
TEST(map.presents(i));
TEST_EQUAL(map.get(i)->getVal(), i);
}
for (auto i : Range(1000)) {
auto del = map.get(i);
map.put(i, new TestClass(i));
delete del;
}
for (auto i : Range(900, 1000)) {
TEST(map.presents(i));
delete map.get(i);
map.remove(i);
TEST(!map.presents(i));
}
for (auto i : Range(900)) {
TEST(map.presents(i));
TEST_EQUAL(map.get(i)->getVal(), i);
}
for (auto i : map) {
i->val->setVal(3);
delete i->val;
}
map.removeAll();
}
TEST_DEF_STATIC(Copy) {
tp::Map<tp::ualni, TestClass, tp::HeapAlloc> map;
for (auto i : Range(10)) {
map.put(i, TestClass(i));
}
tp::Map<tp::ualni, TestClass, tp::HeapAlloc> map2 = map;
TEST_EQUAL(map, map2);
map.removeAll();
map2.removeAll();
}
TEST_DEF_STATIC(SaveLoad) {
tp::Map<tp::ualni, TestClass, tp::HeapAlloc> map;
for (auto i : Range(10)) {
map.put(i, TestClass(i));
}
ArchiverExample<1024, false> write;
ArchiverExample<1024, true> read;
write % map;
map.removeAll();
TEST(map.size() == 0);
memCopy(read.mBuff, write.mBuff, sizeof(write.mBuff));
read % map;
TEST(map.size() == 10);
for (auto i : Range(10)) {
TEST(map.presents(i));
TEST_EQUAL(map.get(i).getVal(), i);
}
map.removeAll();
}
TEST_DEF(Map) {
testSimplePointer();
testSimpleReference();
testSaveLoad();
}
}