mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-09 19:08:02 +00:00
Polish bst check balanced challenge and solution (#84)
Update constraints, tests, and code.
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user