Skip to content

Commit

Permalink
unittest for newly added member functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmankoko committed Oct 22, 2023
1 parent 60c5237 commit e013eaa
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions source/stdcpp/test/vector.d
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,35 @@ module stdcpp.test.vector;
import stdcpp.vector;
import stdcpp.allocator;
int a = 42;
int b = 9;
allocator!int alloc_instance = allocator!(int).init;
unittest
{
auto vec = vector!int(4, alloc_instance);
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
}

0 comments on commit e013eaa

Please sign in to comment.