#273: Remove nose dependency for sorting_searching/ (#278)

This commit is contained in:
Donne Martin 2020-07-11 11:25:26 -04:00 committed by GitHub
parent abf7524c26
commit d488e4f355
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 257 additions and 333 deletions

View File

@ -108,17 +108,17 @@
"outputs": [],
"source": [
"# %load test_anagrams.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestAnagrams(object):\n",
"class TestAnagrams(unittest.TestCase):\n",
"\n",
" def test_group_anagrams(self):\n",
" anagram = Anagram()\n",
" assert_raises(TypeError, anagram.group_anagrams, None)\n",
" self.assertRaises(TypeError, anagram.group_anagrams, None)\n",
" data = ['ram', 'act', 'arm', 'bat', 'cat', 'tab']\n",
" expected = ['ram', 'arm', 'act', 'cat', 'bat', 'tab']\n",
" assert_equal(anagram.group_anagrams(data), expected)\n",
" self.assertEqual(anagram.group_anagrams(data), expected)\n",
"\n",
" print('Success: test_group_anagrams')\n",
"\n",
@ -158,7 +158,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.7.2"
}
},
"nbformat": 4,

View File

@ -98,9 +98,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from collections import OrderedDict\n",
@ -138,9 +136,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -152,17 +148,17 @@
],
"source": [
"%%writefile test_anagrams.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestAnagrams(object):\n",
"class TestAnagrams(unittest.TestCase):\n",
"\n",
" def test_group_anagrams(self):\n",
" anagram = Anagram()\n",
" assert_raises(TypeError, anagram.group_anagrams, None)\n",
" self.assertRaises(TypeError, anagram.group_anagrams, None)\n",
" data = ['ram', 'act', 'arm', 'bat', 'cat', 'tab']\n",
" expected = ['ram', 'arm', 'act', 'cat', 'bat', 'tab']\n",
" assert_equal(anagram.group_anagrams(data), expected)\n",
" self.assertEqual(anagram.group_anagrams(data), expected)\n",
"\n",
" print('Success: test_group_anagrams')\n",
"\n",
@ -179,9 +175,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -212,9 +206,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
}

View File

@ -1,14 +1,14 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestAnagrams(object):
class TestAnagrams(unittest.TestCase):
def test_group_anagrams(self):
anagram = Anagram()
assert_raises(TypeError, anagram.group_anagrams, None)
self.assertRaises(TypeError, anagram.group_anagrams, None)
data = ['ram', 'act', 'arm', 'bat', 'cat', 'tab']
expected = ['ram', 'arm', 'act', 'cat', 'bat', 'tab']
assert_equal(anagram.group_anagrams(data), expected)
self.assertEqual(anagram.group_anagrams(data), expected)
print('Success: test_group_anagrams')

View File

@ -75,9 +75,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class InsertionSort(object):\n",
@ -101,32 +99,30 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_insertion_sort.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestInsertionSort(object):\n",
"class TestInsertionSort(unittest.TestCase):\n",
"\n",
" def test_insertion_sort(self):\n",
" insertion_sort = InsertionSort()\n",
"\n",
" print('None input')\n",
" assert_raises(TypeError, insertion_sort.sort, None)\n",
" self.assertRaises(TypeError, insertion_sort.sort, None)\n",
"\n",
" print('Empty input')\n",
" assert_equal(insertion_sort.sort([]), [])\n",
" self.assertEqual(insertion_sort.sort([]), [])\n",
"\n",
" print('One element')\n",
" assert_equal(insertion_sort.sort([5]), [5])\n",
" self.assertEqual(insertion_sort.sort([5]), [5])\n",
"\n",
" print('Two or more elements')\n",
" data = [5, 1, 7, 2, 6, -3, 5, 7, -1]\n",
" assert_equal(insertion_sort.sort(data), sorted(data))\n",
" self.assertEqual(insertion_sort.sort(data), sorted(data))\n",
"\n",
" print('Success: test_insertion_sort')\n",
"\n",
@ -166,9 +162,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
}

View File

