mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-07 18:08:01 +00:00
@@ -87,9 +87,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class MyStack(Stack):\n",
|
||||
@@ -113,17 +111,15 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# %load test_sort_stack.py\n",
|
||||
"from random import randint\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestSortStack(object):\n",
|
||||
"class TestSortStack(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def get_sorted_stack(self, stack, numbers):\n",
|
||||
" for x in numbers:\n",
|
||||
@@ -134,11 +130,11 @@
|
||||
" def test_sort_stack(self, stack):\n",
|
||||
" print('Test: Empty stack')\n",
|
||||
" sorted_stack = self.get_sorted_stack(stack, [])\n",
|
||||
" assert_equal(sorted_stack.pop(), None)\n",
|
||||
" self.assertEqual(sorted_stack.pop(), None)\n",
|
||||
"\n",
|
||||
" print('Test: One element stack')\n",
|
||||
" sorted_stack = self.get_sorted_stack(stack, [1])\n",
|
||||
" assert_equal(sorted_stack.pop(), 1)\n",
|
||||
" self.assertEqual(sorted_stack.pop(), 1)\n",
|
||||
"\n",
|
||||
" print('Test: Two or more element stack (general case)')\n",
|
||||
" num_items = 10\n",
|
||||
@@ -147,7 +143,7 @@
|
||||
" sorted_numbers = []\n",
|
||||
" for _ in range(num_items):\n",
|
||||
" sorted_numbers.append(sorted_stack.pop())\n",
|
||||
" assert_equal(sorted_numbers, sorted(numbers, reverse=True))\n",
|
||||
" self.assertEqual(sorted_numbers, sorted(numbers, reverse=True))\n",
|
||||
"\n",
|
||||
" print('Success: test_sort_stack')\n",
|
||||
"\n",
|
||||
@@ -193,9 +189,9 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.5.0"
|
||||
"version": "3.7.2"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
"nbformat_minor": 1
|
||||
}
|
||||
|
||||
@@ -84,9 +84,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%run ../stack/stack.py"
|
||||
@@ -95,9 +93,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class MyStack(Stack):\n",
|
||||
@@ -125,9 +121,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class MyStackSimplified(Stack):\n",
|
||||
@@ -153,9 +147,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
@@ -168,10 +160,10 @@
|
||||
"source": [
|
||||
"%%writefile test_sort_stack.py\n",
|
||||
"from random import randint\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestSortStack(object):\n",
|
||||
"class TestSortStack(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def get_sorted_stack(self, stack, numbers):\n",
|
||||
" for x in numbers:\n",
|
||||
@@ -182,11 +174,11 @@
|
||||
" def test_sort_stack(self, stack):\n",
|
||||
" print('Test: Empty stack')\n",
|
||||
" sorted_stack = self.get_sorted_stack(stack, [])\n",
|
||||
" assert_equal(sorted_stack.pop(), None)\n",
|
||||
" self.assertEqual(sorted_stack.pop(), None)\n",
|
||||
"\n",
|
||||
" print('Test: One element stack')\n",
|
||||
" sorted_stack = self.get_sorted_stack(stack, [1])\n",
|
||||
" assert_equal(sorted_stack.pop(), 1)\n",
|
||||
" self.assertEqual(sorted_stack.pop(), 1)\n",
|
||||
"\n",
|
||||
" print('Test: Two or more element stack (general case)')\n",
|
||||
" num_items = 10\n",
|
||||
@@ -195,7 +187,7 @@
|
||||
" sorted_numbers = []\n",
|
||||
" for _ in range(num_items):\n",
|
||||
" sorted_numbers.append(sorted_stack.pop())\n",
|
||||
" assert_equal(sorted_numbers, sorted(numbers, reverse=True))\n",
|
||||
" self.assertEqual(sorted_numbers, sorted(numbers, reverse=True))\n",
|
||||
"\n",
|
||||
" print('Success: test_sort_stack')\n",
|
||||
"\n",
|
||||
@@ -213,9 +205,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
@@ -253,9 +243,9 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.5.0"
|
||||
"version": "3.7.2"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
"nbformat_minor": 1
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from random import randint
|
||||
from nose.tools import assert_equal
|
||||
import unittest
|
||||
|
||||
|
||||
class TestSortStack(object):
|
||||
class TestSortStack(unittest.TestCase):
|
||||
|
||||
def get_sorted_stack(self, stack, numbers):
|
||||
for x in numbers:
|
||||
@@ -13,11 +13,11 @@ class TestSortStack(object):
|
||||
def test_sort_stack(self, stack):
|
||||
print('Test: Empty stack')
|
||||
sorted_stack = self.get_sorted_stack(stack, [])
|
||||
assert_equal(sorted_stack.pop(), None)
|
||||
self.assertEqual(sorted_stack.pop(), None)
|
||||
|
||||
print('Test: One element stack')
|
||||
sorted_stack = self.get_sorted_stack(stack, [1])
|
||||
assert_equal(sorted_stack.pop(), 1)
|
||||
self.assertEqual(sorted_stack.pop(), 1)
|
||||
|
||||
print('Test: Two or more element stack (general case)')
|
||||
num_items = 10
|
||||
@@ -26,7 +26,7 @@ class TestSortStack(object):
|
||||
sorted_numbers = []
|
||||
for _ in range(num_items):
|
||||
sorted_numbers.append(sorted_stack.pop())
|
||||
assert_equal(sorted_numbers, sorted(numbers, reverse=True))
|
||||
self.assertEqual(sorted_numbers, sorted(numbers, reverse=True))
|
||||
|
||||
print('Success: test_sort_stack')
|
||||
|
||||
@@ -38,4 +38,4 @@ def main():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user