Restructure project directories

This commit is contained in:
2019-05-01 19:11:06 +02:00
parent 5e0a815f26
commit db777837ee
7 changed files with 2 additions and 2 deletions

77
test/binarytree.cpp Normal file
View File

@@ -0,0 +1,77 @@
#include "../tree/binarytree.hpp"
#include "testutil.hpp"
#include <unordered_set>
void FillWithRandomNumbers(BinaryTree::Tree<unsigned> & tree,
std::unordered_set<unsigned> & control,
unsigned const count = 512u)
{
for(unsigned i = 0u; i < count; ++i)
{
unsigned const value = Util::GetRandomNumber();
control.insert(value);
tree.Insert(value);
}
}
bool TestInsertContains()
{
std::unordered_set<unsigned> control;
BinaryTree::Tree<unsigned> tree;
FillWithRandomNumbers(tree, control);
bool good = true;
for(auto const & num : control)
{
if(!tree.Contains(num))
{
std::printf("Value %u inserted but cannot be found!\n", num);
good = false;
}
}
return good;
}
bool TestDeletion()
{
std::unordered_set<unsigned> control;
BinaryTree::Tree<unsigned> tree;
FillWithRandomNumbers(tree, control);
unsigned i = 0u;
unsigned const toDeleteCount = control.size() / 4;
while(i < toDeleteCount)
{
auto const toDelete = Util::GetRandomNumber();
auto iter = control.find(toDelete);
if(iter != control.end())
{
control.erase(iter);
tree.Delete(i);
++i;
}
}
bool good = true;
for(auto const & num : control)
{
if(!tree.Contains(num))
{
std::printf("Value %u inserted but cannot be found!\n", num);
good = false;
}
}
return good;
}
int main()
{
Test::Execute(TestInsertContains, "Insertion and find test");
Test::Execute(TestDeletion, "Insertion and deletion test");
return 0;
}