Broke the binary tree, please fix :-)
This commit is contained in:
@@ -1,22 +1,22 @@
|
||||
#include "../tree/binarytree.hpp"
|
||||
#include "testutil.hpp"
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
void FillWithRandomNumbers(BinaryTree::Tree<unsigned> & tree,
|
||||
std::unordered_set<unsigned> & control,
|
||||
std::vector<unsigned> & control,
|
||||
unsigned const count = 512u)
|
||||
{
|
||||
for(unsigned i = 0u; i < count; ++i)
|
||||
{
|
||||
unsigned const value = Util::GetRandomNumber();
|
||||
control.insert(value);
|
||||
control.push_back(value);
|
||||
tree.Insert(value);
|
||||
}
|
||||
}
|
||||
|
||||
bool TestInsertContains()
|
||||
{
|
||||
std::unordered_set<unsigned> control;
|
||||
std::vector<unsigned> control;
|
||||
BinaryTree::Tree<unsigned> tree;
|
||||
|
||||
FillWithRandomNumbers(tree, control);
|
||||
@@ -26,7 +26,7 @@ bool TestInsertContains()
|
||||
{
|
||||
if(!tree.Contains(num))
|
||||
{
|
||||
std::printf("Value %u inserted but cannot be found!\n", num);
|
||||
std::printf("\tValue %u inserted but cannot be found!\n", num);
|
||||
good = false;
|
||||
}
|
||||
}
|
||||
@@ -36,23 +36,19 @@ bool TestInsertContains()
|
||||
|
||||
bool TestDeletion()
|
||||
{
|
||||
std::unordered_set<unsigned> control;
|
||||
std::vector<unsigned> control;
|
||||
BinaryTree::Tree<unsigned> tree;
|
||||
|
||||
FillWithRandomNumbers(tree, control);
|
||||
|
||||
unsigned i = 0u;
|
||||
unsigned const toDeleteCount = control.size() / 4;
|
||||
while(i < toDeleteCount)
|
||||
for(unsigned i = 0u; i < toDeleteCount; ++i)
|
||||
{
|
||||
auto const toDelete = Util::GetRandomNumber();
|
||||
auto iter = control.find(toDelete);
|
||||
if(iter != control.end())
|
||||
{
|
||||
control.erase(iter);
|
||||
tree.Delete(i);
|
||||
++i;
|
||||
}
|
||||
auto const toDeleteIndex = Util::GetRandomNumber() % control.size();
|
||||
auto const toDeleteValue = control[toDeleteIndex];
|
||||
|
||||
control.erase(control.begin() + toDeleteIndex);
|
||||
tree.Delete(toDeleteValue);
|
||||
}
|
||||
|
||||
bool good = true;
|
||||
|
||||
@@ -48,11 +48,11 @@ void Execute(bool (*testFunction)(std::vector<std::string> &), char const * cons
|
||||
}
|
||||
else
|
||||
{
|
||||
std::printf("[FAIL] %s\n", message);
|
||||
for(auto & issue : issues)
|
||||
{
|
||||
std::printf(" Issue: %s\n", issue.c_str());
|
||||
}
|
||||
std::printf("[FAIL] %s\n", message);
|
||||
}
|
||||
}
|
||||
catch(std::exception & e)
|
||||
|
||||
Reference in New Issue
Block a user