Fix #13, PEP8-ify notebooks.

This commit is contained in:
Donne Martin
2015-07-11 15:39:59 -04:00
parent 4566d1a803
commit 3712839cc9
26 changed files with 139 additions and 92 deletions

View File

@@ -1,11 +1,12 @@
class Node(object):
def __init__(self, data):
self.data = data
self.next = None
class Queue(object):
def __init__(self):
self.first = None
self.last = None
@@ -23,7 +24,7 @@ class Queue(object):
# Empty list
if self.first is None and self.last is None:
return None
# Remove only element from a one element list
elif self.first == self.last:
data = self.first.data

View File

@@ -35,7 +35,6 @@
"source": [
"## Constraints\n",
"\n",
"* If there is one item in the list, do you expect the first and last pointers to both point to it?\n",
" * Yes\n",
"* If there are no items on the list, do you expect the first and last pointers to be None?\n",
@@ -87,13 +86,14 @@
"outputs": [],
"source": [
"class Node(object):\n",
" \n",
"\n",
" def __init__(self, data):\n",
" # TODO: Implement me\n",
" pass\n",
"\n",
"\n",
"class Queue(object):\n",
" \n",
"\n",
" def __init__(self):\n",
" # TODO: Implement me\n",
" pass\n",
@@ -131,7 +131,7 @@
"\n",
"\n",
"class TestQueue(object):\n",
" \n",
"\n",
" # TODO: It would be better if we had unit tests for each\n",
" # method in addition to the following end-to-end test\n",
" def test_end_to_end(self):\n",
@@ -154,13 +154,15 @@
" assert_equal(queue.dequeue(), 2)\n",
" assert_equal(queue.dequeue(), 3)\n",
" assert_equal(queue.dequeue(), 4)\n",
" \n",
"\n",
" print('Success: test_end_to_end')\n",
"\n",
"\n",
"def main():\n",
" test = TestQueue()\n",
" test.test_end_to_end()\n",
" \n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]

View File

@@ -34,7 +34,6 @@
"source": [
"## Constraints\n",
"\n",
"* If there is one item in the list, do you expect the first and last pointers to both point to it?\n",
" * Yes\n",
"* If there are no items on the list, do you expect the first and last pointers to be None?\n",
@@ -118,13 +117,14 @@
"source": [
"%%writefile queue_list.py\n",
"class Node(object):\n",
" \n",
"\n",
" def __init__(self, data):\n",
" self.data = data\n",
" self.next = None\n",
"\n",
"\n",
"class Queue(object):\n",
" \n",
"\n",
" def __init__(self):\n",
" self.first = None\n",
" self.last = None\n",
@@ -142,7 +142,7 @@
" # Empty list\n",
" if self.first is None and self.last is None:\n",
" return None\n",
" \n",
"\n",
" # Remove only element from a one element list\n",
" elif self.first == self.last:\n",
" data = self.first.data\n",
@@ -195,7 +195,7 @@
"\n",
"\n",
"class TestQueue(object):\n",
" \n",
"\n",
" # TODO: It would be better if we had unit tests for each\n",
" # method in addition to the following end-to-end test\n",
" def test_end_to_end(self):\n",
@@ -218,13 +218,15 @@
" assert_equal(queue.dequeue(), 2)\n",
" assert_equal(queue.dequeue(), 3)\n",
" assert_equal(queue.dequeue(), 4)\n",
" \n",
"\n",
" print('Success: test_end_to_end')\n",
"\n",
"\n",
"def main():\n",
" test = TestQueue()\n",
" test.test_end_to_end()\n",
" \n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]

View File

@@ -2,7 +2,7 @@ from nose.tools import assert_equal
class TestQueue(object):
# TODO: It would be better if we had unit tests for each
# method in addition to the following end-to-end test
def test_end_to_end(self):
@@ -25,12 +25,14 @@ class TestQueue(object):
assert_equal(queue.dequeue(), 2)
assert_equal(queue.dequeue(), 3)
assert_equal(queue.dequeue(), 4)
print('Success: test_end_to_end')
def main():
test = TestQueue()
test.test_end_to_end()
if __name__ == '__main__':
main()