mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-15 22:08:02 +00:00
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user