From a94017c6d887be95cea78c1dda7414628d54d6c1 Mon Sep 17 00:00:00 2001 From: Tijmen van Nesselrooij Date: Sun, 12 May 2019 13:36:05 +0200 Subject: [PATCH] Binary tree fix --- test/binarytree.cpp | 36 ++++++++++++++++++++++++++++++++---- test/linkedlist.cpp | 2 +- test/ringbuffer.cpp | 2 +- test/stack.cpp | 2 +- test/vector.cpp | 2 +- 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/test/binarytree.cpp b/test/binarytree.cpp index 6f5e219..3d90b46 100644 --- a/test/binarytree.cpp +++ b/test/binarytree.cpp @@ -1,10 +1,10 @@ -#include "../tree/binarytree.hpp" +#include "../src/tree/binarytree.hpp" #include "testutil.hpp" #include void FillWithRandomNumbers(BinaryTree::Tree & tree, std::vector & control, - unsigned const count = 512u) + unsigned const count = 4096u) { for(unsigned i = 0u; i < count; ++i) { @@ -14,7 +14,7 @@ void FillWithRandomNumbers(BinaryTree::Tree & tree, } } -bool TestInsertContains() +bool TestInsert() { std::vector control; BinaryTree::Tree tree; @@ -34,6 +34,33 @@ bool TestInsertContains() return good; } +bool TestInsertNoDuplicates() +{ + unsigned const testSize = 8096u; + + std::vector control; + BinaryTree::Tree 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 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; diff --git a/test/linkedlist.cpp b/test/linkedlist.cpp index 092f9c2..0b2efef 100644 --- a/test/linkedlist.cpp +++ b/test/linkedlist.cpp @@ -1,4 +1,4 @@ -#include "../sequential/linkedlist.hpp" +#include "../src/sequential/linkedlist.hpp" #include "testutil.hpp" bool TestAppending() diff --git a/test/ringbuffer.cpp b/test/ringbuffer.cpp index a3e86bd..b645c16 100644 --- a/test/ringbuffer.cpp +++ b/test/ringbuffer.cpp @@ -1,4 +1,4 @@ -#include "../sequential/ringbuffer.hpp" +#include "../src/sequential/ringbuffer.hpp" #include "testutil.hpp" bool TestInsertion() diff --git a/test/stack.cpp b/test/stack.cpp index b8a12a2..9a901d7 100644 --- a/test/stack.cpp +++ b/test/stack.cpp @@ -1,4 +1,4 @@ -#include "../sequential/stack.hpp" +#include "../src/sequential/stack.hpp" #include "testutil.hpp" #include diff --git a/test/vector.cpp b/test/vector.cpp index e7034d8..ef4d324 100644 --- a/test/vector.cpp +++ b/test/vector.cpp @@ -1,4 +1,4 @@ -#include "../sequential/vector.hpp" +#include "../src/sequential/vector.hpp" #include "testutil.hpp" void FillWithSequentialNumbers(Vector & vector,