Binary tree fix
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
#include "../tree/binarytree.hpp"
|
||||
#include "../src/tree/binarytree.hpp"
|
||||
#include "testutil.hpp"
|
||||
#include <vector>
|
||||
|
||||
void FillWithRandomNumbers(BinaryTree::Tree<unsigned> & tree,
|
||||
std::vector<unsigned> & control,
|
||||
unsigned const count = 512u)
|
||||
unsigned const count = 4096u)
|
||||
{
|
||||
for(unsigned i = 0u; i < count; ++i)
|
||||
{
|
||||
@@ -14,7 +14,7 @@ void FillWithRandomNumbers(BinaryTree::Tree<unsigned> & tree,
|
||||
}
|
||||
}
|
||||
|
||||
bool TestInsertContains()
|
||||
bool TestInsert()
|
||||
{
|
||||
std::vector<unsigned> control;
|
||||
BinaryTree::Tree<unsigned> tree;
|
||||
@@ -34,6 +34,33 @@ bool TestInsertContains()
|
||||
return good;
|
||||
}
|
||||
|
||||
bool TestInsertNoDuplicates()
|
||||
{
|
||||
unsigned const testSize = 8096u;
|
||||
|
||||
std::vector<unsigned> control;
|
||||
BinaryTree::Tree<unsigned> tree;
|
||||
|
||||
for(unsigned i = 0u; i < testSize; ++i)
|
||||
{
|
||||
unsigned const value = Util::GetRandomNumber();
|
||||
control.push_back(value);
|
||||
tree.InsertNoDuplicates(value);
|
||||
}
|
||||
|
||||
bool good = true;
|
||||
for(auto const & num : control)
|
||||
{
|
||||
if(!tree.Contains(num))
|
||||
{
|
||||
std::printf("\tValue %u inserted but cannot be found!\n", num);
|
||||
good = false;
|
||||
}
|
||||
}
|
||||
|
||||
return good;
|
||||
}
|
||||
|
||||
bool TestDeletion()
|
||||
{
|
||||
std::vector<unsigned> control;
|
||||
@@ -66,7 +93,8 @@ bool TestDeletion()
|
||||
|
||||
int main()
|
||||
{
|
||||
Test::Execute(TestInsertContains, "Insertion and find test");
|
||||
Test::Execute(TestInsert, "Insertion and find test");
|
||||
Test::Execute(TestInsertNoDuplicates, "Insertion without duplicates test");
|
||||
Test::Execute(TestDeletion, "Insertion and deletion test");
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../sequential/linkedlist.hpp"
|
||||
#include "../src/sequential/linkedlist.hpp"
|
||||
#include "testutil.hpp"
|
||||
|
||||
bool TestAppending()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../sequential/ringbuffer.hpp"
|
||||
#include "../src/sequential/ringbuffer.hpp"
|
||||
#include "testutil.hpp"
|
||||
|
||||
bool TestInsertion()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../sequential/stack.hpp"
|
||||
#include "../src/sequential/stack.hpp"
|
||||
#include "testutil.hpp"
|
||||
#include <stack>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../sequential/vector.hpp"
|
||||
#include "../src/sequential/vector.hpp"
|
||||
#include "testutil.hpp"
|
||||
|
||||
void FillWithSequentialNumbers(Vector<unsigned> & vector,
|
||||
|
||||
Reference in New Issue
Block a user