Skip to content

Commit

Permalink
#273: Remove nose dependency for staging/
Browse files Browse the repository at this point in the history
  • Loading branch information
donnemartin committed Jul 16, 2020
1 parent 46d3939 commit ec8aa18
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 189 deletions.
30 changes: 17 additions & 13 deletions staging/arrays_strings/reverse_words/reverse_words_challenge.ipynb
Expand Up @@ -100,20 +100,24 @@
"metadata": {},
"outputs": [],
"source": [
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class UnitTest(unittest.TestCase):\n",
"\n",
"class UnitTest (object):\n",
" def testReverseWords(self, func):\n",
" assert_equal(func('the sun is hot'), 'eht nus si toh')\n",
" assert_equal(func(''), None)\n",
" assert_equal(func('123 456 789'), '321 654 987')\n",
" assert_equal(func('magic'), 'cigam')\n",
" self.assertEqual(func('the sun is hot'), 'eht nus si toh')\n",
" self.assertEqual(func(''), None)\n",
" self.assertEqual(func('123 456 789'), '321 654 987')\n",
" self.assertEqual(func('magic'), 'cigam')\n",
" print('Success: reverse_words')\n",
" \n",
"\n",
"\n",
"def main():\n",
" test = UnitTest()\n",
" test.testReverseWords(reverse_words)\n",
"\n",
"\n",
"if __name__==\"__main__\":\n",
" main()"
]
Expand All @@ -129,23 +133,23 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2.0
"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.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}
54 changes: 26 additions & 28 deletions staging/arrays_strings/reverse_words/reverse_words_solution.ipynb
Expand Up @@ -66,29 +66,25 @@
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"def reverse_words(S):\n",
" if len(S) is 0:\n",
" return None\n",
" \n",
"\n",
" words = S.split()\n",
" for i in range (len(words)):\n",
" words[i] = words[i][::-1]\n",
" \n",
"\n",
" return \" \".join(words)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -100,30 +96,32 @@
],
"source": [
"%%writefile reverse_words_solution.py\n",
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"\n",
"class TestReverseWords(unittest.TestCase):\n",
"\n",
"class UnitTest (object):\n",
" def testReverseWords(self, func):\n",
" assert_equal(func('the sun is hot'), 'eht nus si toh')\n",
" assert_equal(func(''), None)\n",
" assert_equal(func('123 456 789'), '321 654 987')\n",
" assert_equal(func('magic'), 'cigam')\n",
" self.assertEqual(func('the sun is hot'), 'eht nus si toh')\n",
" self.assertEqual(func(''), None)\n",
" self.assertEqual(func('123 456 789'), '321 654 987')\n",
" self.assertEqual(func('magic'), 'cigam')\n",
" print('Success: reverse_words')\n",
" \n",
"\n",
"\n",
"def main():\n",
" test = UnitTest()\n",
" test = TestReverseWords()\n",
" test.testReverseWords(reverse_words)\n",
"\n",
"\n",
"if __name__==\"__main__\":\n",
" main()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -140,23 +138,23 @@
],
"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.6"
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}
22 changes: 13 additions & 9 deletions staging/arrays_strings/reverse_words/reverse_words_solution.py
@@ -1,16 +1,20 @@
from nose.tools import assert_equal
import unittest


class TestReverseWords(unittest.TestCase):

class UnitTest (object):
def testReverseWords(self, func):
assert_equal(func('the sun is hot'), 'eht nus si toh')
assert_equal(func(''), None)
assert_equal(func('123 456 789'), '321 654 987')
assert_equal(func('magic'), 'cigam')
self.assertEqual(func('the sun is hot'), 'eht nus si toh')
self.assertEqual(func(''), None)
self.assertEqual(func('123 456 789'), '321 654 987')
self.assertEqual(func('magic'), 'cigam')
print('Success: reverse_words')



def main():
test = UnitTest()
test = TestReverseWords()
test.testReverseWords(reverse_words)


if __name__=="__main__":
main()
main()
2 changes: 1 addition & 1 deletion staging/graphs_trees/binary_tree/binary_search_tree.py
Expand Up @@ -152,4 +152,4 @@ def PreOrder (node):
return preOrder

def treeIsEmpty (self):
return self.root is None
return self.root is None
48 changes: 21 additions & 27 deletions staging/graphs_trees/binary_tree/binary_tree_challenge.ipynb
Expand Up @@ -93,9 +93,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"class Node (object):\n",
Expand All @@ -111,9 +109,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"class BinaryTree (object):\n",
Expand Down Expand Up @@ -163,15 +159,13 @@
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from nose.tools import assert_equal\n",
"import unittest\n",
"\n",
"class TestBinaryTree(object):\n",
"class TestBinaryTree(unittest.TestCase):\n",
"\n",
"\tdef test_insert_traversals (self):\n",
"\t\tmyTree = BinaryTree()\n",
Expand All @@ -182,22 +176,22 @@
"\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\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\tassert_equal(myTree2.printInOrder(), expectVal)\n",
"\t\tself.assertEqual(myTree2.printInOrder(), expectVal)\n",
"\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\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\tassert_equal(myTree2.printPostOrder(), expectVal)\n",
"\t\tself.assertEqual(myTree2.printPostOrder(), expectVal)\n",
"\n",
"\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\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\tassert_equal(myTree2.printPreOrder(), expectVal)\n",
"\t\tself.assertEqual(myTree2.printPreOrder(), expectVal)\n",
"\n",
"\n",
"\t\tprint(\"Success: test_insert_traversals\")\n",
Expand All @@ -209,16 +203,16 @@
"\t\tmyTree.insert(21)\n",
"\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\tassert_equal(myTree.maxNode(), 32)\n",
"\t\tself.assertEqual(myTree.maxNode(), 32)\n",
"\n",
"\t\tprint(\"Test: min node\")\n",
"\t\tassert_equal(myTree.minNode(), 1)\n",
"\t\tself.assertEqual(myTree.minNode(), 1)\n",
"\n",
"\t\tprint(\"Test: min node inserting negative number\")\n",
"\t\tmyTree.insert(-10)\n",
"\t\tassert_equal(myTree.minNode(), -10)\n",
"\t\tself.assertEqual(myTree.minNode(), -10)\n",
"\n",
"\t\tprint(\"Success: test_max_min_nodes\")\n",
"\n",
Expand All @@ -228,15 +222,15 @@
"\n",
"\t\tprint(\"Test: delete\")\n",
"\t\tmyTree.delete(5)\n",
"\t\tassert_equal(myTree.treeIsEmpty(), True)\n",
"\t\tself.assertEqual(myTree.treeIsEmpty(), True)\n",
"\t\t\n",
"\t\tprint(\"Test: more complex deletions\")\n",
"\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",
"\t\tself.assertEqual(myTree.root.rightChild.data, 3)\n",
" \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",
"\t\tprint(\"Success: test_delete\")\n",
Expand Down Expand Up @@ -284,9 +278,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

0 comments on commit ec8aa18

Please sign in to comment.