@ -93,9 +93,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class InsertionSort(object):\n",
@ -125,9 +123,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -139,26 +135,26 @@
],
"source": [
"%%writefile test_insertion_sort.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestInsertionSort(object):\n",
"class TestInsertionSort(unittest.TestCase):\n",
"\n",
" def test_insertion_sort(self):\n",
" insertion_sort = InsertionSort()\n",
"\n",
" print('None input')\n",
" assert_raises(TypeError, insertion_sort.sort, None)\n",
" self.assertRaises(TypeError, insertion_sort.sort, None)\n",
"\n",
" print('Empty input')\n",
" assert_equal(insertion_sort.sort([]), [])\n",
" self.assertEqual(insertion_sort.sort([]), [])\n",
"\n",
" print('One element')\n",
" assert_equal(insertion_sort.sort([5]), [5])\n",
" self.assertEqual(insertion_sort.sort([5]), [5])\n",
"\n",
" print('Two or more elements')\n",
" data = [5, 1, 7, 2, 6, -3, 5, 7, -1]\n",
" assert_equal(insertion_sort.sort(data), sorted(data))\n",
" self.assertEqual(insertion_sort.sort(data), sorted(data))\n",
"\n",
" print('Success: test_insertion_sort')\n",
"\n",
@ -175,9 +171,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -212,9 +206,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
}

View File

@ -1,23 +1,23 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestInsertionSort(object):
class TestInsertionSort(unittest.TestCase):
def test_insertion_sort(self):
insertion_sort = InsertionSort()
print('None input')
assert_raises(TypeError, insertion_sort.sort, None)
self.assertRaises(TypeError, insertion_sort.sort, None)
print('Empty input')
assert_equal(insertion_sort.sort([]), [])
self.assertEqual(insertion_sort.sort([]), [])
print('One element')
assert_equal(insertion_sort.sort([5]), [5])
self.assertEqual(insertion_sort.sort([5]), [5])
print('Two or more elements')
data = [5, 1, 7, 2, 6, -3, 5, 7, -1]
assert_equal(insertion_sort.sort(data), sorted(data))
self.assertEqual(insertion_sort.sort(data), sorted(data))
print('Success: test_insertion_sort')

View File

@ -111,23 +111,23 @@
"outputs": [],
"source": [
"# %load test_merge_into.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestArray(object):\n",
"class TestArray(unittest.TestCase):\n",
"\n",
" def test_merge_into(self):\n",
" array = Array()\n",
" assert_raises(TypeError, array.merge_into, None, None, None, None)\n",
" assert_raises(ValueError, array.merge_into, [1], [2], -1, -1)\n",
" self.assertRaises(TypeError, array.merge_into, None, None, None, None)\n",
" self.assertRaises(ValueError, array.merge_into, [1], [2], -1, -1)\n",
" a = [1, 2, 3]\n",
" assert_equal(array.merge_into(a, [], len(a), 0), [1, 2, 3])\n",
" self.assertEqual(array.merge_into(a, [], len(a), 0), [1, 2, 3])\n",
" a = [1, 2, 3]\n",
" assert_equal(array.merge_into(a, [], len(a), 0), [1, 2, 3])\n",
" self.assertEqual(array.merge_into(a, [], len(a), 0), [1, 2, 3])\n",
" a = [1, 3, 5, 7, 9, None, None, None]\n",
" b = [4, 5, 6]\n",
" expected = [1, 3, 4, 5, 5, 6, 7, 9]\n",
" assert_equal(array.merge_into(a, b, 5, len(b)), expected)\n",
" self.assertEqual(array.merge_into(a, b, 5, len(b)), expected)\n",
" print('Success: test_merge_into')\n",
"\n",
"\n",
@ -166,7 +166,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.7.2"
}
},
"nbformat": 4,

View File

