mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Update tree check balance challenge (#120)
Use more specific exception types.
This commit is contained in:
parent
a0944eb5f4
commit
14de5e4233
|
@ -128,7 +128,7 @@
|
||||||
"\n",
|
"\n",
|
||||||
"class TestCheckBalance(object):\n",
|
"class TestCheckBalance(object):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" @raises(Exception)\n",
|
" @raises(TypeError)\n",
|
||||||
" def test_check_balance_empty(self):\n",
|
" def test_check_balance_empty(self):\n",
|
||||||
" bst = BstBalance(None)\n",
|
" bst = BstBalance(None)\n",
|
||||||
" bst.check_balance()\n",
|
" bst.check_balance()\n",
|
||||||
|
|
|
@ -120,7 +120,7 @@
|
||||||
"\n",
|
"\n",
|
||||||
" def check_balance(self):\n",
|
" def check_balance(self):\n",
|
||||||
" if self.root is None:\n",
|
" if self.root is None:\n",
|
||||||
" raise Exception('No root node')\n",
|
" raise TypeError('root cannot be None')\n",
|
||||||
" height = self._check_height(self.root)\n",
|
" height = self._check_height(self.root)\n",
|
||||||
" return height != -1"
|
" return height != -1"
|
||||||
]
|
]
|
||||||
|
@ -155,7 +155,7 @@
|
||||||
"\n",
|
"\n",
|
||||||
"class TestCheckBalance(object):\n",
|
"class TestCheckBalance(object):\n",
|
||||||
"\n",
|
"\n",
|
||||||
" @raises(Exception)\n",
|
" @raises(TypeError)\n",
|
||||||
" def test_check_balance_empty(self):\n",
|
" def test_check_balance_empty(self):\n",
|
||||||
" bst = BstBalance(None)\n",
|
" bst = BstBalance(None)\n",
|
||||||
" bst.check_balance()\n",
|
" bst.check_balance()\n",
|
||||||
|
|
|
@ -4,7 +4,7 @@ from nose.tools import raises
|
||||||
|
|
||||||
class TestCheckBalance(object):
|
class TestCheckBalance(object):
|
||||||
|
|
||||||
@raises(Exception)
|
@raises(TypeError)
|
||||||
def test_check_balance_empty(self):
|
def test_check_balance_empty(self):
|
||||||
bst = BstBalance(None)
|
bst = BstBalance(None)
|
||||||
bst.check_balance()
|
bst.check_balance()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user