Restructuring

This commit is contained in:
Krzosa Karol
2024-01-12 11:28:19 +01:00
parent dde2334f95
commit eb60189b4b
39 changed files with 55 additions and 55 deletions

44
tests/test_table.cpp Normal file
View File

@@ -0,0 +1,44 @@
#include "../core_library/core.c"
void TestSimpleInsertAndIntegrity() {
MA_Scratch scratch;
Table<uint64_t> table = {scratch};
table.reserve(64);
for (uint64_t i = 0; i < 10000; i += 1) {
table.insert(i, i);
}
for (uint64_t i = 0; i < 10000; i += 1) {
uint64_t *v = table.get(i);
IO_Assert(*v == i);
}
IO_Assert(table.len == 10000);
IO_Assert(table.cap > table.len);
IO_Assert(MA_IS_POW2(table.cap));
table.remove(32);
table.reset();
table.dealloc();
}
void TestStrings() {
struct Data {
int a[32];
int i;
};
Table<Data> table = {};
table.puts("1", Data{{}, 1});
table.puts("2", Data{{}, 2});
table.puts("3", Data{{}, 3});
IO_Assert(table.gets("1")->i == 1);
IO_Assert(table.gets("2")->i == 2);
IO_Assert(table.gets("3")->i == 3);
table.dealloc();
}
int main() {
TestSimpleInsertAndIntegrity();
TestStrings();
return 0;
}