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.

---
 mempool/test/mempool_test.c | 8 ++++++++
 1 file changed, 8 insertions(+)

(limited to 'mempool/test/mempool_test.c')

diff --git a/mempool/test/mempool_test.c b/mempool/test/mempool_test.c
index 6c48a2a..5eaee51 100644
--- a/mempool/test/mempool_test.c
+++ b/mempool/test/mempool_test.c
@@ -41,6 +41,8 @@ TEST_CASE(mempool_allocate_until_full) {
     const int* block = mempool_alloc(&pool);
     TEST_TRUE(block != 0);
   }
+
+  TEST_TRUE(mempool_size(&pool) == NUM_BLOCKS);
 }
 
 // Allocate all N blocks, then free them.
@@ -60,6 +62,7 @@ TEST_CASE(mempool_fill_then_free) {
   }
 
   TEST_EQUAL(count(&pool), 0);
+  TEST_TRUE(mempool_size(&pool) == 0);
 }
 
 // Attempt to allocate blocks past the maximum pool size.
@@ -78,6 +81,8 @@ TEST_CASE(mempool_allocate_beyond_max_size) {
   for (int i = 0; i < NUM_BLOCKS; ++i) {
     TEST_EQUAL(mempool_alloc(&pool), 0);
   }
+
+  TEST_TRUE(mempool_size(&pool) == NUM_BLOCKS);
 }
 
 // Free blocks should always remain zeroed out.
@@ -114,6 +119,7 @@ TEST_CASE(mempool_traverse_empty) {
   mempool_make(&pool);
 
   TEST_EQUAL(count(&pool), 0);
+  TEST_TRUE(mempool_size(&pool) == 0);
 }
 
 // Traverse a partially full pool.
@@ -130,6 +136,7 @@ TEST_CASE(mempool_traverse_partially_full) {
   }
 
   TEST_EQUAL(sum(&pool), N * (N + 1) / 2);
+  TEST_TRUE(mempool_size(&pool) == N);
 }
 
 // Traverse a full pool.
@@ -144,6 +151,7 @@ TEST_CASE(mempool_traverse_full) {
   }
 
   TEST_EQUAL(sum(&pool), NUM_BLOCKS * (NUM_BLOCKS + 1) / 2);
+  TEST_TRUE(mempool_size(&pool) == NUM_BLOCKS);
 }
 
 // Get the ith (allocated) block.
-- 
cgit v1.2.3