Add table tests

This commit is contained in:
Krzosa Karol
2023-12-31 16:41:02 +01:00
parent b3f5ce3772
commit 0a81270278
6 changed files with 87 additions and 19 deletions

View File

@@ -112,11 +112,27 @@ void TestReverseLoop() {
array.dealloc();
}
void TestCopy() {
MA_Scratch scratch;
auto a = GenArray();
auto b = a.tight_copy(scratch);
auto c = a.copy(scratch);
int i = 0;
For(b) IO_Assert(it == i++);
i = 0;
For(c) IO_Assert(it == i++);
IO_Assert(b.cap == b.len && b.len == a.len);
IO_Assert(a.len == c.len && a.cap == c.cap);
}
int main() {
TestExclusiveArenaBackedArray();
TestRemoveForLoop();
TestBasic();
TestReverseLoop();
TestCopy();
return 0;
}

43
test/test_table.cpp Normal file
View File

@@ -0,0 +1,43 @@
#include "../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);
}
int main() {
TestSimpleInsertAndIntegrity();
TestStrings();
return 0;
}