mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-05 08:58:02 +00:00
@@ -111,9 +111,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Knapsack(object):\n",
|
||||
@@ -140,21 +138,19 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# %load test_knapsack_unbounded.py\n",
|
||||
"from nose.tools import assert_equal, assert_raises\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestKnapsack(object):\n",
|
||||
"class TestKnapsack(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_knapsack(self):\n",
|
||||
" knapsack = Knapsack()\n",
|
||||
" assert_raises(TypeError, knapsack.fill_knapsack, None, None)\n",
|
||||
" assert_equal(knapsack.fill_knapsack(0, 0), 0)\n",
|
||||
" self.assertRaises(TypeError, knapsack.fill_knapsack, None, None)\n",
|
||||
" self.assertEqual(knapsack.fill_knapsack(0, 0), 0)\n",
|
||||
" items = []\n",
|
||||
" items.append(Item(label='a', value=1, weight=1))\n",
|
||||
" items.append(Item(label='b', value=3, weight=2))\n",
|
||||
@@ -165,7 +161,7 @@
|
||||
" total_weight = 7\n",
|
||||
" expected_value = 11\n",
|
||||
" results = knapsack.fill_knapsack(items, total_weight)\n",
|
||||
" assert_equal(results, expected_value)\n",
|
||||
" self.assertEqual(results, expected_value)\n",
|
||||
" print('Success: test_knapsack')\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
@@ -203,9 +199,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