@ -149,9 +149,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Array(object):\n",
@ -189,9 +187,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -203,23 +199,23 @@
],
"source": [
"%%writefile test_merge_into.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestArray(object):\n",
"class TestArray(unittest.TestCase):\n",
"\n",
" def test_merge_into(self):\n",
" array = Array()\n",
" assert_raises(TypeError, array.merge_into, None, None, None, None)\n",
" assert_raises(ValueError, array.merge_into, [1], [2], -1, -1)\n",
" self.assertRaises(TypeError, array.merge_into, None, None, None, None)\n",
" self.assertRaises(ValueError, array.merge_into, [1], [2], -1, -1)\n",
" a = [1, 2, 3]\n",
" assert_equal(array.merge_into(a, [], len(a), 0), [1, 2, 3])\n",
" self.assertEqual(array.merge_into(a, [], len(a), 0), [1, 2, 3])\n",
" a = [1, 2, 3]\n",
" assert_equal(array.merge_into(a, [], len(a), 0), [1, 2, 3])\n",
" self.assertEqual(array.merge_into(a, [], len(a), 0), [1, 2, 3])\n",
" a = [1, 3, 5, 7, 9, None, None, None]\n",
" b = [4, 5, 6]\n",
" expected = [1, 3, 4, 5, 5, 6, 7, 9]\n",
" assert_equal(array.merge_into(a, b, 5, len(b)), expected)\n",
" self.assertEqual(array.merge_into(a, b, 5, len(b)), expected)\n",
" print('Success: test_merge_into')\n",
"\n",
"\n",
@ -235,9 +231,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -268,9 +262,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
}

View File

@ -1,20 +1,20 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestArray(object):
class TestArray(unittest.TestCase):
def test_merge_into(self):
array = Array()
assert_raises(TypeError, array.merge_into, None, None, None, None)
assert_raises(ValueError, array.merge_into, [1], [2], -1, -1)
self.assertRaises(TypeError, array.merge_into, None, None, None, None)
self.assertRaises(ValueError, array.merge_into, [1], [2], -1, -1)
a = [1, 2, 3]
assert_equal(array.merge_into(a, [], len(a), 0), [1, 2, 3])
self.assertEqual(array.merge_into(a, [], len(a), 0), [1, 2, 3])
a = [1, 2, 3]
assert_equal(array.merge_into(a, [], len(a), 0), [1, 2, 3])
self.assertEqual(array.merge_into(a, [], len(a), 0), [1, 2, 3])
a = [1, 3, 5, 7, 9, None, None, None]
b = [4, 5, 6]
expected = [1, 3, 4, 5, 5, 6, 7, 9]
assert_equal(array.merge_into(a, b, 5, len(b)), expected)
self.assertEqual(array.merge_into(a, b, 5, len(b)), expected)
print('Success: test_merge_into')

View File

@ -76,9 +76,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class MergeSort(object):\n",
@ -102,32 +100,30 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_merge_sort.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestMergeSort(object):\n",
"class TestMergeSort(unittest.TestCase):\n",
"\n",
" def test_merge_sort(self):\n",
" merge_sort = MergeSort()\n",
"\n",
" print('None input')\n",
" assert_raises(TypeError, merge_sort.sort, None)\n",
" self.assertRaises(TypeError, merge_sort.sort, None)\n",
"\n",
" print('Empty input')\n",
" assert_equal(merge_sort.sort([]), [])\n",
" self.assertEqual(merge_sort.sort([]), [])\n",
"\n",
" print('One element')\n",
" assert_equal(merge_sort.sort([5]), [5])\n",
" self.assertEqual(merge_sort.sort([5]), [5])\n",
"\n",
" print('Two or more elements')\n",
" data = [5, 1, 7, 2, 6, -3, 5, 7, -1]\n",
" assert_equal(merge_sort.sort(data), sorted(data))\n",
" self.assertEqual(merge_sort.sort(data), sorted(data))\n",
"\n",
" print('Success: test_merge_sort')\n",
"\n",
@ -167,9 +163,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
}

View File

@ -99,9 +99,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from __future__ import division\n",
@ -156,9 +154,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -170,26 +166,26 @@
],
"source": [
"%%writefile test_merge_sort.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestMergeSort(object):\n",
"class TestMergeSort(unittest.TestCase):\n",
"\n",
" def test_merge_sort(self):\n",
" merge_sort = MergeSort()\n",
"\n",
" print('None input')\n",
" assert_raises(TypeError, merge_sort.sort, None)\n",
" self.assertRaises(TypeError, merge_sort.sort, None)\n",
"\n",
" print('Empty input')\n",
" assert_equal(merge_sort.sort([]), [])\n",
" self.assertEqual(merge_sort.sort([]), [])\n",
"\n",
" print('One element')\n",
" assert_equal(merge_sort.sort([5]), [5])\n",
" self.assertEqual(merge_sort.sort([5]), [5])\n",
"\n",
" print('Two or more elements')\n",
" data = [5, 1, 7, 2, 6, -3, 5, 7, -1]\n",
" assert_equal(merge_sort.sort(data), sorted(data))\n",
" self.assertEqual(merge_sort.sort(data), sorted(data))\n",
"\n",
" print('Success: test_merge_sort')\n",
"\n",
@ -206,9 +202,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -243,9 +237,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
}

