mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-10 03:18:02 +00:00
binary tree implementation
This commit is contained in:
@@ -161,16 +161,9 @@
|
||||
"## Unit Test"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**The following unit test is expected to fail until you solve the challenge.**"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 6,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
@@ -188,16 +181,23 @@
|
||||
"\t\t[myTree2.insert(num) for num in range (1, 100, 10)]\n",
|
||||
"\n",
|
||||
"\t\tprint(\"Test: insert checking with in order traversal\")\n",
|
||||
"\t\tassert_equal(myTree.printInOrder(), [7, 10, 25, 30, 38, 40, 50, 60, 70, 80])\n",
|
||||
"\t\tassert_equal(myTree2.printInOrder(), [1, 11, 21, 31, 41, 51, 61, 71, 81, 91])\n",
|
||||
"\t\texpectVal = [7, 10, 25, 30, 38, 40, 50, 60, 70, 80]\n",
|
||||
"\t\tassert_equal(myTree.printInOrder(), expectVal)\n",
|
||||
"\t\texpectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]\n",
|
||||
"\t\tassert_equal(myTree2.printInOrder(), expectVal)\n",
|
||||
"\n",
|
||||
"\t\tprint(\"Test: insert checking with post order traversal\")\n",
|
||||
"\t\tassert_equal(myTree.printPostOrder(), [7, 25, 10, 38, 40, 30, 60, 80, 70, 50])\n",
|
||||
"\t\tassert_equal(myTree2.printPostOrder(), [91, 81, 71, 61, 51, 41, 31, 21, 11, 1])\n",
|
||||
"\t\texpectVal = [7, 25, 10, 38, 40, 30, 60, 80, 70, 50]\n",
|
||||
"\t\tassert_equal(myTree.printPostOrder(), expectVal)\n",
|
||||
"\t\texpectVal = [91, 81, 71, 61, 51, 41, 31, 21, 11, 1]\n",
|
||||
"\t\tassert_equal(myTree2.printPostOrder(), expectVal)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\t\tprint(\"Test: insert checking with pre order traversal\")\n",
|
||||
"\t\tassert_equal(myTree.printPreOrder(), [50, 30, 10, 7, 25, 40, 38, 70, 60, 80])\n",
|
||||
"\t\tassert_equal(myTree2.printPreOrder(), [1, 11, 21, 31, 41, 51, 61, 71, 81, 91])\n",
|
||||
"\t\texpectVal = [50, 30, 10, 7, 25, 40, 38, 70, 60, 80]\n",
|
||||
"\t\tassert_equal(myTree.printPreOrder(), expectVal)\n",
|
||||
"\t\texpectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]\n",
|
||||
"\t\tassert_equal(myTree2.printPreOrder(), expectVal)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\t\tprint(\"Success: test_insert_traversals\")\n",
|
||||
@@ -234,6 +234,9 @@
|
||||
"\t\t[myTree.insert(x) for x in range(1, 5)]\n",
|
||||
"\t\tmyTree.delete(2)\n",
|
||||
"\t\tassert_equal(myTree.root.rightChild.data, 3)\n",
|
||||
" \n",
|
||||
"\t\tprint(\"Test: delete invalid value\")\n",
|
||||
"\t\tassert_equal(myTree.delete(100), False)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\t\tprint(\"Success: test_delete\")\n",
|
||||
@@ -245,8 +248,14 @@
|
||||
" testing.test_delete()\n",
|
||||
" \n",
|
||||
"if __name__=='__main__':\n",
|
||||
" main()\n",
|
||||
" "
|
||||
" main()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**The following unit test is expected to fail until you solve the challenge.**"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user