mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-06 01:18:02 +00:00
Polish bst validate challenge and solution (#83)
Update constraints, test cases, tests, algorithm discussion, and code.
This commit is contained in:
@@ -36,7 +36,11 @@
|
||||
"\n",
|
||||
"* Can the tree have duplicates?\n",
|
||||
" * Yes\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?\n",
|
||||
" * Yes\n",
|
||||
"* Can we assume this fits in memory?\n",
|
||||
" * Yes"
|
||||
]
|
||||
},
|
||||
@@ -128,10 +132,15 @@
|
||||
"source": [
|
||||
"# %load test_bst_validate.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"from nose.tools import raises\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestBstValidate(object):\n",
|
||||
"\n",
|
||||
" @raises(Exception)\n",
|
||||
" def test_bst_validate_empty(self):\n",
|
||||
" validate_bst(None)\n",
|
||||
"\n",
|
||||
" def test_bst_validate(self):\n",
|
||||
" node = Node(5)\n",
|
||||
" insert(node, 8)\n",
|
||||
@@ -149,11 +158,13 @@
|
||||
" root.right = right\n",
|
||||
" root.left.right = invalid\n",
|
||||
" assert_equal(validate_bst(root), False)\n",
|
||||
"\n",
|
||||
" print('Success: test_bst_validate')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestBstValidate()\n",
|
||||
" test.test_bst_validate_empty()\n",
|
||||
" test.test_bst_validate()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
@@ -173,21 +184,21 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 2",
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python2"
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 2
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython2",
|
||||
"version": "2.7.10"
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.5.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
Reference in New Issue
Block a user