View File

@ -1,23 +1,23 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestMergeSort(object):
class TestMergeSort(unittest.TestCase):
def test_merge_sort(self):
merge_sort = MergeSort()
print('None input')
assert_raises(TypeError, merge_sort.sort, None)
self.assertRaises(TypeError, merge_sort.sort, None)
print('Empty input')
assert_equal(merge_sort.sort([]), [])
self.assertEqual(merge_sort.sort([]), [])
print('One element')
assert_equal(merge_sort.sort([5]), [5])
self.assertEqual(merge_sort.sort([5]), [5])
print('Two or more elements')
data = [5, 1, 7, 2, 6, -3, 5, 7, -1]
assert_equal(merge_sort.sort(data), sorted(data))
self.assertEqual(merge_sort.sort(data), sorted(data))
print('Success: test_merge_sort')

View File

@ -109,21 +109,21 @@
"outputs": [],
"source": [
"# %load test_new_int.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestBits(object):\n",
"class TestBits(unittest.TestCase):\n",
"\n",
" def test_new_int(self):\n",
" bits = Bits()\n",
" max_size = 32\n",
" assert_raises(TypeError, bits.new_int, None, max_size)\n",
" assert_raises(TypeError, bits.new_int, [], max_size)\n",
" self.assertRaises(TypeError, bits.new_int, None, max_size)\n",
" self.assertRaises(TypeError, bits.new_int, [], max_size)\n",
" data = [item for item in range(30)]\n",
" data.append(31)\n",
" assert_equal(bits.new_int(data, max_size), 30)\n",
" self.assertEqual(bits.new_int(data, max_size), 30)\n",
" data = [item for item in range(32)]\n",
" assert_equal(bits.new_int(data, max_size), None)\n",
" self.assertEqual(bits.new_int(data, max_size), None)\n",
" print('Success: test_find_int_excluded_from_input')\n",
"\n",
"\n",
@ -162,7 +162,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.7.2"
}
},
"nbformat": 4,

View File

@ -97,9 +97,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from bitstring import BitArray # Run pip install bitstring\n",
@ -129,9 +127,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -143,21 +139,21 @@
],
"source": [
"%%writefile test_new_int.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestBits(object):\n",
"class TestBits(unittest.TestCase):\n",
"\n",
" def test_new_int(self):\n",
" bits = Bits()\n",
" max_size = 32\n",
" assert_raises(TypeError, bits.new_int, None, max_size)\n",
" assert_raises(TypeError, bits.new_int, [], max_size)\n",
" self.assertRaises(TypeError, bits.new_int, None, max_size)\n",
" self.assertRaises(TypeError, bits.new_int, [], max_size)\n",
" data = [item for item in range(30)]\n",
" data.append(31)\n",
" assert_equal(bits.new_int(data, max_size), 30)\n",
" self.assertEqual(bits.new_int(data, max_size), 30)\n",
" data = [item for item in range(32)]\n",
" assert_equal(bits.new_int(data, max_size), None)\n",
" self.assertEqual(bits.new_int(data, max_size), None)\n",
" print('Success: test_find_int_excluded_from_input')\n",
"\n",
"\n",
@ -173,9 +169,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -206,9 +200,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -1,18 +1,18 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestBits(object):
class TestBits(unittest.TestCase):
def test_new_int(self):
bits = Bits()
max_size = 32
assert_raises(TypeError, bits.new_int, None, max_size)
assert_raises(TypeError, bits.new_int, [], max_size)
self.assertRaises(TypeError, bits.new_int, None, max_size)
self.assertRaises(TypeError, bits.new_int, [], max_size)
data = [item for item in range(30)]
data.append(31)
assert_equal(bits.new_int(data, max_size), 30)
self.assertEqual(bits.new_int(data, max_size), 30)
data = [item for item in range(32)]
assert_equal(bits.new_int(data, max_size), None)
self.assertEqual(bits.new_int(data, max_size), None)
print('Success: test_find_int_excluded_from_input')

View File

@ -75,9 +75,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class QuickSort(object):\n",
@ -101,32 +99,30 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_quick_sort.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestQuickSort(object):\n",
"class TestQuickSort(unittest.TestCase):\n",
"\n",
" def test_quick_sort(self):\n",
" quick_sort = QuickSort()\n",
"\n",
" print('None input')\n",
" assert_raises(TypeError, quick_sort.sort, None)\n",
" self.assertRaises(TypeError, quick_sort.sort, None)\n",
"\n",
" print('Empty input')\n",
" assert_equal(quick_sort.sort([]), [])\n",
" self.assertEqual(quick_sort.sort([]), [])\n",
"\n",
" print('One element')\n",
" assert_equal(quick_sort.sort([5]), [5])\n",
" self.assertEqual(quick_sort.sort([5]), [5])\n",
"\n",
" print('Two or more elements')\n",
" data = [5, 1, 7, 2, 6, -3, 5, 7, -1]\n",
" assert_equal(quick_sort.sort(data), sorted(data))\n",
" self.assertEqual(quick_sort.sort(data), sorted(data))\n",
"\n",
" print('Success: test_quick_sort\\n')\n",
"\n",
@ -166,9 +162,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
}

