mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-05 17:08:02 +00:00
@@ -80,9 +80,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Stacks(object):\n",
|
||||
@@ -118,25 +116,20 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# %load test_n_stacks.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"from nose.tools import raises\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestStacks(object):\n",
|
||||
"class TestStacks(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" @raises(Exception)\n",
|
||||
" def test_pop_on_empty(self, num_stacks, stack_size):\n",
|
||||
" print('Test: Pop on empty stack')\n",
|
||||
" stacks = Stacks(num_stacks, stack_size)\n",
|
||||
" stacks.pop(0)\n",
|
||||
"\n",
|
||||
" @raises(Exception)\n",
|
||||
" def test_push_on_full(self, num_stacks, stack_size):\n",
|
||||
" print('Test: Push to full stack')\n",
|
||||
" stacks = Stacks(num_stacks, stack_size)\n",
|
||||
@@ -153,10 +146,10 @@
|
||||
" stacks.push(2, 4)\n",
|
||||
"\n",
|
||||
" print('Test: Pop on non-empty stack')\n",
|
||||
" assert_equal(stacks.pop(0), 2)\n",
|
||||
" assert_equal(stacks.pop(0), 1)\n",
|
||||
" assert_equal(stacks.pop(1), 3)\n",
|
||||
" assert_equal(stacks.pop(2), 4)\n",
|
||||
" self.assertEqual(stacks.pop(0), 2)\n",
|
||||
" self.assertEqual(stacks.pop(0), 1)\n",
|
||||
" self.assertEqual(stacks.pop(1), 3)\n",
|
||||
" self.assertEqual(stacks.pop(2), 4)\n",
|
||||
"\n",
|
||||
" print('Success: test_stacks\\n')\n",
|
||||
"\n",
|
||||
@@ -165,8 +158,10 @@
|
||||
" num_stacks = 3\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.assertRaises(Exception, test.test_pop_on_empty, num_stacks,\n",
|
||||
" stack_size)\n",
|
||||
" test.assertRaises(Exception, test.test_push_on_full, num_stacks,\n",
|
||||
" stack_size)\n",
|
||||
" test.test_stacks(num_stacks, stack_size)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
@@ -200,9 +195,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
|
||||
}
|
||||
|
||||
@@ -110,9 +110,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Stacks(object):\n",
|
||||
@@ -154,9 +152,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
@@ -168,19 +164,16 @@
|
||||
],
|
||||
"source": [
|
||||
"%%writefile test_n_stacks.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"from nose.tools import raises\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestStacks(object):\n",
|
||||
"class TestStacks(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" @raises(Exception)\n",
|
||||
" def test_pop_on_empty(self, num_stacks, stack_size):\n",
|
||||
" print('Test: Pop on empty stack')\n",
|
||||
" stacks = Stacks(num_stacks, stack_size)\n",
|
||||
" stacks.pop(0)\n",
|
||||
"\n",
|
||||
" @raises(Exception)\n",
|
||||
" def test_push_on_full(self, num_stacks, stack_size):\n",
|
||||
" print('Test: Push to full stack')\n",
|
||||
" stacks = Stacks(num_stacks, stack_size)\n",
|
||||
@@ -197,10 +190,10 @@
|
||||
" stacks.push(2, 4)\n",
|
||||
"\n",
|
||||
" print('Test: Pop on non-empty stack')\n",
|
||||
" assert_equal(stacks.pop(0), 2)\n",
|
||||
" assert_equal(stacks.pop(0), 1)\n",
|
||||
" assert_equal(stacks.pop(1), 3)\n",
|
||||
" assert_equal(stacks.pop(2), 4)\n",
|
||||
" self.assertEqual(stacks.pop(0), 2)\n",
|
||||
" self.assertEqual(stacks.pop(0), 1)\n",
|
||||
" self.assertEqual(stacks.pop(1), 3)\n",
|
||||
" self.assertEqual(stacks.pop(2), 4)\n",
|
||||
"\n",
|
||||
" print('Success: test_stacks\\n')\n",
|
||||
"\n",
|
||||
@@ -209,8 +202,10 @@
|
||||
" num_stacks = 3\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.assertRaises(Exception, test.test_pop_on_empty, num_stacks,\n",
|
||||
" stack_size)\n",
|
||||
" test.assertRaises(Exception, test.test_push_on_full, num_stacks,\n",
|
||||
" stack_size)\n",
|
||||
" test.test_stacks(num_stacks, stack_size)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
@@ -221,9 +216,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
@@ -241,6 +234,13 @@
|
||||
"source": [
|
||||
"run -i test_n_stacks.py"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
@@ -259,9 +259,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,16 +1,13 @@
|
||||
from nose.tools import assert_equal
|
||||
from nose.tools import raises
|
||||
import unittest
|
||||
|
||||
|
||||
class TestStacks(object):
|
||||
class TestStacks(unittest.TestCase):
|
||||
|
||||
@raises(Exception)
|
||||
def test_pop_on_empty(self, num_stacks, stack_size):
|
||||
print('Test: Pop on empty stack')
|
||||
stacks = Stacks(num_stacks, stack_size)
|
||||
stacks.pop(0)
|
||||
|
||||
@raises(Exception)
|
||||
def test_push_on_full(self, num_stacks, stack_size):
|
||||
print('Test: Push to full stack')
|
||||
stacks = Stacks(num_stacks, stack_size)
|
||||
@@ -27,10 +24,10 @@ class TestStacks(object):
|
||||
stacks.push(2, 4)
|
||||
|
||||
print('Test: Pop on non-empty stack')
|
||||
assert_equal(stacks.pop(0), 2)
|
||||
assert_equal(stacks.pop(0), 1)
|
||||
assert_equal(stacks.pop(1), 3)
|
||||
assert_equal(stacks.pop(2), 4)
|
||||
self.assertEqual(stacks.pop(0), 2)
|
||||
self.assertEqual(stacks.pop(0), 1)
|
||||
self.assertEqual(stacks.pop(1), 3)
|
||||
self.assertEqual(stacks.pop(2), 4)
|
||||
|
||||
print('Success: test_stacks\n')
|
||||
|
||||
@@ -39,10 +36,12 @@ def main():
|
||||
num_stacks = 3
|
||||
stack_size = 100
|
||||
test = TestStacks()
|
||||
test.test_pop_on_empty(num_stacks, stack_size)
|
||||
test.test_push_on_full(num_stacks, stack_size)
|
||||
test.assertRaises(Exception, test.test_pop_on_empty, num_stacks,
|
||||
stack_size)
|
||||
test.assertRaises(Exception, test.test_push_on_full, num_stacks,
|
||||
stack_size)
|
||||
test.test_stacks(num_stacks, stack_size)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user