Polish bst check balanced challenge and solution (#84)

Update constraints, tests, and code.
This commit is contained in:
Donne Martin
2016-06-25 22:13:15 -04:00
committed by GitHub
parent 589ff06b15
commit d3fd7bc0a1
3 changed files with 23 additions and 10 deletions

View File

@@ -36,7 +36,7 @@
"\n",
"* Is a balanced tree one where the heights of two sub trees of any node doesn't differ by more than 1?\n",
" * Yes\n",
"* If this is called on a None input, should we return False?\n",
"* If this is called on a None input, should we raise an exception?\n",
" * Yes\n",
"* Can we assume we already have a Node class with an insert method?\n",
" * Yes\n",
@@ -121,13 +121,16 @@
"source": [
"# %load test_check_balance.py\n",
"from nose.tools import assert_equal\n",
"from nose.tools import raises\n",
"\n",
"\n",
"class TestCheckBalance(object):\n",
"\n",
" def test_check_balance(self):\n",
" assert_equal(check_balance(None), False)\n",
" @raises(Exception)\n",
" def test_check_balance_empty(self):\n",
" check_balance(None)\n",
"\n",
" def test_check_balance(self):\n",
" node = Node(5)\n",
" assert_equal(check_balance(node), True)\n",
"\n",
@@ -158,6 +161,7 @@
"\n",
"def main():\n",
" test = TestCheckBalance()\n",
" test.test_check_balance_empty()\n",
" test.test_check_balance()\n",
"\n",
"\n",