Skip to content

Commit ec8aa18

Browse files
committed
#273: Remove nose dependency for staging/
1 parent 46d3939 commit ec8aa18

10 files changed

+170
-189
lines changed

staging/arrays_strings/reverse_words/reverse_words_challenge.ipynb

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,24 @@
100100
"metadata": {},
101101
"outputs": [],
102102
"source": [
103-
"from nose.tools import assert_equal\n",
103+
"import unittest\n",
104+
"\n",
105+
"\n",
106+
"class UnitTest(unittest.TestCase):\n",
104107
"\n",
105-
"class UnitTest (object):\n",
106108
" def testReverseWords(self, func):\n",
107-
" assert_equal(func('the sun is hot'), 'eht nus si toh')\n",
108-
" assert_equal(func(''), None)\n",
109-
" assert_equal(func('123 456 789'), '321 654 987')\n",
110-
" assert_equal(func('magic'), 'cigam')\n",
109+
" self.assertEqual(func('the sun is hot'), 'eht nus si toh')\n",
110+
" self.assertEqual(func(''), None)\n",
111+
" self.assertEqual(func('123 456 789'), '321 654 987')\n",
112+
" self.assertEqual(func('magic'), 'cigam')\n",
111113
" print('Success: reverse_words')\n",
112-
" \n",
114+
"\n",
115+
"\n",
113116
"def main():\n",
114117
" test = UnitTest()\n",
115118
" test.testReverseWords(reverse_words)\n",
116119
"\n",
120+
"\n",
117121
"if __name__==\"__main__\":\n",
118122
" main()"
119123
]
@@ -129,23 +133,23 @@
129133
],
130134
"metadata": {
131135
"kernelspec": {
132-
"display_name": "Python 2",
136+
"display_name": "Python 3",
133137
"language": "python",
134-
"name": "python2"
138+
"name": "python3"
135139
},
136140
"language_info": {
137141
"codemirror_mode": {
138142
"name": "ipython",
139-
"version": 2.0
143+
"version": 3
140144
},
141145
"file_extension": ".py",
142146
"mimetype": "text/x-python",
143147
"name": "python",
144148
"nbconvert_exporter": "python",
145-
"pygments_lexer": "ipython2",
146-
"version": "2.7.10"
149+
"pygments_lexer": "ipython3",
150+
"version": "3.7.2"
147151
}
148152
},
149153
"nbformat": 4,
150-
"nbformat_minor": 0
154+
"nbformat_minor": 1
151155
}

