From afe1e1d12e42a0881aff63c766c14e48319b560c Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 9 Mar 2024 08:36:02 -0800 Subject: Define functions to get the number of used blocks. --- mem/test/mem_test.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'mem/test') diff --git a/mem/test/mem_test.c b/mem/test/mem_test.c index d3c43b9..97db079 100644 --- a/mem/test/mem_test.c +++ b/mem/test/mem_test.c @@ -41,6 +41,8 @@ TEST_CASE(mem_fully_allocate) { const int* block = mem_alloc(&mem, 1); TEST_TRUE(block != 0); } + + TEST_TRUE(mem_size(&mem) == NUM_BLOCKS); } // Allocate N chunks of 1 block each, then free them. @@ -60,6 +62,7 @@ TEST_CASE(mem_fill_then_free) { } TEST_EQUAL(count(&mem), 0); + TEST_TRUE(mem_size(&mem) == 0); } // Attempt to allocate blocks past the maximum allocator size. @@ -78,6 +81,8 @@ TEST_CASE(mem_allocate_beyond_max_size) { for (int i = 0; i < NUM_BLOCKS; ++i) { TEST_EQUAL(mem_alloc(&mem, 1), 0); } + + TEST_TRUE(mem_size(&mem) == NUM_BLOCKS); } // Free blocks should always remain zeroed out. @@ -114,6 +119,7 @@ TEST_CASE(mem_traverse_empty) { mem_make(&mem); TEST_EQUAL(count(&mem), 0); + TEST_TRUE(mem_size(&mem) == 0); } // Traverse a partially full allocator. @@ -130,6 +136,7 @@ TEST_CASE(mem_traverse_partially_full) { } TEST_EQUAL(sum(&mem), (N) * (N + 1) / 2); + TEST_TRUE(mem_size(&mem) == N); } // Traverse a full allocator. @@ -144,6 +151,7 @@ TEST_CASE(mem_traverse_full) { } TEST_EQUAL(sum(&mem), (NUM_BLOCKS) * (NUM_BLOCKS + 1) / 2); + TEST_TRUE(mem_size(&mem) == NUM_BLOCKS); } // Get the ith (allocated) chunk. -- cgit v1.2.3