Add None input test case to insertion sort

This commit is contained in:
Donne Martin 2016-02-25 05:47:15 -05:00
parent d8ac0b8fc6
commit a2b4978c2e
3 changed files with 29 additions and 11 deletions

View File

@ -44,6 +44,7 @@
"source": [ "source": [
"## Test Cases\n", "## Test Cases\n",
"\n", "\n",
"* None -> None\n",
"* Empty input -> []\n", "* Empty input -> []\n",
"* One element -> [element]\n", "* One element -> [element]\n",
"* Two or more elements" "* Two or more elements"
@ -104,6 +105,11 @@
"class TestInsertionSort(object):\n", "class TestInsertionSort(object):\n",
"\n", "\n",
" def test_insertion_sort(self):\n", " def test_insertion_sort(self):\n",
" print('None input')\n",
" data = None\n",
" insertion_sort(data)\n",
" assert_equal(data, None)\n",
"\n",
" print('Empty input')\n", " print('Empty input')\n",
" data = []\n", " data = []\n",
" insertion_sort(data)\n", " insertion_sort(data)\n",
@ -143,21 +149,21 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 2", "display_name": "Python 3",
"language": "python", "language": "python",
"name": "python2" "name": "python3"
}, },
"language_info": { "language_info": {
"codemirror_mode": { "codemirror_mode": {
"name": "ipython", "name": "ipython",
"version": 2 "version": 3
}, },
"file_extension": ".py", "file_extension": ".py",
"mimetype": "text/x-python", "mimetype": "text/x-python",
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython2", "pygments_lexer": "ipython3",
"version": "2.7.10" "version": "3.4.3"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@ -43,6 +43,7 @@
"source": [ "source": [
"## Test Cases\n", "## Test Cases\n",
"\n", "\n",
"* None -> None\n",
"* Empty input -> []\n", "* Empty input -> []\n",
"* One element -> [element]\n", "* One element -> [element]\n",
"* Two or more elements" "* Two or more elements"
@ -85,7 +86,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"def insertion_sort(data):\n", "def insertion_sort(data):\n",
" if len(data) < 2:\n", " if data is None or len(data) < 2:\n",
" return\n", " return\n",
" for r in range(1, len(data)):\n", " for r in range(1, len(data)):\n",
" for l in range(0, r):\n", " for l in range(0, r):\n",
@ -127,6 +128,11 @@
"class TestInsertionSort(object):\n", "class TestInsertionSort(object):\n",
"\n", "\n",
" def test_insertion_sort(self):\n", " def test_insertion_sort(self):\n",
" print('None input')\n",
" data = None\n",
" insertion_sort(data)\n",
" assert_equal(data, None)\n",
"\n",
" print('Empty input')\n", " print('Empty input')\n",
" data = []\n", " data = []\n",
" insertion_sort(data)\n", " insertion_sort(data)\n",
@ -165,6 +171,7 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"None input\n",
"Empty input\n", "Empty input\n",
"One element\n", "One element\n",
"Two or more elements\n", "Two or more elements\n",
@ -179,21 +186,21 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 2", "display_name": "Python 3",
"language": "python", "language": "python",
"name": "python2" "name": "python3"
}, },
"language_info": { "language_info": {
"codemirror_mode": { "codemirror_mode": {
"name": "ipython", "name": "ipython",
"version": 2 "version": 3
}, },
"file_extension": ".py", "file_extension": ".py",
"mimetype": "text/x-python", "mimetype": "text/x-python",
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython2", "pygments_lexer": "ipython3",
"version": "2.7.10" "version": "3.4.3"
} }
}, },
"nbformat": 4, "nbformat": 4,

View File

@ -4,6 +4,11 @@ from nose.tools import assert_equal
class TestInsertionSort(object): class TestInsertionSort(object):
def test_insertion_sort(self): def test_insertion_sort(self):
print('None input')
data = None
insertion_sort(data)
assert_equal(data, None)
print('Empty input') print('Empty input')
data = [] data = []
insertion_sort(data) insertion_sort(data)