staging/arrays_strings/reverse_words/reverse_words_solution.ipynb

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,25 @@
6666
},
6767
{
6868
"cell_type": "code",
69-
"execution_count": 2,
70-
"metadata": {
71-
"collapsed": false
72-
},
69+
"execution_count": 1,
70+
"metadata": {},
7371
"outputs": [],
7472
"source": [
7573
"def reverse_words(S):\n",
7674
" if len(S) is 0:\n",
7775
" return None\n",
78-
" \n",
76+
"\n",
7977
" words = S.split()\n",
8078
" for i in range (len(words)):\n",
8179
" words[i] = words[i][::-1]\n",
82-
" \n",
80+
"\n",
8381
" return \" \".join(words)"
8482
]
8583
},
8684
{
8785
"cell_type": "code",
88-
"execution_count": 4,
89-
"metadata": {
90-
"collapsed": false
91-
},
86+
"execution_count": 2,
87+
"metadata": {},
9288
"outputs": [
9389
{
9490
"name": "stdout",
@@ -100,30 +96,32 @@
10096
],
10197
"source": [
10298
"%%writefile reverse_words_solution.py\n",
103-
"from nose.tools import assert_equal\n",
99+
"import unittest\n",
100+
"\n",
101+
"\n",
102+
"class TestReverseWords(unittest.TestCase):\n",
104103
"\n",
105-
"class UnitTest (object):\n",
106104
" def testReverseWords(self, func):\n",
107-
" assert_equal(func('the sun is hot'), 'eht nus si toh')\n",
108-
" assert_equal(func(''), None)\n",
109-
" assert_equal(func('123 456 789'), '321 654 987')\n",
110-
" assert_equal(func('magic'), 'cigam')\n",
105+
" self.assertEqual(func('the sun is hot'), 'eht nus si toh')\n",
106+
" self.assertEqual(func(''), None)\n",
107+
" self.assertEqual(func('123 456 789'), '321 654 987')\n",
108+
" self.assertEqual(func('magic'), 'cigam')\n",
111109
" print('Success: reverse_words')\n",
112-
" \n",
110+
"\n",
111+
"\n",
113112
"def main():\n",
114-
" test = UnitTest()\n",
113+
" test = TestReverseWords()\n",
115114
" test.testReverseWords(reverse_words)\n",
116115
"\n",
116+
"\n",
117117
"if __name__==\"__main__\":\n",
118118
" main()"
119119
]
120120
},
121121
{
122122
"cell_type": "code",
123-
"execution_count": 5,
124-
"metadata": {
125-
"collapsed": false
126-
},
123+
"execution_count": 3,
124+
"metadata": {},
127125
"outputs": [
128126
{
129127
"name": "stdout",
@@ -140,23 +138,23 @@
140138
],
141139
"metadata": {
142140
"kernelspec": {
143-
"display_name": "Python 2",
141+
"display_name": "Python 3",
144142
"language": "python",
145-
"name": "python2"
143+
"name": "python3"
146144
},
147145
"language_info": {
148146
"codemirror_mode": {
149147
"name": "ipython",
150-
"version": 2
148+
"version": 3
151149
},
152150
"file_extension": ".py",
153151
"mimetype": "text/x-python",
154152
"name": "python",
155153
"nbconvert_exporter": "python",
156-
"pygments_lexer": "ipython2",
157-
"version": "2.7.6"
154+
"pygments_lexer": "ipython3",
155+
"version": "3.7.2"
158156
}
159157
},
160158
"nbformat": 4,
161-
"nbformat_minor": 0
159+
"nbformat_minor": 1
162160
}
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
from nose.tools import assert_equal
1+
import unittest
2+
3+
4+
class TestReverseWords(unittest.TestCase):
25

3-
class UnitTest (object):
46
def testReverseWords(self, func):
5-
assert_equal(func('the sun is hot'), 'eht nus si toh')
6-
assert_equal(func(''), None)
7-
assert_equal(func('123 456 789'), '321 654 987')
8-
assert_equal(func('magic'), 'cigam')
7+
self.assertEqual(func('the sun is hot'), 'eht nus si toh')
8+
self.assertEqual(func(''), None)
9+
self.assertEqual(func('123 456 789'), '321 654 987')
10+
self.assertEqual(func('magic'), 'cigam')
911
print('Success: reverse_words')
10-
12+
13+
1114
def main():
12-
test = UnitTest()
15+
test = TestReverseWords()
1316
test.testReverseWords(reverse_words)
1417

18+
1519
if __name__=="__main__":
16-
main()
20+
main()

staging/graphs_trees/binary_tree/binary_search_tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,4 @@ def PreOrder (node):
152152
return preOrder
153153

154154
def treeIsEmpty (self):
155-
return self.root is None
155+
return self.root is None

staging/graphs_trees/binary_tree/binary_tree_challenge.ipynb

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@
9393
{
9494
"cell_type": "code",
9595
"execution_count": null,
96-
"metadata": {
97-
"collapsed": true
98-
},
96+
"metadata": {},
9997
"outputs": [],
10098
"source": [
10199
"class Node (object):\n",
@@ -111,9 +109,7 @@
111109
{
112110
"cell_type": "code",
113111
"execution_count": null,
114-
"metadata": {
115-
"collapsed": true
116-
},
112+
"metadata": {},
117113
"outputs": [],
118114
"source": [
119115
"class BinaryTree (object):\n",
@@ -163,15 +159,13 @@
163159
},
164160
{
165161
"cell_type": "code",
166-
"execution_count": 6,
167-
"metadata": {
168-
"collapsed": false
169-
},
162+
"execution_count": null,
163+
"metadata": {},
170164
"outputs": [],
171165
"source": [
172-
"from nose.tools import assert_equal\n",
166+
"import unittest\n",
173167
"\n",
174-
"class TestBinaryTree(object):\n",
168+
"class TestBinaryTree(unittest.TestCase):\n",
175169
"\n",
176170
"\tdef test_insert_traversals (self):\n",
177171
"\t\tmyTree = BinaryTree()\n",
@@ -182,22 +176,22 @@
182176
"\n",
183177
"\t\tprint(\"Test: insert checking with in order traversal\")\n",
184178
"\t\texpectVal = [7, 10, 25, 30, 38, 40, 50, 60, 70, 80]\n",
185-
"\t\tassert_equal(myTree.printInOrder(), expectVal)\n",
179+
"\t\tself.assertEqual(myTree.printInOrder(), expectVal)\n",
186180
"\t\texpectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]\n",
187-
"\t\tassert_equal(myTree2.printInOrder(), expectVal)\n",
181+
"\t\tself.assertEqual(myTree2.printInOrder(), expectVal)\n",
188182
"\n",
189183
"\t\tprint(\"Test: insert checking with post order traversal\")\n",
190184
"\t\texpectVal = [7, 25, 10, 38, 40, 30, 60, 80, 70, 50]\n",
191-
"\t\tassert_equal(myTree.printPostOrder(), expectVal)\n",
185+
"\t\tself.assertEqual(myTree.printPostOrder(), expectVal)\n",
192186
"\t\texpectVal = [91, 81, 71, 61, 51, 41, 31, 21, 11, 1]\n",
193-
"\t\tassert_equal(myTree2.printPostOrder(), expectVal)\n",
187+
"\t\tself.assertEqual(myTree2.printPostOrder(), expectVal)\n",
194188
"\n",
195189
"\n",
196190
"\t\tprint(\"Test: insert checking with pre order traversal\")\n",
197191
"\t\texpectVal = [50, 30, 10, 7, 25, 40, 38, 70, 60, 80]\n",
198-
"\t\tassert_equal(myTree.printPreOrder(), expectVal)\n",
192+
"\t\tself.assertEqual(myTree.printPreOrder(), expectVal)\n",
199193
"\t\texpectVal = [1, 11, 21, 31, 41, 51, 61, 71, 81, 91]\n",
200-
"\t\tassert_equal(myTree2.printPreOrder(), expectVal)\n",
194+
"\t\tself.assertEqual(myTree2.printPreOrder(), expectVal)\n",
201195
"\n",
202196
"\n",
203197
"\t\tprint(\"Success: test_insert_traversals\")\n",
@@ -209,16 +203,16 @@
209203
"\t\tmyTree.insert(21)\n",
210204
"\n",
211205
"\t\tprint(\"Test: max node\")\n",
212-
"\t\tassert_equal(myTree.maxNode(), 21)\n",
206+
"\t\tself.assertEqual(myTree.maxNode(), 21)\n",
213207
"\t\tmyTree.insert(32)\n",
214-
"\t\tassert_equal(myTree.maxNode(), 32)\n",
208+
"\t\tself.assertEqual(myTree.maxNode(), 32)\n",
215209
"\n",
216210
"\t\tprint(\"Test: min node\")\n",
217-
"\t\tassert_equal(myTree.minNode(), 1)\n",
211+
"\t\tself.assertEqual(myTree.minNode(), 1)\n",
218212
"\n",
219213
"\t\tprint(\"Test: min node inserting negative number\")\n",
220214
"\t\tmyTree.insert(-10)\n",
221-
"\t\tassert_equal(myTree.minNode(), -10)\n",
215+
"\t\tself.assertEqual(myTree.minNode(), -10)\n",
222216
"\n",
223217
"\t\tprint(\"Success: test_max_min_nodes\")\n",
224218
"\n",
@@ -228,15 +222,15 @@
228222
"\n",
229223
"\t\tprint(\"Test: delete\")\n",
230224
"\t\tmyTree.delete(5)\n",
231-
"\t\tassert_equal(myTree.treeIsEmpty(), True)\n",
225+
"\t\tself.assertEqual(myTree.treeIsEmpty(), True)\n",
232226
"\t\t\n",
233227
"\t\tprint(\"Test: more complex deletions\")\n",
234228
"\t\t[myTree.insert(x) for x in range(1, 5)]\n",
235229
"\t\tmyTree.delete(2)\n",
236-
"\t\tassert_equal(myTree.root.rightChild.data, 3)\n",
230+
"\t\tself.assertEqual(myTree.root.rightChild.data, 3)\n",
237231
" \n",
238232
"\t\tprint(\"Test: delete invalid value\")\n",
239-
"\t\tassert_equal(myTree.delete(100), False)\n",
233+
"\t\tself.assertEqual(myTree.delete(100), False)\n",
240234
"\n",
241235
"\n",
242236
"\t\tprint(\"Success: test_delete\")\n",
@@ -284,9 +278,9 @@
284278
"name": "python",
285279
"nbconvert_exporter": "python",
286280
"pygments_lexer": "ipython3",
287-
"version": "3.4.3"
281+
"version": "3.7.2"
288282
}
289283
},
290284
"nbformat": 4,
291-
"nbformat_minor": 0
285+
"nbformat_minor": 1
292286
}

0 commit comments

Comments
 (0)