View File

@ -100,9 +100,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from __future__ import division\n",
@ -148,9 +146,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -162,26 +158,26 @@
],
"source": [
"%%writefile test_quick_sort.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestQuickSort(object):\n",
"class TestQuickSort(unittest.TestCase):\n",
"\n",
" def test_quick_sort(self):\n",
" quick_sort = QuickSort()\n",
"\n",
" print('None input')\n",
" assert_raises(TypeError, quick_sort.sort, None)\n",
" self.assertRaises(TypeError, quick_sort.sort, None)\n",
"\n",
" print('Empty input')\n",
" assert_equal(quick_sort.sort([]), [])\n",
" self.assertEqual(quick_sort.sort([]), [])\n",
"\n",
" print('One element')\n",
" assert_equal(quick_sort.sort([5]), [5])\n",
" self.assertEqual(quick_sort.sort([5]), [5])\n",
"\n",
" print('Two or more elements')\n",
" data = [5, 1, 7, 2, 6, -3, 5, 7, -1]\n",
" assert_equal(quick_sort.sort(data), sorted(data))\n",
" self.assertEqual(quick_sort.sort(data), sorted(data))\n",
"\n",
" print('Success: test_quick_sort\\n')\n",
"\n",
@ -198,9 +194,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -236,9 +230,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
}

View File

@ -1,23 +1,23 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestQuickSort(object):
class TestQuickSort(unittest.TestCase):
def test_quick_sort(self):
quick_sort = QuickSort()
print('None input')
assert_raises(TypeError, quick_sort.sort, None)
self.assertRaises(TypeError, quick_sort.sort, None)
print('Empty input')
assert_equal(quick_sort.sort([]), [])
self.assertEqual(quick_sort.sort([]), [])
print('One element')
assert_equal(quick_sort.sort([5]), [5])
self.assertEqual(quick_sort.sort([5]), [5])
print('Two or more elements')
data = [5, 1, 7, 2, 6, -3, 5, 7, -1]
assert_equal(quick_sort.sort(data), sorted(data))
self.assertEqual(quick_sort.sort(data), sorted(data))
print('Success: test_quick_sort\n')

View File

@ -108,18 +108,18 @@
"outputs": [],
"source": [
"# %load test_radix_sort.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestRadixSort(object):\n",
"class TestRadixSort(unittest.TestCase):\n",
"\n",
" def test_sort(self):\n",
" radix_sort = RadixSort()\n",
" assert_raises(TypeError, radix_sort.sort, None)\n",
" assert_equal(radix_sort.sort([]), [])\n",
" self.assertRaises(TypeError, radix_sort.sort, None)\n",
" self.assertEqual(radix_sort.sort([]), [])\n",
" array = [128, 256, 164, 8, 2, 148, 212, 242, 244]\n",
" expected = [2, 8, 128, 148, 164, 212, 242, 244, 256]\n",
" assert_equal(radix_sort.sort(array), expected)\n",
" self.assertEqual(radix_sort.sort(array), expected)\n",
" print('Success: test_sort')\n",
"\n",
"\n",
@ -158,7 +158,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.7.2"
}
},
"nbformat": 4,

