#273: Remove nose dependency for staging/ (#283)

This commit is contained in:
Donne Martin 2020-07-15 20:19:14 -04:00 committed by GitHub
parent 46d3939632
commit 0236a45a94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 170 additions and 189 deletions

View File

@ -100,20 +100,24 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from nose.tools import assert_equal\n", "import unittest\n",
"\n",
"\n",
"class UnitTest(unittest.TestCase):\n",
"\n", "\n",
"class UnitTest (object):\n",
" def testReverseWords(self, func):\n", " def testReverseWords(self, func):\n",
" assert_equal(func('the sun is hot'), 'eht nus si toh')\n", " self.assertEqual(func('the sun is hot'), 'eht nus si toh')\n",
" assert_equal(func(''), None)\n", " self.assertEqual(func(''), None)\n",
" assert_equal(func('123 456 789'), '321 654 987')\n", " self.assertEqual(func('123 456 789'), '321 654 987')\n",
" assert_equal(func('magic'), 'cigam')\n", " self.assertEqual(func('magic'), 'cigam')\n",
" print('Success: reverse_words')\n", " print('Success: reverse_words')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = UnitTest()\n", " test = UnitTest()\n",
" test.testReverseWords(reverse_words)\n", " test.testReverseWords(reverse_words)\n",
"\n", "\n",
"\n",
"if __name__==\"__main__\":\n", "if __name__==\"__main__\":\n",
" main()" " main()"
] ]
@ -129,23 +133,23 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 2", "display_name": "Python 3",
"language": "python", "language": "python",
"name": "python2" "name": "python3"
}, },
"language_info": { "language_info": {
"codemirror_mode": { "codemirror_mode": {
"name": "ipython", "name": "ipython",
"version": 2.0 "version": 3
}, },
"file_extension": ".py", "file_extension": ".py",
"mimetype": "text/x-python", "mimetype": "text/x-python",
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython2", "pygments_lexer": "ipython3",
"version": "2.7.10" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -66,10 +66,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"def reverse_words(S):\n", "def reverse_words(S):\n",
@ -85,10 +83,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -100,30 +96,32 @@
], ],
"source": [ "source": [
"%%writefile reverse_words_solution.py\n", "%%writefile reverse_words_solution.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n",
"\n",
"class TestReverseWords(unittest.TestCase):\n",
"\n", "\n",
"class UnitTest (object):\n",
" def testReverseWords(self, func):\n", " def testReverseWords(self, func):\n",
" assert_equal(func('the sun is hot'), 'eht nus si toh')\n", " self.assertEqual(func('the sun is hot'), 'eht nus si toh')\n",
" assert_equal(func(''), None)\n", " self.assertEqual(func(''), None)\n",
" assert_equal(func('123 456 789'), '321 654 987')\n", " self.assertEqual(func('123 456 789'), '321 654 987')\n",
" assert_equal(func('magic'), 'cigam')\n", " self.assertEqual(func('magic'), 'cigam')\n",
" print('Success: reverse_words')\n", " print('Success: reverse_words')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = UnitTest()\n", " test = TestReverseWords()\n",
" test.testReverseWords(reverse_words)\n", " test.testReverseWords(reverse_words)\n",
"\n", "\n",
"\n",
"if __name__==\"__main__\":\n", "if __name__==\"__main__\":\n",
" main()" " main()"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -140,23 +138,23 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 2", "display_name": "Python 3",
"language": "python", "language": "python",
"name": "python2" "name": "python3"
}, },
"language_info": { "language_info": {
"codemirror_mode": { "codemirror_mode": {
"name": "ipython", "name": "ipython",
"version": 2 "version": 3
}, },
"file_extension": ".py", "file_extension": ".py",
"mimetype": "text/x-python", "mimetype": "text/x-python",
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython2", "pygments_lexer": "ipython3",
"version": "2.7.6" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -1,16 +1,20 @@
from nose.tools import assert_equal import unittest
class TestReverseWords(unittest.TestCase):
class UnitTest (object):
def testReverseWords(self, func): def testReverseWords(self, func):
assert_equal(func('the sun is hot'), 'eht nus si toh') self.assertEqual(func('the sun is hot'), 'eht nus si toh')
assert_equal(func(''), None) self.assertEqual(func(''), None)
assert_equal(func('123 456 789'), '321 654 987') self.assertEqual(func('123 456 789'), '321 654 987')
assert_equal(func('magic'), 'cigam') self.assertEqual(func('magic'), 'cigam')
print('Success: reverse_words') print('Success: reverse_words')
def main(): def main():
test = UnitTest() test = TestReverseWords()
test.testReverseWords(reverse_words) test.testReverseWords(reverse_words)
if __name__=="__main__": if __name__=="__main__":
main() main()

View File

@ -93,9 +93,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Node (object):\n", "class Node (object):\n",
@ -111,9 +109,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class BinaryTree (object):\n", "class BinaryTree (object):\n",
@ -163,15 +159,13 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"class TestBinaryTree(object):\n", "class TestBinaryTree(unittest.TestCase):\n",
"\n", "\n",
"\tdef test_insert_traversals (self):\n", "\tdef test_insert_traversals (self):\n",
"\t\tmyTree = BinaryTree()\n", "\t\tmyTree = BinaryTree()\n",
@ -182,22 +176,22 @@
"\n", "\n",
"\t\tprint(\"Test: insert checking with in order traversal\")\n", "\t\tprint(\"Test: insert checking with in order traversal\")\n",
"\t\texpectVal = [7, 10, 25, 30, 38, 40, 50, 60, 70, 80]\n", "\t\texpectVal = [7, 10, 25, 30, 38, 40, 50, 60, 70, 80]\n",
"\t\tassert_equal(myTree.printInOrder(), expectVal)\n", "\t\tself.assertEqual(myTree.printInOrder(), expectVal)\n",
"\t\texpectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]\n", "\t\texpectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]\n",
"\t\tassert_equal(myTree2.printInOrder(), expectVal)\n", "\t\tself.assertEqual(myTree2.printInOrder(), expectVal)\n",
"\n", "\n",
"\t\tprint(\"Test: insert checking with post order traversal\")\n", "\t\tprint(\"Test: insert checking with post order traversal\")\n",
"\t\texpectVal = [7, 25, 10, 38, 40, 30, 60, 80, 70, 50]\n", "\t\texpectVal = [7, 25, 10, 38, 40, 30, 60, 80, 70, 50]\n",
"\t\tassert_equal(myTree.printPostOrder(), expectVal)\n", "\t\tself.assertEqual(myTree.printPostOrder(), expectVal)\n",
"\t\texpectVal = [91, 81, 71, 61, 51, 41, 31, 21, 11, 1]\n", "\t\texpectVal = [91, 81, 71, 61, 51, 41, 31, 21, 11, 1]\n",
"\t\tassert_equal(myTree2.printPostOrder(), expectVal)\n", "\t\tself.assertEqual(myTree2.printPostOrder(), expectVal)\n",
"\n", "\n",
"\n", "\n",
"\t\tprint(\"Test: insert checking with pre order traversal\")\n", "\t\tprint(\"Test: insert checking with pre order traversal\")\n",
"\t\texpectVal = [50, 30, 10, 7, 25, 40, 38, 70, 60, 80]\n", "\t\texpectVal = [50, 30, 10, 7, 25, 40, 38, 70, 60, 80]\n",
"\t\tassert_equal(myTree.printPreOrder(), expectVal)\n", "\t\tself.assertEqual(myTree.printPreOrder(), expectVal)\n",
"\t\texpectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]\n", "\t\texpectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]\n",
"\t\tassert_equal(myTree2.printPreOrder(), expectVal)\n", "\t\tself.assertEqual(myTree2.printPreOrder(), expectVal)\n",
"\n", "\n",
"\n", "\n",
"\t\tprint(\"Success: test_insert_traversals\")\n", "\t\tprint(\"Success: test_insert_traversals\")\n",
@ -209,16 +203,16 @@
"\t\tmyTree.insert(21)\n", "\t\tmyTree.insert(21)\n",
"\n", "\n",
"\t\tprint(\"Test: max node\")\n", "\t\tprint(\"Test: max node\")\n",
"\t\tassert_equal(myTree.maxNode(), 21)\n", "\t\tself.assertEqual(myTree.maxNode(), 21)\n",
"\t\tmyTree.insert(32)\n", "\t\tmyTree.insert(32)\n",
"\t\tassert_equal(myTree.maxNode(), 32)\n", "\t\tself.assertEqual(myTree.maxNode(), 32)\n",
"\n", "\n",
"\t\tprint(\"Test: min node\")\n", "\t\tprint(\"Test: min node\")\n",
"\t\tassert_equal(myTree.minNode(), 1)\n", "\t\tself.assertEqual(myTree.minNode(), 1)\n",
"\n", "\n",
"\t\tprint(\"Test: min node inserting negative number\")\n", "\t\tprint(\"Test: min node inserting negative number\")\n",
"\t\tmyTree.insert(-10)\n", "\t\tmyTree.insert(-10)\n",
"\t\tassert_equal(myTree.minNode(), -10)\n", "\t\tself.assertEqual(myTree.minNode(), -10)\n",
"\n", "\n",
"\t\tprint(\"Success: test_max_min_nodes\")\n", "\t\tprint(\"Success: test_max_min_nodes\")\n",
"\n", "\n",
@ -228,15 +222,15 @@
"\n", "\n",
"\t\tprint(\"Test: delete\")\n", "\t\tprint(\"Test: delete\")\n",
"\t\tmyTree.delete(5)\n", "\t\tmyTree.delete(5)\n",
"\t\tassert_equal(myTree.treeIsEmpty(), True)\n", "\t\tself.assertEqual(myTree.treeIsEmpty(), True)\n",
"\t\t\n", "\t\t\n",
"\t\tprint(\"Test: more complex deletions\")\n", "\t\tprint(\"Test: more complex deletions\")\n",
"\t\t[myTree.insert(x) for x in range(1, 5)]\n", "\t\t[myTree.insert(x) for x in range(1, 5)]\n",
"\t\tmyTree.delete(2)\n", "\t\tmyTree.delete(2)\n",
"\t\tassert_equal(myTree.root.rightChild.data, 3)\n", "\t\tself.assertEqual(myTree.root.rightChild.data, 3)\n",
" \n", " \n",
"\t\tprint(\"Test: delete invalid value\")\n", "\t\tprint(\"Test: delete invalid value\")\n",
"\t\tassert_equal(myTree.delete(100), False)\n", "\t\tself.assertEqual(myTree.delete(100), False)\n",
"\n", "\n",
"\n", "\n",
"\t\tprint(\"Success: test_delete\")\n", "\t\tprint(\"Success: test_delete\")\n",
@ -284,9 +278,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.4.3" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -169,10 +169,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -343,10 +341,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"%run binary_search_tree.py" "%run binary_search_tree.py"
@ -354,10 +350,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -369,9 +363,9 @@
], ],
"source": [ "source": [
"%%writefile test_binary_search_tree.py\n", "%%writefile test_binary_search_tree.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"class TestBinaryTree(object):\n", "class TestBinaryTree(unittest.TestCase):\n",
"\n", "\n",
"\tdef test_insert_traversals (self):\n", "\tdef test_insert_traversals (self):\n",
"\t\tmyTree = BinaryTree()\n", "\t\tmyTree = BinaryTree()\n",
@ -382,22 +376,22 @@
"\n", "\n",
"\t\tprint(\"Test: insert checking with in order traversal\")\n", "\t\tprint(\"Test: insert checking with in order traversal\")\n",
"\t\texpectVal = [7, 10, 25, 30, 38, 40, 50, 60, 70, 80]\n", "\t\texpectVal = [7, 10, 25, 30, 38, 40, 50, 60, 70, 80]\n",
"\t\tassert_equal(myTree.printInOrder(), expectVal)\n", "\t\tself.assertEqual(myTree.printInOrder(), expectVal)\n",
"\t\texpectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]\n", "\t\texpectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]\n",
"\t\tassert_equal(myTree2.printInOrder(), expectVal)\n", "\t\tself.assertEqual(myTree2.printInOrder(), expectVal)\n",
"\n", "\n",
"\t\tprint(\"Test: insert checking with post order traversal\")\n", "\t\tprint(\"Test: insert checking with post order traversal\")\n",
"\t\texpectVal = [7, 25, 10, 38, 40, 30, 60, 80, 70, 50]\n", "\t\texpectVal = [7, 25, 10, 38, 40, 30, 60, 80, 70, 50]\n",
"\t\tassert_equal(myTree.printPostOrder(), expectVal)\n", "\t\tself.assertEqual(myTree.printPostOrder(), expectVal)\n",
"\t\texpectVal = [91, 81, 71, 61, 51, 41, 31, 21, 11, 1]\n", "\t\texpectVal = [91, 81, 71, 61, 51, 41, 31, 21, 11, 1]\n",
"\t\tassert_equal(myTree2.printPostOrder(), expectVal)\n", "\t\tself.assertEqual(myTree2.printPostOrder(), expectVal)\n",
"\n", "\n",
"\n", "\n",
"\t\tprint(\"Test: insert checking with pre order traversal\")\n", "\t\tprint(\"Test: insert checking with pre order traversal\")\n",
"\t\texpectVal = [50, 30, 10, 7, 25, 40, 38, 70, 60, 80]\n", "\t\texpectVal = [50, 30, 10, 7, 25, 40, 38, 70, 60, 80]\n",
"\t\tassert_equal(myTree.printPreOrder(), expectVal)\n", "\t\tself.assertEqual(myTree.printPreOrder(), expectVal)\n",
"\t\texpectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]\n", "\t\texpectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]\n",
"\t\tassert_equal(myTree2.printPreOrder(), expectVal)\n", "\t\tself.assertEqual(myTree2.printPreOrder(), expectVal)\n",
"\n", "\n",
"\n", "\n",
"\t\tprint(\"Success: test_insert_traversals\")\n", "\t\tprint(\"Success: test_insert_traversals\")\n",
@ -409,16 +403,16 @@
"\t\tmyTree.insert(21)\n", "\t\tmyTree.insert(21)\n",
"\n", "\n",
"\t\tprint(\"Test: max node\")\n", "\t\tprint(\"Test: max node\")\n",
"\t\tassert_equal(myTree.maxNode(), 21)\n", "\t\tself.assertEqual(myTree.maxNode(), 21)\n",
"\t\tmyTree.insert(32)\n", "\t\tmyTree.insert(32)\n",
"\t\tassert_equal(myTree.maxNode(), 32)\n", "\t\tself.assertEqual(myTree.maxNode(), 32)\n",
"\n", "\n",
"\t\tprint(\"Test: min node\")\n", "\t\tprint(\"Test: min node\")\n",
"\t\tassert_equal(myTree.minNode(), 1)\n", "\t\tself.assertEqual(myTree.minNode(), 1)\n",
"\n", "\n",
"\t\tprint(\"Test: min node inserting negative number\")\n", "\t\tprint(\"Test: min node inserting negative number\")\n",
"\t\tmyTree.insert(-10)\n", "\t\tmyTree.insert(-10)\n",
"\t\tassert_equal(myTree.minNode(), -10)\n", "\t\tself.assertEqual(myTree.minNode(), -10)\n",
"\n", "\n",
"\t\tprint(\"Success: test_max_min_nodes\")\n", "\t\tprint(\"Success: test_max_min_nodes\")\n",
"\n", "\n",
@ -428,15 +422,15 @@
"\n", "\n",
"\t\tprint(\"Test: delete\")\n", "\t\tprint(\"Test: delete\")\n",
"\t\tmyTree.delete(5)\n", "\t\tmyTree.delete(5)\n",
"\t\tassert_equal(myTree.treeIsEmpty(), True)\n", "\t\tself.assertEqual(myTree.treeIsEmpty(), True)\n",
"\t\t\n", "\t\t\n",
"\t\tprint(\"Test: more complex deletions\")\n", "\t\tprint(\"Test: more complex deletions\")\n",
"\t\t[myTree.insert(x) for x in range(1, 5)]\n", "\t\t[myTree.insert(x) for x in range(1, 5)]\n",
"\t\tmyTree.delete(2)\n", "\t\tmyTree.delete(2)\n",
"\t\tassert_equal(myTree.root.rightChild.data, 3)\n", "\t\tself.assertEqual(myTree.root.rightChild.data, 3)\n",
" \n", " \n",
"\t\tprint(\"Test: delete invalid value\")\n", "\t\tprint(\"Test: delete invalid value\")\n",
"\t\tassert_equal(myTree.delete(100), False)\n", "\t\tself.assertEqual(myTree.delete(100), False)\n",
"\n", "\n",
"\n", "\n",
"\t\tprint(\"Success: test_delete\")\n", "\t\tprint(\"Success: test_delete\")\n",
@ -453,10 +447,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 4,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -498,9 +490,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.4.3" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -1,6 +1,6 @@
from nose.tools import assert_equal import unittest
class TestBinaryTree(object): class TestBinaryTree(unittest.TestCase):
def test_insert_traversals (self): def test_insert_traversals (self):
myTree = BinaryTree() myTree = BinaryTree()
@ -11,22 +11,22 @@ class TestBinaryTree(object):
print("Test: insert checking with in order traversal") print("Test: insert checking with in order traversal")
expectVal = [7, 10, 25, 30, 38, 40, 50, 60, 70, 80] expectVal = [7, 10, 25, 30, 38, 40, 50, 60, 70, 80]
assert_equal(myTree.printInOrder(), expectVal) self.assertEqual(myTree.printInOrder(), expectVal)
expectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91] expectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]
assert_equal(myTree2.printInOrder(), expectVal) self.assertEqual(myTree2.printInOrder(), expectVal)
print("Test: insert checking with post order traversal") print("Test: insert checking with post order traversal")
expectVal = [7, 25, 10, 38, 40, 30, 60, 80, 70, 50] expectVal = [7, 25, 10, 38, 40, 30, 60, 80, 70, 50]
assert_equal(myTree.printPostOrder(), expectVal) self.assertEqual(myTree.printPostOrder(), expectVal)
expectVal = [91, 81, 71, 61, 51, 41, 31, 21, 11, 1] expectVal = [91, 81, 71, 61, 51, 41, 31, 21, 11, 1]
assert_equal(myTree2.printPostOrder(), expectVal) self.assertEqual(myTree2.printPostOrder(), expectVal)
print("Test: insert checking with pre order traversal") print("Test: insert checking with pre order traversal")
expectVal = [50, 30, 10, 7, 25, 40, 38, 70, 60, 80] expectVal = [50, 30, 10, 7, 25, 40, 38, 70, 60, 80]
assert_equal(myTree.printPreOrder(), expectVal) self.assertEqual(myTree.printPreOrder(), expectVal)
expectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91] expectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]
assert_equal(myTree2.printPreOrder(), expectVal) self.assertEqual(myTree2.printPreOrder(), expectVal)
print("Success: test_insert_traversals") print("Success: test_insert_traversals")
@ -38,16 +38,16 @@ class TestBinaryTree(object):
myTree.insert(21) myTree.insert(21)
print("Test: max node") print("Test: max node")
assert_equal(myTree.maxNode(), 21) self.assertEqual(myTree.maxNode(), 21)
myTree.insert(32) myTree.insert(32)
assert_equal(myTree.maxNode(), 32) self.assertEqual(myTree.maxNode(), 32)
print("Test: min node") print("Test: min node")
assert_equal(myTree.minNode(), 1) self.assertEqual(myTree.minNode(), 1)
print("Test: min node inserting negative number") print("Test: min node inserting negative number")
myTree.insert(-10) myTree.insert(-10)
assert_equal(myTree.minNode(), -10) self.assertEqual(myTree.minNode(), -10)
print("Success: test_max_min_nodes") print("Success: test_max_min_nodes")
@ -57,14 +57,15 @@ class TestBinaryTree(object):
print("Test: delete") print("Test: delete")
myTree.delete(5) myTree.delete(5)
assert_equal(myTree.treeIsEmpty(), True) self.assertEqual(myTree.treeIsEmpty(), True)
print("Test: more complex deletions") print("Test: more complex deletions")
[myTree.insert(x) for x in range(1, 5)] [myTree.insert(x) for x in range(1, 5)]
myTree.delete(2) myTree.delete(2)
assert_equal(myTree.root.rightChild.data, 3) self.assertEqual(myTree.root.rightChild.data, 3)
print("Test: delete invalid value") print("Test: delete invalid value")
assert_equal(myTree.delete(100), False) self.assertEqual(myTree.delete(100), False)
print("Success: test_delete") print("Success: test_delete")

