Fix #13, PEP8-ify notebooks.

This commit is contained in:
Donne Martin
2015-07-11 15:34:52 -04:00
parent 374d67ff30
commit 04083b2011
25 changed files with 210 additions and 173 deletions

View File

@@ -34,7 +34,6 @@
"source": [
"## Constraints\n",
"\n",
"* Is this a singly linked list?\n",
" * Yes\n",
"* Can we assume we are always passed a circular linked list?\n",
@@ -93,7 +92,7 @@
"outputs": [],
"source": [
"class MyLinkedList(LinkedList):\n",
" \n",
"\n",
" def find_loop_start(self):\n",
" # TODO: Implement me\n",
" pass"
@@ -128,25 +127,25 @@
"\n",
"\n",
"class TestFindLoopStart(object):\n",
" \n",
"\n",
" def test_find_loop_start(self):\n",
" print('Test: Empty list')\n",
" linked_list = MyLinkedList()\n",
" assert_equal(linked_list.find_loop_start(), None)\n",
" \n",
"\n",
" print('Test: Not a circular linked list: One element')\n",
" head = Node(1)\n",
" linked_list = MyLinkedList(head)\n",
" assert_equal(linked_list.find_loop_start(), None)\n",
" \n",
"\n",
" print('Test: Not a circular linked list: Two elements')\n",
" linked_list.append(2)\n",
" assert_equal(linked_list.find_loop_start(), None)\n",
" \n",
"\n",
" print('Test: Not a circular linked list: Three or more elements')\n",
" linked_list.append(3)\n",
" assert_equal(linked_list.find_loop_start(), None)\n",
" \n",
"\n",
" print('Test: General case: Circular linked list')\n",
" node10 = Node(10)\n",
" node9 = Node(9, node10)\n",
@@ -162,13 +161,15 @@
" node10.next = node3\n",
" linked_list = MyLinkedList(node0)\n",
" assert_equal(linked_list.find_loop_start(), 3)\n",
" \n",
"\n",
" print('Success: test_find_loop_start')\n",
"\n",
"\n",
"def main():\n",
" test = TestFindLoopStart()\n",
" test.test_find_loop_start()\n",
" \n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]

View File

@@ -33,7 +33,6 @@
"source": [
"## Constraints\n",
"\n",
"* Is this a singly linked list?\n",
" * Yes\n",
"* Can we assume we are always passed a circular linked list?\n",
@@ -101,7 +100,7 @@
"outputs": [],
"source": [
"class MyLinkedList(LinkedList):\n",
" \n",
"\n",
" def find_loop_start(self):\n",
" if self.head is None or self.head.next is None:\n",
" return\n",
@@ -109,7 +108,7 @@
" j = self.head\n",
" i = i.next\n",
" j = j.next.next\n",
" \n",
"\n",
" # Increment i and j until they meet\n",
" # j is incremented twice as fast as i\n",
" while j != i:\n",
@@ -117,11 +116,11 @@
" if j is None or j.next is None:\n",
" return\n",
" j = j.next.next\n",
" \n",
"\n",
" # When i and j meet, move j to the head\n",
" j = self.head\n",
" \n",
" # Increment i and j one node at a time until \n",
"\n",
" # Increment i and j one node at a time until\n",
" # they meet, which is the start of the loop\n",
" while j != i:\n",
" i = i.next\n",
@@ -157,25 +156,25 @@
"\n",
"\n",
"class TestFindLoopStart(object):\n",
" \n",
"\n",
" def test_find_loop_start(self):\n",
" print('Test: Empty list')\n",
" linked_list = MyLinkedList()\n",
" assert_equal(linked_list.find_loop_start(), None)\n",
" \n",
"\n",
" print('Test: Not a circular linked list: One element')\n",
" head = Node(1)\n",
" linked_list = MyLinkedList(head)\n",
" assert_equal(linked_list.find_loop_start(), None)\n",
" \n",
"\n",
" print('Test: Not a circular linked list: Two elements')\n",
" linked_list.append(2)\n",
" assert_equal(linked_list.find_loop_start(), None)\n",
" \n",
"\n",
" print('Test: Not a circular linked list: Three or more elements')\n",
" linked_list.append(3)\n",
" assert_equal(linked_list.find_loop_start(), None)\n",
" \n",
"\n",
" print('Test: General case: Circular linked list')\n",
" node10 = Node(10)\n",
" node9 = Node(9, node10)\n",
@@ -191,13 +190,15 @@
" node10.next = node3\n",
" linked_list = MyLinkedList(node0)\n",
" assert_equal(linked_list.find_loop_start(), 3)\n",
" \n",
"\n",
" print('Success: test_find_loop_start')\n",
"\n",
"\n",
"def main():\n",
" test = TestFindLoopStart()\n",
" test.test_find_loop_start()\n",
" \n",
"\n",
"\n",
"if __name__ == '__main__':\n",
" main()"
]

View File

@@ -2,25 +2,25 @@ from nose.tools import assert_equal
class TestFindLoopStart(object):
def test_find_loop_start(self):
print('Test: Empty list')
linked_list = MyLinkedList()
assert_equal(linked_list.find_loop_start(), None)
print('Test: Not a circular linked list: One element')
head = Node(1)
linked_list = MyLinkedList(head)
assert_equal(linked_list.find_loop_start(), None)
print('Test: Not a circular linked list: Two elements')
linked_list.append(2)
assert_equal(linked_list.find_loop_start(), None)
print('Test: Not a circular linked list: Three or more elements')
linked_list.append(3)
assert_equal(linked_list.find_loop_start(), None)
print('Test: General case: Circular linked list')
node10 = Node(10)
node9 = Node(9, node10)
@@ -36,12 +36,14 @@ class TestFindLoopStart(object):
node10.next = node3
linked_list = MyLinkedList(node0)
assert_equal(linked_list.find_loop_start(), 3)
print('Success: test_find_loop_start')
def main():
test = TestFindLoopStart()
test.test_find_loop_start()
if __name__ == '__main__':
main()