// TODO: Make the tests actually decent

void RunTests()
{
	TestFreeListAlloc();
	TestHashTable();
}

void TestFreeListAlloc()
{
	Printfln("Starting free list allocator tests...");

	FLAlloc alloc = {0};
	usize alloc_size = KB(256);
	FreeListInit(&alloc, alloc_size);
	u8 *value = (u8 *)(uintptr(alloc.lists[0]->data) + uintptr(alloc_size-sizeof(FreeList)-2));
	*value = 255;
	Assert(*value == 255, "data set is invalid");

	u32 u32_count = 2000;
	u32 f64_count = 3000;

	u32 *u32_arr = FreeListAlloc(&alloc, sizeof(u32) * u32_count);
	f64 *f64_arr = FreeListAlloc(&alloc, sizeof(f64) * f64_count);

	for (u32 i = 0; i < u32_count; i++)
	{
		u32_arr[i] = 3 * i;
	}

	for (u32 i = 0; i < f64_count; i++)
	{
		f64_arr[i] = f64(i);
	}

	for (u32 i = 0; i < u32_count; i++)
	{
		Assert(u32_arr[i] == 3 * i, "u32 memory incorrect");
	}

	for (u32 i = 0; i < f64_count; i++)
	{
		Assert(f64_arr[i] == f64(i), "f64 memory incorrect");
	}

	FreeListFree(&alloc, u32_arr);

	for (u32 i = 0; i < f64_count; i++)
	{
		Assert(f64_arr[i] == f64(i), "f64 memory incorrect post free");
	}
}

void TestHashTable()
{
	Printfln("Starting hash table tests...");
	HashTable table;
	HashTableInit(&table, 16);

	for (u64 i = 1; i < 2000; i++)
	{
		HashTablePushU64U64(&table, i*3, i);
	}

	for (u64 i = 1; i < 2000; i++)
	{
		KeyValuePair *result = HashTableSearchU64(&table, i*3);
		Assert(result != P_HT_NIL, "HashTable result isn't found");
		Assert(result->value_u64 == i, "HashTable result doesn't match");
	}

	HashTableClear(&table);

	KeyValuePair *result = HashTableSearchU64(&table, 1);
	Assert(result == NULL, "Result isn't nil after HashTable clear");
}
