Browse Source

avl_tree.h: adding more test, fixing more bugs

undefined
Guillaume Bittoun Sam Hocevar <sam@hocevar.net> 10 years ago
parent
commit
1d144ebf52
2 changed files with 7 additions and 2 deletions
  1. +2
    -2
      src/lol/algorithm/avl_tree.h
  2. +5
    -0
      src/t/algorithm/avl_tree.cpp

+ 2
- 2
src/lol/algorithm/avl_tree.h View File

@@ -171,8 +171,8 @@ protected:


void compute_balance() void compute_balance()
{ {
this->m_stairs_lo = this->m_lo ? this->m_lo->m_stairs_lo + this->m_lo->m_stairs_hi + 1 : 0;
this->m_stairs_hi = this->m_hi ? this->m_hi->m_stairs_lo + this->m_hi->m_stairs_hi + 1 : 0;
this->m_stairs_lo = this->m_lo ? lol::max(this->m_lo->m_stairs_lo, this->m_lo->m_stairs_hi) + 1 : 0;
this->m_stairs_hi = this->m_hi ? lol::max(this->m_hi->m_stairs_lo, this->m_hi->m_stairs_hi) + 1 : 0;
} }


int get_balance() int get_balance()


+ 5
- 0
src/t/algorithm/avl_tree.cpp View File

@@ -12,6 +12,8 @@


#include <lol/engine-internal.h> #include <lol/engine-internal.h>


#include <lol/algorithm/avl_tree.h>

#include <lolunit.h> #include <lolunit.h>


namespace lol namespace lol
@@ -60,6 +62,9 @@ lolunit_declare_fixture(AvlTreeTest)


lolunit_assert_equal(tree.insert(-1, 1), true); lolunit_assert_equal(tree.insert(-1, 1), true);
lolunit_assert_equal(tree.get_root_balance(), -1); lolunit_assert_equal(tree.get_root_balance(), -1);

lolunit_assert_equal(tree.insert(-2, 1), true);
lolunit_assert_equal(tree.get_root_balance(), 0);
} }
}; };




Loading…
Cancel
Save