View File

@ -115,9 +115,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class RadixSort(object):\n",
@ -150,9 +148,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -164,18 +160,18 @@
],
"source": [
"%%writefile test_radix_sort.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestRadixSort(object):\n",
"class TestRadixSort(unittest.TestCase):\n",
"\n",
" def test_sort(self):\n",
" radix_sort = RadixSort()\n",
" assert_raises(TypeError, radix_sort.sort, None)\n",
" assert_equal(radix_sort.sort([]), [])\n",
" self.assertRaises(TypeError, radix_sort.sort, None)\n",
" self.assertEqual(radix_sort.sort([]), [])\n",
" array = [128, 256, 164, 8, 2, 148, 212, 242, 244]\n",
" expected = [2, 8, 128, 148, 164, 212, 242, 244, 256]\n",
" assert_equal(radix_sort.sort(array), expected)\n",
" self.assertEqual(radix_sort.sort(array), expected)\n",
" print('Success: test_sort')\n",
"\n",
"\n",
@ -191,9 +187,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -224,9 +218,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
}

View File

@ -1,15 +1,15 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestRadixSort(object):
class TestRadixSort(unittest.TestCase):
def test_sort(self):
radix_sort = RadixSort()
assert_raises(TypeError, radix_sort.sort, None)
assert_equal(radix_sort.sort([]), [])
self.assertRaises(TypeError, radix_sort.sort, None)
self.assertEqual(radix_sort.sort([]), [])
array = [128, 256, 164, 8, 2, 148, 212, 242, 244]
expected = [2, 8, 128, 148, 164, 212, 242, 244, 256]
assert_equal(radix_sort.sort(array), expected)
self.assertEqual(radix_sort.sort(array), expected)
print('Success: test_sort')

View File

@ -111,20 +111,20 @@
"outputs": [],
"source": [
"# %load test_search_sorted_array.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestArray(object):\n",
"class TestArray(unittest.TestCase):\n",
"\n",
" def test_search_sorted_array(self):\n",
" array = Array()\n",
" assert_raises(TypeError, array.search_sorted_array, None)\n",
" assert_equal(array.search_sorted_array([3, 1, 2], 0), None)\n",
" assert_equal(array.search_sorted_array([3, 1, 2], 0), None)\n",
" self.assertRaises(TypeError, array.search_sorted_array, None)\n",
" self.assertEqual(array.search_sorted_array([3, 1, 2], 0), None)\n",
" self.assertEqual(array.search_sorted_array([3, 1, 2], 0), None)\n",
" data = [10, 12, 14, 1, 3, 5, 6, 7, 8, 9]\n",
" assert_equal(array.search_sorted_array(data, val=1), 3)\n",
" self.assertEqual(array.search_sorted_array(data, val=1), 3)\n",
" data = [ 1, 1, 2, 1, 1, 1, 1, 1, 1, 1]\n",
" assert_equal(array.search_sorted_array(data, val=2), 2)\n",
" self.assertEqual(array.search_sorted_array(data, val=2), 2)\n",
" print('Success: test_search_sorted_array')\n",
"\n",
"\n",
@ -163,7 +163,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.7.2"
}
},
"nbformat": 4,

View File

