Reworked notebook: Added more detail to constraints and test cases. Reworked unit test.

This commit is contained in:
Donne Martin 2015-06-27 06:38:30 -04:00
parent 0c43a34ae1
commit 9c36d2dc0a

View File

@ -13,20 +13,23 @@
"source": [ "source": [
"## Problem: Implement insertion sort.\n", "## Problem: Implement insertion sort.\n",
"\n", "\n",
"* [Clarifying Questions](#Clarifying-Questions)\n", "* [Constraints and Assumptions](#Constraints-and-Assumptions)\n",
"* [Test Cases](#Test-Cases)\n", "* [Test Cases](#Test-Cases)\n",
"* [Algorithm](#Algorithm)\n", "* [Algorithm](#Algorithm)\n",
"* [Code](#Code)\n", "* [Code](#Code)\n",
"* [Pythonic-Code](#Pythonic-Code)" "* [Unit Test](#Unit-Test)"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Clarifying Questions\n", "## Constraints and Assumptions\n",
"\n", "\n",
"* None" "*Problem statements are often intentionally ambiguous. Identifying constraints and stating assumptions can help to ensure you code the intended solution.*\n",
"\n",
"* Are you looking for a naiive solution?\n",
" * Yes"
] ]
}, },
{ {
@ -70,7 +73,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 1,
"metadata": { "metadata": {
"collapsed": false "collapsed": false
}, },
@ -89,25 +92,57 @@
] ]
}, },
{ {
"cell_type": "code", "cell_type": "markdown",
"execution_count": null, "metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [ "source": [
"## Unit Test\n",
"\n",
"*It is important to identify and run through general and edge cases from the [Test Cases](#Test-Cases) section by hand. You generally will not be asked to write a unit test like what is shown below.*"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Empty input\n",
"One element\n",
"Two or more elements\n",
"Success: test_insertion_sort\n"
]
}
],
"source": [
"from nose.tools import assert_equal\n",
"\n",
"class Test(object):\n",
" def test_insertion_sort(self):\n",
" print('Empty input')\n", " print('Empty input')\n",
" data = []\n", " data = []\n",
" insertion_sort(data)\n", " insertion_sort(data)\n",
"print(data)\n", " assert_equal(data, [])\n",
"\n",
" print('One element')\n", " print('One element')\n",
" data = [5]\n", " data = [5]\n",
" insertion_sort(data)\n", " insertion_sort(data)\n",
"print(data)\n", " assert_equal(data, [5])\n",
"\n",
" print('Two or more elements')\n", " print('Two or more elements')\n",
" data = [5, 1, 7, 2, 6, -3, 5, 7, -1]\n", " data = [5, 1, 7, 2, 6, -3, 5, 7, -1]\n",
" insertion_sort(data)\n", " insertion_sort(data)\n",
"print(data)" " assert_equal(data, sorted(data))\n",
" \n",
" print('Success: test_insertion_sort')\n",
"\n",
"if __name__ == '__main__':\n",
" test = Test()\n",
" test.test_insertion_sort()"
] ]
} }
], ],