Restructure project directories
This commit is contained in:
75
test/vector.cpp
Normal file
75
test/vector.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "../sequential/vector.hpp"
|
||||
#include "testutil.hpp"
|
||||
|
||||
void FillWithSequentialNumbers(Vector<unsigned> & vector,
|
||||
unsigned const count = 1024u)
|
||||
{
|
||||
for(unsigned i = 0; i < count; ++i)
|
||||
{
|
||||
vector[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
bool TestInsertion()
|
||||
{
|
||||
unsigned const targetSize = 1024u;
|
||||
Vector<unsigned> vector;
|
||||
try
|
||||
{
|
||||
vector.Resize(targetSize);
|
||||
}
|
||||
catch(std::exception & e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
FillWithSequentialNumbers(vector, targetSize);
|
||||
|
||||
for(unsigned i = 0; i < vector.GetSize(); ++i)
|
||||
{
|
||||
if(vector[i] != i)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
vector[targetSize + 1] = 42;
|
||||
}
|
||||
catch(std::exception & e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TestResize()
|
||||
{
|
||||
Vector<unsigned> vector;
|
||||
|
||||
vector.Resize(2048u);
|
||||
FillWithSequentialNumbers(vector);
|
||||
|
||||
vector.Resize(vector.GetSize() / 2u);
|
||||
for(unsigned i = 0; i < vector.GetSize(); ++i)
|
||||
{
|
||||
if(vector[i] != i)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
vector.Resize(vector.GetSize() * 16u);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Test::Execute(TestInsertion, "Insertion test");
|
||||
Test::Execute(TestResize, "Resize test");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user