From 3712839cc964ab1860bc4cd116af0e20091255d3 Mon Sep 17 00:00:00 2001 From: Donne Martin Date: Sat, 11 Jul 2015 15:39:59 -0400 Subject: [PATCH] Fix #13, PEP8-ify notebooks. --- stacks_queues/hanoi/hanoi_challenge.ipynb | 7 ++++--- stacks_queues/hanoi/hanoi_solution.ipynb | 7 ++++--- stacks_queues/hanoi/test_hanoi.py | 2 ++ stacks_queues/n_stacks/n_stacks_challenge.ipynb | 11 ++++++----- stacks_queues/n_stacks/n_stacks_solution.ipynb | 13 +++++++------ stacks_queues/n_stacks/test_n_stacks.py | 2 ++ .../queue_from_stacks_challenge.ipynb | 11 ++++++----- .../queue_from_stacks_solution.ipynb | 11 ++++++----- .../queue_from_stacks/test_queue_from_stacks.py | 8 +++++--- stacks_queues/queue_list/queue_list.py | 7 ++++--- .../queue_list/queue_list_challenge.ipynb | 14 ++++++++------ .../queue_list/queue_list_solution.ipynb | 16 +++++++++------- stacks_queues/queue_list/test_queue_list.py | 8 +++++--- .../set_of_stacks/set_of_stacks_challenge.ipynb | 14 ++++++++------ .../set_of_stacks/set_of_stacks_solution.ipynb | 14 ++++++++------ .../set_of_stacks/test_set_of_stacks.py | 8 +++++--- .../sort_stack/sort_stack_challenge.ipynb | 9 +++++---- .../sort_stack/sort_stack_solution.ipynb | 9 +++++---- stacks_queues/sort_stack/test_sort_stack.py | 2 ++ stacks_queues/stack/stack.py | 5 +++-- stacks_queues/stack/stack_challenge.ipynb | 14 ++++++++------ stacks_queues/stack/stack_solution.ipynb | 14 ++++++++------ stacks_queues/stack/test_stack.py | 8 +++++--- .../stack_min/stack_min_challenge.ipynb | 6 +++++- stacks_queues/stack_min/stack_min_solution.ipynb | 6 +++++- stacks_queues/stack_min/test_stack_min.py | 5 ++++- 26 files changed, 139 insertions(+), 92 deletions(-) diff --git a/stacks_queues/hanoi/hanoi_challenge.ipynb b/stacks_queues/hanoi/hanoi_challenge.ipynb index 51da878..e9c6d56 100644 --- a/stacks_queues/hanoi/hanoi_challenge.ipynb +++ b/stacks_queues/hanoi/hanoi_challenge.ipynb @@ -34,7 +34,6 @@ "source": [ "## Constraints\n", "\n", - "* Can we assume we already have a stack class that can be used for this problem?\n", " * Yes" ] @@ -116,7 +115,7 @@ "\n", "\n", "class TestHanoi(object):\n", - " \n", + "\n", " def test_hanoi(self):\n", " num_disks = 3\n", " src = Stack()\n", @@ -144,10 +143,12 @@ "\n", " print('Success: test_hanoi')\n", "\n", + "\n", "def main():\n", " test = TestHanoi()\n", " test.test_hanoi()\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/stacks_queues/hanoi/hanoi_solution.ipynb b/stacks_queues/hanoi/hanoi_solution.ipynb index 884cb22..96ffcbb 100644 --- a/stacks_queues/hanoi/hanoi_solution.ipynb +++ b/stacks_queues/hanoi/hanoi_solution.ipynb @@ -33,7 +33,6 @@ "source": [ "## Constraints\n", "\n", - "* Can we assume we already have a stack class that can be used for this problem?\n", " * Yes" ] @@ -133,7 +132,7 @@ "\n", "\n", "class TestHanoi(object):\n", - " \n", + "\n", " def test_hanoi(self):\n", " num_disks = 3\n", " src = Stack()\n", @@ -161,10 +160,12 @@ "\n", " print('Success: test_hanoi')\n", "\n", + "\n", "def main():\n", " test = TestHanoi()\n", " test.test_hanoi()\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/stacks_queues/hanoi/test_hanoi.py b/stacks_queues/hanoi/test_hanoi.py index 5a2606d..7fa113d 100644 --- a/stacks_queues/hanoi/test_hanoi.py +++ b/stacks_queues/hanoi/test_hanoi.py @@ -30,9 +30,11 @@ class TestHanoi(object): print('Success: test_hanoi') + def main(): test = TestHanoi() test.test_hanoi() + if __name__ == '__main__': main() \ No newline at end of file diff --git a/stacks_queues/n_stacks/n_stacks_challenge.ipynb b/stacks_queues/n_stacks/n_stacks_challenge.ipynb index 070a88c..2b1ca82 100644 --- a/stacks_queues/n_stacks/n_stacks_challenge.ipynb +++ b/stacks_queues/n_stacks/n_stacks_challenge.ipynb @@ -34,7 +34,6 @@ "source": [ "## Constraints\n", "\n", - "* Are the stacks and array a fixed size?\n", " * Yes" ] @@ -77,7 +76,7 @@ "outputs": [], "source": [ "class Stacks(object):\n", - " \n", + "\n", " def __init__(self, num_stacks, stack_size):\n", " # TODO: Implement me\n", " pass\n", @@ -120,7 +119,7 @@ "\n", "\n", "class TestStacks(object):\n", - " \n", + "\n", " @raises(Exception)\n", " def test_pop_on_empty(self, num_stacks, stack_size):\n", " print('Test: Pop on empty stack')\n", @@ -151,14 +150,16 @@ "\n", " print('Success: test_stacks\\n')\n", "\n", + "\n", "def main():\n", " num_stacks = 3\n", - " stack_size = 100 \n", + " stack_size = 100\n", " test = TestStacks()\n", " test.test_pop_on_empty(num_stacks, stack_size)\n", " test.test_push_on_full(num_stacks, stack_size)\n", " test.test_stacks(num_stacks, stack_size)\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/stacks_queues/n_stacks/n_stacks_solution.ipynb b/stacks_queues/n_stacks/n_stacks_solution.ipynb index aa1efea..c5cd113 100644 --- a/stacks_queues/n_stacks/n_stacks_solution.ipynb +++ b/stacks_queues/n_stacks/n_stacks_solution.ipynb @@ -33,7 +33,6 @@ "source": [ "## Constraints\n", "\n", - "* Are the stacks and array a fixed size?\n", " * Yes" ] @@ -107,7 +106,7 @@ "outputs": [], "source": [ "class Stacks(object):\n", - " \n", + "\n", " def __init__(self, num_stacks, stack_size):\n", " self.num_stacks = num_stacks\n", " self.stack_size = stack_size\n", @@ -129,7 +128,7 @@ " if self.stack_pointers[stack_index] == -1:\n", " raise Exception('Stack is empty')\n", " else:\n", - " array_index = self.abs_index(stack_index) \n", + " array_index = self.abs_index(stack_index)\n", " data = self.stack_array[array_index]\n", " self.stack_array[array_index] = None\n", " self.stack_pointers[stack_index] -= 1\n", @@ -166,7 +165,7 @@ "\n", "\n", "class TestStacks(object):\n", - " \n", + "\n", " @raises(Exception)\n", " def test_pop_on_empty(self, num_stacks, stack_size):\n", " print('Test: Pop on empty stack')\n", @@ -197,14 +196,16 @@ "\n", " print('Success: test_stacks\\n')\n", "\n", + "\n", "def main():\n", " num_stacks = 3\n", - " stack_size = 100 \n", + " stack_size = 100\n", " test = TestStacks()\n", " test.test_pop_on_empty(num_stacks, stack_size)\n", " test.test_push_on_full(num_stacks, stack_size)\n", " test.test_stacks(num_stacks, stack_size)\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/stacks_queues/n_stacks/test_n_stacks.py b/stacks_queues/n_stacks/test_n_stacks.py index 5878d28..33cb5b6 100644 --- a/stacks_queues/n_stacks/test_n_stacks.py +++ b/stacks_queues/n_stacks/test_n_stacks.py @@ -34,6 +34,7 @@ class TestStacks(object): print('Success: test_stacks\n') + def main(): num_stacks = 3 stack_size = 100 @@ -42,5 +43,6 @@ def main(): test.test_push_on_full(num_stacks, stack_size) test.test_stacks(num_stacks, stack_size) + if __name__ == '__main__': main() \ No newline at end of file diff --git a/stacks_queues/queue_from_stacks/queue_from_stacks_challenge.ipynb b/stacks_queues/queue_from_stacks/queue_from_stacks_challenge.ipynb index 1819fac..c1ebb7a 100644 --- a/stacks_queues/queue_from_stacks/queue_from_stacks_challenge.ipynb +++ b/stacks_queues/queue_from_stacks/queue_from_stacks_challenge.ipynb @@ -34,7 +34,6 @@ "source": [ "## Constraints\n", "\n", - "* Do you expect the methods to be enqueue and dequeue?\n", " * Yes\n", "* Can we assume we already have a stack class that can be used for this problem?\n", @@ -92,7 +91,7 @@ "outputs": [], "source": [ "class QueueFromStacks(object):\n", - " \n", + "\n", " def __init__(self):\n", " # TODO: Implement me\n", " pass\n", @@ -131,7 +130,7 @@ "\n", "\n", "class TestQueueFromStacks(object):\n", - " \n", + "\n", " def test_queue_from_stacks(self):\n", " print('Test: Dequeue on empty stack')\n", " queue = QueueFromStacks()\n", @@ -141,7 +140,7 @@ " print('Test: Enqueue on non-empty stack')\n", " print('Test: Multiple enqueue in a row')\n", " num_items = 3\n", - " for i in range (0, num_items):\n", + " for i in range(0, num_items):\n", " queue.enqueue(i)\n", "\n", " print('Test: Dequeue on non-empty stack')\n", @@ -158,10 +157,12 @@ "\n", " print('Success: test_queue_from_stacks')\n", "\n", + "\n", "def main():\n", " test = TestQueueFromStacks()\n", " test.test_queue_from_stacks()\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/stacks_queues/queue_from_stacks/queue_from_stacks_solution.ipynb b/stacks_queues/queue_from_stacks/queue_from_stacks_solution.ipynb index 149bd5e..c6dbebf 100644 --- a/stacks_queues/queue_from_stacks/queue_from_stacks_solution.ipynb +++ b/stacks_queues/queue_from_stacks/queue_from_stacks_solution.ipynb @@ -33,7 +33,6 @@ "source": [ "## Constraints\n", "\n", - "* Do you expect the methods to be enqueue and dequeue?\n", " * Yes\n", "* Can we assume we already have a stack class that can be used for this problem?\n", @@ -121,7 +120,7 @@ "outputs": [], "source": [ "class QueueFromStacks(object):\n", - " \n", + "\n", " def __init__(self):\n", " self.left_stack = Stack()\n", " self.right_stack = Stack()\n", @@ -170,7 +169,7 @@ "\n", "\n", "class TestQueueFromStacks(object):\n", - " \n", + "\n", " def test_queue_from_stacks(self):\n", " print('Test: Dequeue on empty stack')\n", " queue = QueueFromStacks()\n", @@ -180,7 +179,7 @@ " print('Test: Enqueue on non-empty stack')\n", " print('Test: Multiple enqueue in a row')\n", " num_items = 3\n", - " for i in range (0, num_items):\n", + " for i in range(0, num_items):\n", " queue.enqueue(i)\n", "\n", " print('Test: Dequeue on non-empty stack')\n", @@ -197,10 +196,12 @@ "\n", " print('Success: test_queue_from_stacks')\n", "\n", + "\n", "def main():\n", " test = TestQueueFromStacks()\n", " test.test_queue_from_stacks()\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/stacks_queues/queue_from_stacks/test_queue_from_stacks.py b/stacks_queues/queue_from_stacks/test_queue_from_stacks.py index 15f5f9d..d0f3c5b 100644 --- a/stacks_queues/queue_from_stacks/test_queue_from_stacks.py +++ b/stacks_queues/queue_from_stacks/test_queue_from_stacks.py @@ -2,7 +2,7 @@ from nose.tools import assert_equal class TestQueueFromStacks(object): - + def test_queue_from_stacks(self): print('Test: Dequeue on empty stack') queue = QueueFromStacks() @@ -12,7 +12,7 @@ class TestQueueFromStacks(object): print('Test: Enqueue on non-empty stack') print('Test: Multiple enqueue in a row') num_items = 3 - for i in range (0, num_items): + for i in range(0, num_items): queue.enqueue(i) print('Test: Dequeue on non-empty stack') @@ -29,9 +29,11 @@ class TestQueueFromStacks(object): print('Success: test_queue_from_stacks') + def main(): test = TestQueueFromStacks() test.test_queue_from_stacks() - + + if __name__ == '__main__': main() \ No newline at end of file diff --git a/stacks_queues/queue_list/queue_list.py b/stacks_queues/queue_list/queue_list.py index 7df7bfb..878f087 100644 --- a/stacks_queues/queue_list/queue_list.py +++ b/stacks_queues/queue_list/queue_list.py @@ -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 diff --git a/stacks_queues/queue_list/queue_list_challenge.ipynb b/stacks_queues/queue_list/queue_list_challenge.ipynb index 04024be..a06ab45 100644 --- a/stacks_queues/queue_list/queue_list_challenge.ipynb +++ b/stacks_queues/queue_list/queue_list_challenge.ipynb @@ -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()" ] diff --git a/stacks_queues/queue_list/queue_list_solution.ipynb b/stacks_queues/queue_list/queue_list_solution.ipynb index 00a46c1..07c0d9a 100644 --- a/stacks_queues/queue_list/queue_list_solution.ipynb +++ b/stacks_queues/queue_list/queue_list_solution.ipynb @@ -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()" ] diff --git a/stacks_queues/queue_list/test_queue_list.py b/stacks_queues/queue_list/test_queue_list.py index e8429ac..589fdee 100644 --- a/stacks_queues/queue_list/test_queue_list.py +++ b/stacks_queues/queue_list/test_queue_list.py @@ -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() \ No newline at end of file diff --git a/stacks_queues/set_of_stacks/set_of_stacks_challenge.ipynb b/stacks_queues/set_of_stacks/set_of_stacks_challenge.ipynb index d5b8abd..a0ca6d1 100644 --- a/stacks_queues/set_of_stacks/set_of_stacks_challenge.ipynb +++ b/stacks_queues/set_of_stacks/set_of_stacks_challenge.ipynb @@ -34,7 +34,6 @@ "source": [ "## Constraints\n", "\n", - "* Can we assume we already have a stack class that can be used for this problem?\n", " * Yes\n", "* If a stack becomes full, we should automatically create one?\n", @@ -92,7 +91,7 @@ "outputs": [], "source": [ "class StackWithCapacity(Stack):\n", - " \n", + "\n", " def __init__(self, top=None, capacity=10):\n", " # TODO: Implement me\n", " pass\n", @@ -109,8 +108,9 @@ " # TODO: Implement me\n", " pass\n", "\n", + "\n", "class SetOfStacks(object):\n", - " \n", + "\n", " def __init__(self, capacity):\n", " # TODO: Implement me\n", " pass\n", @@ -148,7 +148,7 @@ "\n", "\n", "class TestSetOfStacks(object):\n", - " \n", + "\n", " def test_set_of_stacks(self):\n", " print('Test: Push on an empty stack')\n", " capacity = 2\n", @@ -170,13 +170,15 @@ "\n", " print('Test: Pop on no elements')\n", " assert_equal(stacks.pop(), None)\n", - " \n", + "\n", " print('Success: test_set_of_stacks')\n", "\n", + "\n", "def main():\n", " test = TestSetOfStacks()\n", " test.test_set_of_stacks()\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/stacks_queues/set_of_stacks/set_of_stacks_solution.ipynb b/stacks_queues/set_of_stacks/set_of_stacks_solution.ipynb index 45673f4..0d1b8a5 100644 --- a/stacks_queues/set_of_stacks/set_of_stacks_solution.ipynb +++ b/stacks_queues/set_of_stacks/set_of_stacks_solution.ipynb @@ -33,7 +33,6 @@ "source": [ "## Constraints\n", "\n", - "* Can we assume we already have a stack class that can be used for this problem?\n", " * Yes\n", "* If a stack becomes full, we should automatically create one?\n", @@ -112,7 +111,7 @@ "outputs": [], "source": [ "class StackWithCapacity(Stack):\n", - " \n", + "\n", " def __init__(self, top=None, capacity=10):\n", " self.capacity = capacity\n", " self.num_items = 0\n", @@ -133,8 +132,9 @@ " def is_full(self):\n", " return self.num_items == self.capacity\n", "\n", + "\n", "class SetOfStacks(object):\n", - " \n", + "\n", " def __init__(self, capacity):\n", " self.capacity = capacity\n", " self.stacks = []\n", @@ -191,7 +191,7 @@ "\n", "\n", "class TestSetOfStacks(object):\n", - " \n", + "\n", " def test_set_of_stacks(self):\n", " print('Test: Push on an empty stack')\n", " capacity = 2\n", @@ -213,13 +213,15 @@ "\n", " print('Test: Pop on no elements')\n", " assert_equal(stacks.pop(), None)\n", - " \n", + "\n", " print('Success: test_set_of_stacks')\n", "\n", + "\n", "def main():\n", " test = TestSetOfStacks()\n", " test.test_set_of_stacks()\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/stacks_queues/set_of_stacks/test_set_of_stacks.py b/stacks_queues/set_of_stacks/test_set_of_stacks.py index 88dd30b..fcb3f30 100644 --- a/stacks_queues/set_of_stacks/test_set_of_stacks.py +++ b/stacks_queues/set_of_stacks/test_set_of_stacks.py @@ -2,7 +2,7 @@ from nose.tools import assert_equal class TestSetOfStacks(object): - + def test_set_of_stacks(self): print('Test: Push on an empty stack') capacity = 2 @@ -24,12 +24,14 @@ class TestSetOfStacks(object): print('Test: Pop on no elements') assert_equal(stacks.pop(), None) - + print('Success: test_set_of_stacks') + def main(): test = TestSetOfStacks() test.test_set_of_stacks() - + + if __name__ == '__main__': main() \ No newline at end of file diff --git a/stacks_queues/sort_stack/sort_stack_challenge.ipynb b/stacks_queues/sort_stack/sort_stack_challenge.ipynb index 7b29aa5..1132e50 100644 --- a/stacks_queues/sort_stack/sort_stack_challenge.ipynb +++ b/stacks_queues/sort_stack/sort_stack_challenge.ipynb @@ -34,7 +34,6 @@ "source": [ "## Constraints\n", "\n", - "* When sorted, should the largest element be at the top or bottom?\n", " * Top\n", "* Can you have duplicate values like 5, 5?\n", @@ -92,7 +91,7 @@ "outputs": [], "source": [ "class MyStack(Stack):\n", - " \n", + "\n", " def sort(self):\n", " # TODO: Implement me\n", " pass" @@ -123,7 +122,7 @@ "\n", "\n", "class TestSortStack(object):\n", - " \n", + "\n", " def get_sorted_stack(self, numbers):\n", " stack = MyStack()\n", " for x in numbers:\n", @@ -148,13 +147,15 @@ " for _ in range(num_items):\n", " sorted_numbers.append(sorted_stack.pop())\n", " assert_equal(sorted_numbers, sorted(numbers, reverse=True))\n", - " \n", + "\n", " print('Success: test_sort_stack')\n", "\n", + "\n", "def main():\n", " test = TestSortStack()\n", " test.test_sort_stack()\n", "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/stacks_queues/sort_stack/sort_stack_solution.ipynb b/stacks_queues/sort_stack/sort_stack_solution.ipynb index 7ace48a..c8ed967 100644 --- a/stacks_queues/sort_stack/sort_stack_solution.ipynb +++ b/stacks_queues/sort_stack/sort_stack_solution.ipynb @@ -33,7 +33,6 @@ "source": [ "## Constraints\n", "\n", - "* When sorted, should the largest element be at the top or bottom?\n", " * Top\n", "* Can you have duplicate values like 5, 5?\n", @@ -101,7 +100,7 @@ "outputs": [], "source": [ "class MyStack(Stack):\n", - " \n", + "\n", " def sort(self):\n", " buff = MyStack()\n", " while not self.is_empty():\n", @@ -142,7 +141,7 @@ "\n", "\n", "class TestSortStack(object):\n", - " \n", + "\n", " def get_sorted_stack(self, numbers):\n", " stack = MyStack()\n", " for x in numbers:\n", @@ -167,13 +166,15 @@ " for _ in range(num_items):\n", " sorted_numbers.append(sorted_stack.pop())\n", " assert_equal(sorted_numbers, sorted(numbers, reverse=True))\n", - " \n", + "\n", " print('Success: test_sort_stack')\n", "\n", + "\n", "def main():\n", " test = TestSortStack()\n", " test.test_sort_stack()\n", "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/stacks_queues/sort_stack/test_sort_stack.py b/stacks_queues/sort_stack/test_sort_stack.py index 4985077..e117053 100644 --- a/stacks_queues/sort_stack/test_sort_stack.py +++ b/stacks_queues/sort_stack/test_sort_stack.py @@ -31,9 +31,11 @@ class TestSortStack(object): print('Success: test_sort_stack') + def main(): test = TestSortStack() test.test_sort_stack() + if __name__ == '__main__': main() \ No newline at end of file diff --git a/stacks_queues/stack/stack.py b/stacks_queues/stack/stack.py index 82b74a7..27dceed 100644 --- a/stacks_queues/stack/stack.py +++ b/stacks_queues/stack/stack.py @@ -1,11 +1,12 @@ class Node(object): - + def __init__(self, data): self.data = data self.next = None + class Stack(object): - + def __init__(self, top=None): self.top = top diff --git a/stacks_queues/stack/stack_challenge.ipynb b/stacks_queues/stack/stack_challenge.ipynb index eeb2e7c..29be60f 100644 --- a/stacks_queues/stack/stack_challenge.ipynb +++ b/stacks_queues/stack/stack_challenge.ipynb @@ -35,7 +35,6 @@ "source": [ "## Constraints\n", "\n", - "* None" ] }, @@ -92,13 +91,14 @@ "outputs": [], "source": [ "class Node(object):\n", - " \n", + "\n", " def __init__(self, data):\n", " # TODO: Implement me\n", " pass\n", "\n", + "\n", "class Stack(object):\n", - " \n", + "\n", " def __init__(self, top=None):\n", " # TODO: Implement me\n", " pass\n", @@ -144,7 +144,7 @@ "\n", "\n", "class TestStack(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", @@ -172,13 +172,15 @@ " assert_equal(stack.pop(), 1)\n", " assert_equal(stack.peek(), None)\n", " assert_equal(stack.is_empty(), True)\n", - " \n", + "\n", " print('Success: test_end_to_end')\n", "\n", + "\n", "def main():\n", " test = TestStack()\n", " test.test_end_to_end()\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/stacks_queues/stack/stack_solution.ipynb b/stacks_queues/stack/stack_solution.ipynb index bc81cad..a05fef9 100644 --- a/stacks_queues/stack/stack_solution.ipynb +++ b/stacks_queues/stack/stack_solution.ipynb @@ -34,7 +34,6 @@ "source": [ "## Constraints\n", "\n", - "* None" ] }, @@ -137,13 +136,14 @@ "source": [ "%%writefile stack.py\n", "class Node(object):\n", - " \n", + "\n", " def __init__(self, data):\n", " self.data = data\n", " self.next = None\n", "\n", + "\n", "class Stack(object):\n", - " \n", + "\n", " def __init__(self, top=None):\n", " self.top = top\n", "\n", @@ -208,7 +208,7 @@ "\n", "\n", "class TestStack(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", @@ -236,13 +236,15 @@ " assert_equal(stack.pop(), 1)\n", " assert_equal(stack.peek(), None)\n", " assert_equal(stack.is_empty(), True)\n", - " \n", + "\n", " print('Success: test_end_to_end')\n", "\n", + "\n", "def main():\n", " test = TestStack()\n", " test.test_end_to_end()\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/stacks_queues/stack/test_stack.py b/stacks_queues/stack/test_stack.py index cc56e2e..2349595 100644 --- a/stacks_queues/stack/test_stack.py +++ b/stacks_queues/stack/test_stack.py @@ -2,7 +2,7 @@ from nose.tools import assert_equal class TestStack(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): @@ -30,12 +30,14 @@ class TestStack(object): assert_equal(stack.pop(), 1) assert_equal(stack.peek(), None) assert_equal(stack.is_empty(), True) - + print('Success: test_end_to_end') + def main(): test = TestStack() test.test_end_to_end() - + + if __name__ == '__main__': main() \ No newline at end of file diff --git a/stacks_queues/stack_min/stack_min_challenge.ipynb b/stacks_queues/stack_min/stack_min_challenge.ipynb index 69e9467..c4bf6cc 100644 --- a/stacks_queues/stack_min/stack_min_challenge.ipynb +++ b/stacks_queues/stack_min/stack_min_challenge.ipynb @@ -92,6 +92,7 @@ "\n", "\n", "class MyStack(Stack):\n", + "\n", " def __init__(self, top=None):\n", " # TODO: Implement me\n", " pass\n", @@ -133,6 +134,7 @@ "\n", "\n", "class TestStackMin(object):\n", + "\n", " def test_stack_min(self):\n", " print('Test: Push on empty stack, non-empty stack')\n", " stack = MyStack()\n", @@ -161,13 +163,15 @@ "\n", " print('Test: Pop empty stack')\n", " assert_equal(stack.pop(), None)\n", - " \n", + "\n", " print('Success: test_stack_min')\n", "\n", + "\n", "def main():\n", " test = TestStackMin()\n", " test.test_stack_min()\n", "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/stacks_queues/stack_min/stack_min_solution.ipynb b/stacks_queues/stack_min/stack_min_solution.ipynb index df978eb..062bbe7 100644 --- a/stacks_queues/stack_min/stack_min_solution.ipynb +++ b/stacks_queues/stack_min/stack_min_solution.ipynb @@ -120,6 +120,7 @@ "\n", "\n", "class MyStack(Stack):\n", + "\n", " def __init__(self, top=None):\n", " self.min_vals = Stack()\n", " super(MyStack, self).__init__(top)\n", @@ -171,6 +172,7 @@ "\n", "\n", "class TestStackMin(object):\n", + "\n", " def test_stack_min(self):\n", " print('Test: Push on empty stack, non-empty stack')\n", " stack = MyStack()\n", @@ -199,13 +201,15 @@ "\n", " print('Test: Pop empty stack')\n", " assert_equal(stack.pop(), None)\n", - " \n", + "\n", " print('Success: test_stack_min')\n", "\n", + "\n", "def main():\n", " test = TestStackMin()\n", " test.test_stack_min()\n", "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/stacks_queues/stack_min/test_stack_min.py b/stacks_queues/stack_min/test_stack_min.py index 8b475c2..c76a6b0 100644 --- a/stacks_queues/stack_min/test_stack_min.py +++ b/stacks_queues/stack_min/test_stack_min.py @@ -2,6 +2,7 @@ from nose.tools import assert_equal class TestStackMin(object): + def test_stack_min(self): print('Test: Push on empty stack, non-empty stack') stack = MyStack() @@ -30,12 +31,14 @@ class TestStackMin(object): print('Test: Pop empty stack') assert_equal(stack.pop(), None) - + print('Success: test_stack_min') + def main(): test = TestStackMin() test.test_stack_min() + if __name__ == '__main__': main() \ No newline at end of file