From 227690f3b0c7d56a479d18e34a069b15d0d9475b Mon Sep 17 00:00:00 2001 From: Guillaume Bittoun Date: Tue, 14 Oct 2014 07:58:24 +0000 Subject: [PATCH] avl_tree: bug fixes + tests + nit --- src/t/algorithm/avl_tree.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/t/algorithm/avl_tree.cpp b/src/t/algorithm/avl_tree.cpp index ea55b447..f902ea58 100644 --- a/src/t/algorithm/avl_tree.cpp +++ b/src/t/algorithm/avl_tree.cpp @@ -12,8 +12,6 @@ #include -#include - #include namespace lol @@ -95,6 +93,37 @@ lolunit_declare_fixture(AvlTreeTest) lolunit_assert_equal(tree.erase(20), true); lolunit_assert_equal(tree.insert(20, 1), true); } + + lolunit_declare_test(AvlTreeExistence) + { + test_tree tree; + + lolunit_assert_equal(tree.insert(10, 1), true); + lolunit_assert_equal(tree.get_root_balance(), 0); + + lolunit_assert_equal(tree.insert(20, 1), true); + lolunit_assert_equal(tree.get_root_balance(), 1); + + lolunit_assert_equal(tree.erase(10), true); + lolunit_assert_equal(tree.exists(20), true); + lolunit_assert_equal(tree.exists(10), false); + + lolunit_assert_equal(tree.insert(10, 1), true); + lolunit_assert_equal(tree.get_root_balance(), -1); + + lolunit_assert_equal(tree.insert(30, 1), true); + lolunit_assert_equal(tree.get_root_balance(), 0); + + lolunit_assert_equal(tree.insert(40, 1), true); + lolunit_assert_equal(tree.get_root_balance(), 1); + + lolunit_assert_equal(tree.insert(50, 1), true); + lolunit_assert_equal(tree.get_root_balance(), 1); + + lolunit_assert_equal(tree.erase(30), true); + lolunit_assert_equal(tree.exists(40), true); + lolunit_assert_equal(tree.exists(50), true); + } }; }