View File

@ -71,9 +71,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"def group_ordered(list_in):\n", "def group_ordered(list_in):\n",
@ -98,28 +96,26 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# %load test_group_ordered.py\n", "# %load test_group_ordered.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class TestGroupOrdered(object):\n", "class TestGroupOrdered(unittest.TestCase):\n",
" def test_group_ordered(self, func):\n", " def test_group_ordered(self, func):\n",
"\n", "\n",
" assert_equal(func(None), None)\n", " self.assertEqual(func(None), None)\n",
" print('Success: ' + func.__name__ + \" None case.\")\n", " print('Success: ' + func.__name__ + \" None case.\")\n",
" assert_equal(func([]), [])\n", " self.assertEqual(func([]), [])\n",
" print('Success: ' + func.__name__ + \" Empty case.\")\n", " print('Success: ' + func.__name__ + \" Empty case.\")\n",
" assert_equal(func([1]), [1])\n", " self.assertEqual(func([1]), [1])\n",
" print('Success: ' + func.__name__ + \" Single element case.\")\n", " print('Success: ' + func.__name__ + \" Single element case.\")\n",
" assert_equal(func([1, 2, 1, 3, 2]), [1, 1, 2, 2, 3])\n", " self.assertEqual(func([1, 2, 1, 3, 2]), [1, 1, 2, 2, 3])\n",
" assert_equal(func(['a', 'b', 'a']), ['a', 'a', 'b'])\n", " self.assertEqual(func(['a', 'b', 'a']), ['a', 'a', 'b'])\n",
" assert_equal(func([1, 1, 2, 3, 4, 5, 2, 1]), [1, 1, 1, 2, 2, 3, 4, 5])\n", " self.assertEqual(func([1, 1, 2, 3, 4, 5, 2, 1]), [1, 1, 1, 2, 2, 3, 4, 5])\n",
" assert_equal(func([1, 2, 3, 4, 3, 4]), [1, 2, 3, 3, 4, 4])\n", " self.assertEqual(func([1, 2, 3, 4, 3, 4]), [1, 2, 3, 3, 4, 4])\n",
" print('Success: ' + func.__name__)\n", " print('Success: ' + func.__name__)\n",
"\n", "\n",
"\n", "\n",
@ -149,23 +145,23 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 2", "display_name": "Python 3",
"language": "python", "language": "python",
"name": "python2" "name": "python3"
}, },
"language_info": { "language_info": {
"codemirror_mode": { "codemirror_mode": {
"name": "ipython", "name": "ipython",
"version": 2 "version": 3
}, },
"file_extension": ".py", "file_extension": ".py",
"mimetype": "text/x-python", "mimetype": "text/x-python",
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython2", "pygments_lexer": "ipython3",
"version": "2.7.6" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -77,10 +77,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"def make_order_list(list_in):\n", "def make_order_list(list_in):\n",
@ -135,10 +133,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"from collections import OrderedDict\n", "from collections import OrderedDict\n",
@ -163,10 +159,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -178,22 +172,22 @@
], ],
"source": [ "source": [
"%%writefile test_group_ordered.py\n", "%%writefile test_group_ordered.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class TestGroupOrdered(object):\n", "class TestGroupOrdered(unittest.TestCase):\n",
" def test_group_ordered(self, func):\n", " def test_group_ordered(self, func):\n",
"\n", "\n",
" assert_equal(func(None), None)\n", " self.assertEqual(func(None), None)\n",
" print('Success: ' + func.__name__ + \" None case.\")\n", " print('Success: ' + func.__name__ + \" None case.\")\n",
" assert_equal(func([]), [])\n", " self.assertEqual(func([]), [])\n",
" print('Success: ' + func.__name__ + \" Empty case.\")\n", " print('Success: ' + func.__name__ + \" Empty case.\")\n",
" assert_equal(func([1]), [1])\n", " self.assertEqual(func([1]), [1])\n",
" print('Success: ' + func.__name__ + \" Single element case.\")\n", " print('Success: ' + func.__name__ + \" Single element case.\")\n",
" assert_equal(func([1, 2, 1, 3, 2]), [1, 1, 2, 2, 3])\n", " self.assertEqual(func([1, 2, 1, 3, 2]), [1, 1, 2, 2, 3])\n",
" assert_equal(func(['a', 'b', 'a']), ['a', 'a', 'b'])\n", " self.assertEqual(func(['a', 'b', 'a']), ['a', 'a', 'b'])\n",
" assert_equal(func([1, 1, 2, 3, 4, 5, 2, 1]), [1, 1, 1, 2, 2, 3, 4, 5])\n", " self.assertEqual(func([1, 1, 2, 3, 4, 5, 2, 1]), [1, 1, 1, 2, 2, 3, 4, 5])\n",
" assert_equal(func([1, 2, 3, 4, 3, 4]), [1, 2, 3, 3, 4, 4])\n", " self.assertEqual(func([1, 2, 3, 4, 3, 4]), [1, 2, 3, 3, 4, 4])\n",
" print('Success: ' + func.__name__)\n", " print('Success: ' + func.__name__)\n",
"\n", "\n",
"\n", "\n",
@ -213,10 +207,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 4,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -240,23 +232,23 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 2", "display_name": "Python 3",
"language": "python", "language": "python",
"name": "python2" "name": "python3"
}, },
"language_info": { "language_info": {
"codemirror_mode": { "codemirror_mode": {
"name": "ipython", "name": "ipython",
"version": 2 "version": 3
}, },
"file_extension": ".py", "file_extension": ".py",
"mimetype": "text/x-python", "mimetype": "text/x-python",
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython2", "pygments_lexer": "ipython3",
"version": "2.7.6" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@ -1,19 +1,19 @@
from nose.tools import assert_equal import unittest
class TestGroupOrdered(object): class TestGroupOrdered(unittest.TestCase):
def test_group_ordered(self, func): def test_group_ordered(self, func):
assert_equal(func(None), None) self.assertEqual(func(None), None)
print('Success: ' + func.__name__ + " None case.") print('Success: ' + func.__name__ + " None case.")
assert_equal(func([]), []) self.assertEqual(func([]), [])
print('Success: ' + func.__name__ + " Empty case.") print('Success: ' + func.__name__ + " Empty case.")
assert_equal(func([1]), [1]) self.assertEqual(func([1]), [1])
print('Success: ' + func.__name__ + " Single element case.") print('Success: ' + func.__name__ + " Single element case.")
assert_equal(func([1, 2, 1, 3, 2]), [1, 1, 2, 2, 3]) self.assertEqual(func([1, 2, 1, 3, 2]), [1, 1, 2, 2, 3])
assert_equal(func(['a', 'b', 'a']), ['a', 'a', 'b']) self.assertEqual(func(['a', 'b', 'a']), ['a', 'a', 'b'])
assert_equal(func([1, 1, 2, 3, 4, 5, 2, 1]), [1, 1, 1, 2, 2, 3, 4, 5]) self.assertEqual(func([1, 1, 2, 3, 4, 5, 2, 1]), [1, 1, 1, 2, 2, 3, 4, 5])
assert_equal(func([1, 2, 3, 4, 3, 4]), [1, 2, 3, 3, 4, 4]) self.assertEqual(func([1, 2, 3, 4, 3, 4]), [1, 2, 3, 3, 4, 4])
print('Success: ' + func.__name__) print('Success: ' + func.__name__)