From e013eaa2042541d864a661eaf8e45ebff426ef89 Mon Sep 17 00:00:00 2001 From: Emmankoko Date: Sun, 22 Oct 2023 18:34:17 +0000 Subject: [PATCH] unittest for newly added member functions --- source/stdcpp/test/vector.d | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/source/stdcpp/test/vector.d b/source/stdcpp/test/vector.d index f7f0bc3..f37395d 100644 --- a/source/stdcpp/test/vector.d +++ b/source/stdcpp/test/vector.d @@ -8,6 +8,7 @@ module stdcpp.test.vector; import stdcpp.vector; import stdcpp.allocator; int a = 42; +int b = 9; allocator!int alloc_instance = allocator!(int).init; unittest { @@ -15,4 +16,27 @@ unittest vec.push_back(a); assert(vec.length == 5); assert(vec[4] == 42); + assert(vec.at(3) == 0); + vec.pop_back(); + assert(vec.length == 4); + vec.clear(); + assert(vec.empty == 1); +} + + + +unittest +{ + auto p = vector!int(4, b, alloc_instance); + assert(p.capacity() == 4); + p.reserve(6); + assert(p.capacity() == 6); + //3 push backs to reallocate memory by 2 after initially capacity fills up + p.push_back(a); + p.push_back(a);//capacity is 6 now + p.push_back(a); + assert(p.capacity() == 12); + p.resize(5); + assert(p.length == 5); + assert(p.sizeof == 24);//verifying three pointers }