@ -130,9 +130,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class Array(object):\n",
@ -184,9 +182,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -198,20 +194,20 @@
],
"source": [
"%%writefile test_search_sorted_array.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestArray(object):\n",
"class TestArray(unittest.TestCase):\n",
"\n",
" def test_search_sorted_array(self):\n",
" array = Array()\n",
" assert_raises(TypeError, array.search_sorted_array, None)\n",
" assert_equal(array.search_sorted_array([3, 1, 2], 0), None)\n",
" assert_equal(array.search_sorted_array([3, 1, 2], 0), None)\n",
" self.assertRaises(TypeError, array.search_sorted_array, None)\n",
" self.assertEqual(array.search_sorted_array([3, 1, 2], 0), None)\n",
" self.assertEqual(array.search_sorted_array([3, 1, 2], 0), None)\n",
" data = [10, 12, 14, 1, 3, 5, 6, 7, 8, 9]\n",
" assert_equal(array.search_sorted_array(data, val=1), 3)\n",
" self.assertEqual(array.search_sorted_array(data, val=1), 3)\n",
" data = [ 1, 1, 2, 1, 1, 1, 1, 1, 1, 1]\n",
" assert_equal(array.search_sorted_array(data, val=2), 2)\n",
" self.assertEqual(array.search_sorted_array(data, val=2), 2)\n",
" print('Success: test_search_sorted_array')\n",
"\n",
"\n",
@ -227,9 +223,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -260,9 +254,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -1,17 +1,17 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestArray(object):
class TestArray(unittest.TestCase):
def test_search_sorted_array(self):
array = Array()
assert_raises(TypeError, array.search_sorted_array, None)
assert_equal(array.search_sorted_array([3, 1, 2], 0), None)
assert_equal(array.search_sorted_array([3, 1, 2], 0), None)
self.assertRaises(TypeError, array.search_sorted_array, None)
self.assertEqual(array.search_sorted_array([3, 1, 2], 0), None)
self.assertEqual(array.search_sorted_array([3, 1, 2], 0), None)
data = [10, 12, 14, 1, 3, 5, 6, 7, 8, 9]
assert_equal(array.search_sorted_array(data, val=1), 3)
self.assertEqual(array.search_sorted_array(data, val=1), 3)
data = [ 1, 1, 2, 1, 1, 1, 1, 1, 1, 1]
assert_equal(array.search_sorted_array(data, val=2), 2)
self.assertEqual(array.search_sorted_array(data, val=2), 2)
print('Success: test_search_sorted_array')

View File

@ -116,10 +116,10 @@
"outputs": [],
"source": [
"# %load test_search_sorted_matrix.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestSortedMatrix(object):\n",
"class TestSortedMatrix(unittest.TestCase):\n",
"\n",
" def test_find_val(self):\n",
" matrix = [[20, 40, 63, 80],\n",
@ -127,9 +127,9 @@
" [40, 60, 110, 110],\n",
" [50, 65, 105, 150]]\n",
" sorted_matrix = SortedMatrix()\n",
" assert_raises(TypeError, sorted_matrix.find_val, None, None)\n",
" assert_equal(sorted_matrix.find_val(matrix, 1000), None)\n",
" assert_equal(sorted_matrix.find_val(matrix, 60), (2, 1))\n",
" self.assertRaises(TypeError, sorted_matrix.find_val, None, None)\n",
" self.assertEqual(sorted_matrix.find_val(matrix, 1000), None)\n",
" self.assertEqual(sorted_matrix.find_val(matrix, 60), (2, 1))\n",
" print('Success: test_find_val')\n",
"\n",
"\n",
@ -168,7 +168,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.7.2"
}
},
"nbformat": 4,

View File

@ -107,9 +107,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class SortedMatrix(object):\n",
@ -139,24 +137,22 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Writing test_search_sorted_matrix.py\n"
"Overwriting test_search_sorted_matrix.py\n"
]
}
],
"source": [
"%%writefile test_search_sorted_matrix.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestSortedMatrix(object):\n",
"class TestSortedMatrix(unittest.TestCase):\n",
"\n",
" def test_find_val(self):\n",
" matrix = [[20, 40, 63, 80],\n",
@ -164,9 +160,9 @@
" [40, 60, 110, 110],\n",
" [50, 65, 105, 150]]\n",
" sorted_matrix = SortedMatrix()\n",
" assert_raises(TypeError, sorted_matrix.find_val, None, None)\n",
" assert_equal(sorted_matrix.find_val(matrix, 1000), None)\n",
" assert_equal(sorted_matrix.find_val(matrix, 60), (2, 1))\n",
" self.assertRaises(TypeError, sorted_matrix.find_val, None, None)\n",
" self.assertEqual(sorted_matrix.find_val(matrix, 1000), None)\n",
" self.assertEqual(sorted_matrix.find_val(matrix, 60), (2, 1))\n",
" print('Success: test_find_val')\n",
"\n",
"\n",
@ -182,9 +178,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -215,9 +209,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
}

