mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Add None input test case to insertion sort
This commit is contained in:
parent
d8ac0b8fc6
commit
a2b4978c2e
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user