From a2b4978c2eef7b9b7a654db1857c541ddb289d9f Mon Sep 17 00:00:00 2001 From: Donne Martin Date: Thu, 25 Feb 2016 05:47:15 -0500 Subject: [PATCH] Add None input test case to insertion sort --- .../insertion_sort_challenge.ipynb | 16 +++++++++++----- .../insertion_sort_solution.ipynb | 19 +++++++++++++------ .../insertion_sort/test_insertion_sort.py | 5 +++++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/sorting_searching/insertion_sort/insertion_sort_challenge.ipynb b/sorting_searching/insertion_sort/insertion_sort_challenge.ipynb index 9976d09..dce6097 100644 --- a/sorting_searching/insertion_sort/insertion_sort_challenge.ipynb +++ b/sorting_searching/insertion_sort/insertion_sort_challenge.ipynb @@ -44,6 +44,7 @@ "source": [ "## Test Cases\n", "\n", + "* None -> None\n", "* Empty input -> []\n", "* One element -> [element]\n", "* Two or more elements" @@ -104,6 +105,11 @@ "class TestInsertionSort(object):\n", "\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", " data = []\n", " insertion_sort(data)\n", @@ -143,21 +149,21 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.10" + "pygments_lexer": "ipython3", + "version": "3.4.3" } }, "nbformat": 4, diff --git a/sorting_searching/insertion_sort/insertion_sort_solution.ipynb b/sorting_searching/insertion_sort/insertion_sort_solution.ipynb index f136447..b78aebf 100644 --- a/sorting_searching/insertion_sort/insertion_sort_solution.ipynb +++ b/sorting_searching/insertion_sort/insertion_sort_solution.ipynb @@ -43,6 +43,7 @@ "source": [ "## Test Cases\n", "\n", + "* None -> None\n", "* Empty input -> []\n", "* One element -> [element]\n", "* Two or more elements" @@ -85,7 +86,7 @@ "outputs": [], "source": [ "def insertion_sort(data):\n", - " if len(data) < 2:\n", + " if data is None or len(data) < 2:\n", " return\n", " for r in range(1, len(data)):\n", " for l in range(0, r):\n", @@ -127,6 +128,11 @@ "class TestInsertionSort(object):\n", "\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", " data = []\n", " insertion_sort(data)\n", @@ -165,6 +171,7 @@ "name": "stdout", "output_type": "stream", "text": [ + "None input\n", "Empty input\n", "One element\n", "Two or more elements\n", @@ -179,21 +186,21 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.10" + "pygments_lexer": "ipython3", + "version": "3.4.3" } }, "nbformat": 4, diff --git a/sorting_searching/insertion_sort/test_insertion_sort.py b/sorting_searching/insertion_sort/test_insertion_sort.py index 7b4e85f..a99ee7e 100644 --- a/sorting_searching/insertion_sort/test_insertion_sort.py +++ b/sorting_searching/insertion_sort/test_insertion_sort.py @@ -4,6 +4,11 @@ from nose.tools import assert_equal class TestInsertionSort(object): def test_insertion_sort(self): + print('None input') + data = None + insertion_sort(data) + assert_equal(data, None) + print('Empty input') data = [] insertion_sort(data)