View File

@ -1,7 +1,7 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestSortedMatrix(object):
class TestSortedMatrix(unittest.TestCase):
def test_find_val(self):
matrix = [[20, 40, 63, 80],
@ -9,9 +9,9 @@ class TestSortedMatrix(object):
[40, 60, 110, 110],
[50, 65, 105, 150]]
sorted_matrix = SortedMatrix()
assert_raises(TypeError, sorted_matrix.find_val, None, None)
assert_equal(sorted_matrix.find_val(matrix, 1000), None)
assert_equal(sorted_matrix.find_val(matrix, 60), (2, 1))
self.assertRaises(TypeError, sorted_matrix.find_val, None, None)
self.assertEqual(sorted_matrix.find_val(matrix, 1000), None)
self.assertEqual(sorted_matrix.find_val(matrix, 60), (2, 1))
print('Success: test_find_val')

View File

@ -75,9 +75,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"class SelectionSort(object):\n",
@ -101,30 +99,28 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# %load test_selection_sort.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestSelectionSort(object):\n",
"class TestSelectionSort(unittest.TestCase):\n",
"\n",
" def test_selection_sort(self, func):\n",
" print('None input')\n",
" assert_raises(TypeError, func, None)\n",
" self.assertRaises(TypeError, func, None)\n",
"\n",
" print('Empty input')\n",
" assert_equal(func([]), [])\n",
" self.assertEqual(func([]), [])\n",
"\n",
" print('One element')\n",
" assert_equal(func([5]), [5])\n",
" self.assertEqual(func([5]), [5])\n",
"\n",
" print('Two or more elements')\n",
" data = [5, 1, 7, 2, 6, -3, 5, 7, -10]\n",
" assert_equal(func(data), sorted(data))\n",
" self.assertEqual(func(data), sorted(data))\n",
"\n",
" print('Success: test_selection_sort\\n')\n",
"\n",
@ -172,9 +168,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
}

View File

@ -95,9 +95,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"class SelectionSort(object):\n",
@ -164,9 +162,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -178,24 +174,24 @@
],
"source": [
"%%writefile test_selection_sort.py\n",
"from nose.tools import assert_equal, assert_raises\n",
"import unittest\n",
"\n",
"\n",
"class TestSelectionSort(object):\n",
"class TestSelectionSort(unittest.TestCase):\n",
"\n",
" def test_selection_sort(self, func):\n",
" print('None input')\n",
" assert_raises(TypeError, func, None)\n",
" self.assertRaises(TypeError, func, None)\n",
"\n",
" print('Empty input')\n",
" assert_equal(func([]), [])\n",
" self.assertEqual(func([]), [])\n",
"\n",
" print('One element')\n",
" assert_equal(func([5]), [5])\n",
" self.assertEqual(func([5]), [5])\n",
"\n",
" print('Two or more elements')\n",
" data = [5, 1, 7, 2, 6, -3, 5, 7, -10]\n",
" assert_equal(func(data), sorted(data))\n",
" self.assertEqual(func(data), sorted(data))\n",
"\n",
" print('Success: test_selection_sort\\n')\n",
"\n",
@ -220,9 +216,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@ -262,9 +256,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}

View File

@ -1,21 +1,21 @@
from nose.tools import assert_equal, assert_raises
import unittest
class TestSelectionSort(object):
class TestSelectionSort(unittest.TestCase):
def test_selection_sort(self, func):
print('None input')
assert_raises(TypeError, func, None)
self.assertRaises(TypeError, func, None)
print('Empty input')
assert_equal(func([]), [])
self.assertEqual(func([]), [])
print('One element')
assert_equal(func([5]), [5])
self.assertEqual(func([5]), [5])
print('Two or more elements')
data = [5, 1, 7, 2, 6, -3, 5, 7, -10]
assert_equal(func(data), sorted(data))
self.assertEqual(func(data), sorted(data))
print('Success: test_selection_sort\n')