#273: Remove nose dependency for linked_lists/ (#275)

This commit is contained in:
Donne Martin
2020-07-06 21:09:04 -04:00
committed by GitHub
parent b598f474af
commit 0e7ed80228
25 changed files with 283 additions and 383 deletions

View File

@@ -95,9 +95,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class MyLinkedList(LinkedList):\n", "class MyLinkedList(LinkedList):\n",
@@ -126,22 +124,20 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# %load test_add_reverse.py\n", "# %load test_add_reverse.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class TestAddReverse(object):\n", "class TestAddReverse(unittest.TestCase):\n",
"\n", "\n",
" def test_add_reverse(self):\n", " def test_add_reverse(self):\n",
" print('Test: Empty list(s)')\n", " print('Test: Empty list(s)')\n",
" assert_equal(MyLinkedList().add_reverse(None, None), None)\n", " self.assertEqual(MyLinkedList().add_reverse(None, None), None)\n",
" assert_equal(MyLinkedList().add_reverse(Node(5), None), None)\n", " self.assertEqual(MyLinkedList().add_reverse(Node(5), None), None)\n",
" assert_equal(MyLinkedList().add_reverse(None, Node(10)), None)\n", " self.assertEqual(MyLinkedList().add_reverse(None, Node(10)), None)\n",
"\n", "\n",
" print('Test: Add values of different lengths')\n", " print('Test: Add values of different lengths')\n",
" # Input 1: 6->5->None\n", " # Input 1: 6->5->None\n",
@@ -153,7 +149,7 @@
" second_list.append(8)\n", " second_list.append(8)\n",
" second_list.append(7)\n", " second_list.append(7)\n",
" result = MyLinkedList().add_reverse(first_list, second_list)\n", " result = MyLinkedList().add_reverse(first_list, second_list)\n",
" assert_equal(result.get_all_data(), [5, 4, 8])\n", " self.assertEqual(result.get_all_data(), [5, 4, 8])\n",
"\n", "\n",
" print('Test: Add values of same lengths')\n", " print('Test: Add values of same lengths')\n",
" # Input 1: 6->5->4\n", " # Input 1: 6->5->4\n",
@@ -168,7 +164,7 @@
" second_list.append(8)\n", " second_list.append(8)\n",
" second_list.append(7)\n", " second_list.append(7)\n",
" result = MyLinkedList().add_reverse(first_list, second_list)\n", " result = MyLinkedList().add_reverse(first_list, second_list)\n",
" assert_equal(result.get_all_data(), [5, 4, 2, 1])\n", " self.assertEqual(result.get_all_data(), [5, 4, 2, 1])\n",
"\n", "\n",
" print('Success: test_add_reverse')\n", " print('Success: test_add_reverse')\n",
"\n", "\n",
@@ -208,9 +204,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@@ -103,9 +103,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"%run ../linked_list/linked_list.py" "%run ../linked_list/linked_list.py"
@@ -114,9 +112,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class MyLinkedList(LinkedList):\n", "class MyLinkedList(LinkedList):\n",
@@ -157,9 +153,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@@ -171,16 +165,16 @@
], ],
"source": [ "source": [
"%%writefile test_add_reverse.py\n", "%%writefile test_add_reverse.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class TestAddReverse(object):\n", "class TestAddReverse(unittest.TestCase):\n",
"\n", "\n",
" def test_add_reverse(self):\n", " def test_add_reverse(self):\n",
" print('Test: Empty list(s)')\n", " print('Test: Empty list(s)')\n",
" assert_equal(MyLinkedList().add_reverse(None, None), None)\n", " self.assertEqual(MyLinkedList().add_reverse(None, None), None)\n",
" assert_equal(MyLinkedList().add_reverse(Node(5), None), None)\n", " self.assertEqual(MyLinkedList().add_reverse(Node(5), None), None)\n",
" assert_equal(MyLinkedList().add_reverse(None, Node(10)), None)\n", " self.assertEqual(MyLinkedList().add_reverse(None, Node(10)), None)\n",
"\n", "\n",
" print('Test: Add values of different lengths')\n", " print('Test: Add values of different lengths')\n",
" # Input 1: 6->5->None\n", " # Input 1: 6->5->None\n",
@@ -192,7 +186,7 @@
" second_list.append(8)\n", " second_list.append(8)\n",
" second_list.append(7)\n", " second_list.append(7)\n",
" result = MyLinkedList().add_reverse(first_list, second_list)\n", " result = MyLinkedList().add_reverse(first_list, second_list)\n",
" assert_equal(result.get_all_data(), [5, 4, 8])\n", " self.assertEqual(result.get_all_data(), [5, 4, 8])\n",
"\n", "\n",
" print('Test: Add values of same lengths')\n", " print('Test: Add values of same lengths')\n",
" # Input 1: 6->5->4\n", " # Input 1: 6->5->4\n",
@@ -207,7 +201,7 @@
" second_list.append(8)\n", " second_list.append(8)\n",
" second_list.append(7)\n", " second_list.append(7)\n",
" result = MyLinkedList().add_reverse(first_list, second_list)\n", " result = MyLinkedList().add_reverse(first_list, second_list)\n",
" assert_equal(result.get_all_data(), [5, 4, 2, 1])\n", " self.assertEqual(result.get_all_data(), [5, 4, 2, 1])\n",
"\n", "\n",
" print('Success: test_add_reverse')\n", " print('Success: test_add_reverse')\n",
"\n", "\n",
@@ -224,9 +218,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 4,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@@ -260,9 +252,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@@ -1,13 +1,13 @@
from nose.tools import assert_equal import unittest
class TestAddReverse(object): class TestAddReverse(unittest.TestCase):
def test_add_reverse(self): def test_add_reverse(self):
print('Test: Empty list(s)') print('Test: Empty list(s)')
assert_equal(MyLinkedList().add_reverse(None, None), None) self.assertEqual(MyLinkedList().add_reverse(None, None), None)
assert_equal(MyLinkedList().add_reverse(Node(5), None), None) self.assertEqual(MyLinkedList().add_reverse(Node(5), None), None)
assert_equal(MyLinkedList().add_reverse(None, Node(10)), None) self.assertEqual(MyLinkedList().add_reverse(None, Node(10)), None)
print('Test: Add values of different lengths') print('Test: Add values of different lengths')
# Input 1: 6->5->None # Input 1: 6->5->None
@@ -19,7 +19,7 @@ class TestAddReverse(object):
second_list.append(8) second_list.append(8)
second_list.append(7) second_list.append(7)
result = MyLinkedList().add_reverse(first_list, second_list) result = MyLinkedList().add_reverse(first_list, second_list)
assert_equal(result.get_all_data(), [5, 4, 8]) self.assertEqual(result.get_all_data(), [5, 4, 8])
print('Test: Add values of same lengths') print('Test: Add values of same lengths')
# Input 1: 6->5->4 # Input 1: 6->5->4
@@ -34,7 +34,7 @@ class TestAddReverse(object):
second_list.append(8) second_list.append(8)
second_list.append(7) second_list.append(7)
result = MyLinkedList().add_reverse(first_list, second_list) result = MyLinkedList().add_reverse(first_list, second_list)
assert_equal(result.get_all_data(), [5, 4, 2, 1]) self.assertEqual(result.get_all_data(), [5, 4, 2, 1])
print('Success: test_add_reverse') print('Success: test_add_reverse')

View File

@@ -73,9 +73,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"%run ../linked_list/linked_list.py\n", "%run ../linked_list/linked_list.py\n",
@@ -85,9 +83,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class MyLinkedList(LinkedList):\n", "class MyLinkedList(LinkedList):\n",
@@ -116,28 +112,26 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# %load test_delete_mid.py\n", "# %load test_delete_mid.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class TestDeleteNode(object):\n", "class TestDeleteNode(unittest.TestCase):\n",
"\n", "\n",
" def test_delete_node(self):\n", " def test_delete_node(self):\n",
" print('Test: Empty list, null node to delete')\n", " print('Test: Empty list, null node to delete')\n",
" linked_list = MyLinkedList(None)\n", " linked_list = MyLinkedList(None)\n",
" linked_list.delete_node(None)\n", " linked_list.delete_node(None)\n",
" assert_equal(linked_list.get_all_data(), [])\n", " self.assertEqual(linked_list.get_all_data(), [])\n",
"\n", "\n",
" print('Test: One node')\n", " print('Test: One node')\n",
" head = Node(2)\n", " head = Node(2)\n",
" linked_list = MyLinkedList(head)\n", " linked_list = MyLinkedList(head)\n",
" linked_list.delete_node(head)\n", " linked_list.delete_node(head)\n",
" assert_equal(linked_list.get_all_data(), [None])\n", " self.assertEqual(linked_list.get_all_data(), [None])\n",
"\n", "\n",
" print('Test: Multiple nodes')\n", " print('Test: Multiple nodes')\n",
" linked_list = MyLinkedList(None)\n", " linked_list = MyLinkedList(None)\n",
@@ -146,7 +140,7 @@
" node2 = linked_list.insert_to_front(4)\n", " node2 = linked_list.insert_to_front(4)\n",
" node3 = linked_list.insert_to_front(1)\n", " node3 = linked_list.insert_to_front(1)\n",
" linked_list.delete_node(node1)\n", " linked_list.delete_node(node1)\n",
" assert_equal(linked_list.get_all_data(), [1, 4, 2])\n", " self.assertEqual(linked_list.get_all_data(), [1, 4, 2])\n",
"\n", "\n",
" print('Test: Multiple nodes, delete last element')\n", " print('Test: Multiple nodes, delete last element')\n",
" linked_list = MyLinkedList(None)\n", " linked_list = MyLinkedList(None)\n",
@@ -155,7 +149,7 @@
" node2 = linked_list.insert_to_front(4)\n", " node2 = linked_list.insert_to_front(4)\n",
" node3 = linked_list.insert_to_front(1)\n", " node3 = linked_list.insert_to_front(1)\n",
" linked_list.delete_node(node0)\n", " linked_list.delete_node(node0)\n",
" assert_equal(linked_list.get_all_data(), [1, 4, 3, None])\n", " self.assertEqual(linked_list.get_all_data(), [1, 4, 3, None])\n",
"\n", "\n",
" print('Success: test_delete_node')\n", " print('Success: test_delete_node')\n",
"\n", "\n",
@@ -195,9 +189,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@@ -79,9 +79,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"%run ../linked_list/linked_list.py" "%run ../linked_list/linked_list.py"
@@ -90,9 +88,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class MyLinkedList(LinkedList):\n", "class MyLinkedList(LinkedList):\n",
@@ -117,9 +113,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@@ -131,22 +125,22 @@
], ],
"source": [ "source": [
"%%writefile test_delete_mid.py\n", "%%writefile test_delete_mid.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class TestDeleteNode(object):\n", "class TestDeleteNode(unittest.TestCase):\n",
"\n", "\n",
" def test_delete_node(self):\n", " def test_delete_node(self):\n",
" print('Test: Empty list, null node to delete')\n", " print('Test: Empty list, null node to delete')\n",
" linked_list = MyLinkedList(None)\n", " linked_list = MyLinkedList(None)\n",
" linked_list.delete_node(None)\n", " linked_list.delete_node(None)\n",
" assert_equal(linked_list.get_all_data(), [])\n", " self.assertEqual(linked_list.get_all_data(), [])\n",
"\n", "\n",
" print('Test: One node')\n", " print('Test: One node')\n",
" head = Node(2)\n", " head = Node(2)\n",
" linked_list = MyLinkedList(head)\n", " linked_list = MyLinkedList(head)\n",
" linked_list.delete_node(head)\n", " linked_list.delete_node(head)\n",
" assert_equal(linked_list.get_all_data(), [None])\n", " self.assertEqual(linked_list.get_all_data(), [None])\n",
"\n", "\n",
" print('Test: Multiple nodes')\n", " print('Test: Multiple nodes')\n",
" linked_list = MyLinkedList(None)\n", " linked_list = MyLinkedList(None)\n",
@@ -155,7 +149,7 @@
" node2 = linked_list.insert_to_front(4)\n", " node2 = linked_list.insert_to_front(4)\n",
" node3 = linked_list.insert_to_front(1)\n", " node3 = linked_list.insert_to_front(1)\n",
" linked_list.delete_node(node1)\n", " linked_list.delete_node(node1)\n",
" assert_equal(linked_list.get_all_data(), [1, 4, 2])\n", " self.assertEqual(linked_list.get_all_data(), [1, 4, 2])\n",
"\n", "\n",
" print('Test: Multiple nodes, delete last element')\n", " print('Test: Multiple nodes, delete last element')\n",
" linked_list = MyLinkedList(None)\n", " linked_list = MyLinkedList(None)\n",
@@ -164,7 +158,7 @@
" node2 = linked_list.insert_to_front(4)\n", " node2 = linked_list.insert_to_front(4)\n",
" node3 = linked_list.insert_to_front(1)\n", " node3 = linked_list.insert_to_front(1)\n",
" linked_list.delete_node(node0)\n", " linked_list.delete_node(node0)\n",
" assert_equal(linked_list.get_all_data(), [1, 4, 3, None])\n", " self.assertEqual(linked_list.get_all_data(), [1, 4, 3, None])\n",
"\n", "\n",
" print('Success: test_delete_node')\n", " print('Success: test_delete_node')\n",
"\n", "\n",
@@ -181,9 +175,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 4,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@@ -218,9 +210,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@@ -1,19 +1,19 @@
from nose.tools import assert_equal import unittest
class TestDeleteNode(object): class TestDeleteNode(unittest.TestCase):
def test_delete_node(self): def test_delete_node(self):
print('Test: Empty list, null node to delete') print('Test: Empty list, null node to delete')
linked_list = MyLinkedList(None) linked_list = MyLinkedList(None)
linked_list.delete_node(None) linked_list.delete_node(None)
assert_equal(linked_list.get_all_data(), []) self.assertEqual(linked_list.get_all_data(), [])
print('Test: One node') print('Test: One node')
head = Node(2) head = Node(2)
linked_list = MyLinkedList(head) linked_list = MyLinkedList(head)
linked_list.delete_node(head) linked_list.delete_node(head)
assert_equal(linked_list.get_all_data(), [None]) self.assertEqual(linked_list.get_all_data(), [None])
print('Test: Multiple nodes') print('Test: Multiple nodes')
linked_list = MyLinkedList(None) linked_list = MyLinkedList(None)
@@ -22,7 +22,7 @@ class TestDeleteNode(object):
node2 = linked_list.insert_to_front(4) node2 = linked_list.insert_to_front(4)
node3 = linked_list.insert_to_front(1) node3 = linked_list.insert_to_front(1)
linked_list.delete_node(node1) linked_list.delete_node(node1)
assert_equal(linked_list.get_all_data(), [1, 4, 2]) self.assertEqual(linked_list.get_all_data(), [1, 4, 2])
print('Test: Multiple nodes, delete last element') print('Test: Multiple nodes, delete last element')
linked_list = MyLinkedList(None) linked_list = MyLinkedList(None)
@@ -31,7 +31,7 @@ class TestDeleteNode(object):
node2 = linked_list.insert_to_front(4) node2 = linked_list.insert_to_front(4)
node3 = linked_list.insert_to_front(1) node3 = linked_list.insert_to_front(1)
linked_list.delete_node(node0) linked_list.delete_node(node0)
assert_equal(linked_list.get_all_data(), [1, 4, 3, None]) self.assertEqual(linked_list.get_all_data(), [1, 4, 3, None])
print('Success: test_delete_node') print('Success: test_delete_node')

View File

@@ -88,9 +88,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class MyLinkedList(LinkedList):\n", "class MyLinkedList(LinkedList):\n",
@@ -119,34 +117,32 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# %load test_find_loop_start.py\n", "# %load test_find_loop_start.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class TestFindLoopStart(object):\n", "class TestFindLoopStart(unittest.TestCase):\n",
"\n", "\n",
" def test_find_loop_start(self):\n", " def test_find_loop_start(self):\n",
" print('Test: Empty list')\n", " print('Test: Empty list')\n",
" linked_list = MyLinkedList()\n", " linked_list = MyLinkedList()\n",
" assert_equal(linked_list.find_loop_start(), None)\n", " self.assertEqual(linked_list.find_loop_start(), None)\n",
"\n", "\n",
" print('Test: Not a circular linked list: One element')\n", " print('Test: Not a circular linked list: One element')\n",
" head = Node(1)\n", " head = Node(1)\n",
" linked_list = MyLinkedList(head)\n", " linked_list = MyLinkedList(head)\n",
" assert_equal(linked_list.find_loop_start(), None)\n", " self.assertEqual(linked_list.find_loop_start(), None)\n",
"\n", "\n",
" print('Test: Not a circular linked list: Two elements')\n", " print('Test: Not a circular linked list: Two elements')\n",
" linked_list.append(2)\n", " linked_list.append(2)\n",
" assert_equal(linked_list.find_loop_start(), None)\n", " self.assertEqual(linked_list.find_loop_start(), None)\n",
"\n", "\n",
" print('Test: Not a circular linked list: Three or more elements')\n", " print('Test: Not a circular linked list: Three or more elements')\n",
" linked_list.append(3)\n", " linked_list.append(3)\n",
" assert_equal(linked_list.find_loop_start(), None)\n", " self.assertEqual(linked_list.find_loop_start(), None)\n",
"\n", "\n",
" print('Test: General case: Circular linked list')\n", " print('Test: General case: Circular linked list')\n",
" node10 = Node(10)\n", " node10 = Node(10)\n",
@@ -162,7 +158,7 @@
" node0 = Node(0, node1)\n", " node0 = Node(0, node1)\n",
" node10.next = node3\n", " node10.next = node3\n",
" linked_list = MyLinkedList(node0)\n", " linked_list = MyLinkedList(node0)\n",
" assert_equal(linked_list.find_loop_start(), node3)\n", " self.assertEqual(linked_list.find_loop_start(), node3)\n",
"\n", "\n",
" print('Success: test_find_loop_start')\n", " print('Success: test_find_loop_start')\n",
"\n", "\n",
@@ -202,9 +198,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@@ -85,9 +85,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"%run ../linked_list/linked_list.py" "%run ../linked_list/linked_list.py"
@@ -96,9 +94,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class MyLinkedList(LinkedList):\n", "class MyLinkedList(LinkedList):\n",
@@ -134,9 +130,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@@ -148,28 +142,28 @@
], ],
"source": [ "source": [
"%%writefile test_find_loop_start.py\n", "%%writefile test_find_loop_start.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class TestFindLoopStart(object):\n", "class TestFindLoopStart(unittest.TestCase):\n",
"\n", "\n",
" def test_find_loop_start(self):\n", " def test_find_loop_start(self):\n",
" print('Test: Empty list')\n", " print('Test: Empty list')\n",
" linked_list = MyLinkedList()\n", " linked_list = MyLinkedList()\n",
" assert_equal(linked_list.find_loop_start(), None)\n", " self.assertEqual(linked_list.find_loop_start(), None)\n",
"\n", "\n",
" print('Test: Not a circular linked list: One element')\n", " print('Test: Not a circular linked list: One element')\n",
" head = Node(1)\n", " head = Node(1)\n",
" linked_list = MyLinkedList(head)\n", " linked_list = MyLinkedList(head)\n",
" assert_equal(linked_list.find_loop_start(), None)\n", " self.assertEqual(linked_list.find_loop_start(), None)\n",
"\n", "\n",
" print('Test: Not a circular linked list: Two elements')\n", " print('Test: Not a circular linked list: Two elements')\n",
" linked_list.append(2)\n", " linked_list.append(2)\n",
" assert_equal(linked_list.find_loop_start(), None)\n", " self.assertEqual(linked_list.find_loop_start(), None)\n",
"\n", "\n",
" print('Test: Not a circular linked list: Three or more elements')\n", " print('Test: Not a circular linked list: Three or more elements')\n",
" linked_list.append(3)\n", " linked_list.append(3)\n",
" assert_equal(linked_list.find_loop_start(), None)\n", " self.assertEqual(linked_list.find_loop_start(), None)\n",
"\n", "\n",
" print('Test: General case: Circular linked list')\n", " print('Test: General case: Circular linked list')\n",
" node10 = Node(10)\n", " node10 = Node(10)\n",
@@ -185,7 +179,7 @@
" node0 = Node(0, node1)\n", " node0 = Node(0, node1)\n",
" node10.next = node3\n", " node10.next = node3\n",
" linked_list = MyLinkedList(node0)\n", " linked_list = MyLinkedList(node0)\n",
" assert_equal(linked_list.find_loop_start(), node3)\n", " self.assertEqual(linked_list.find_loop_start(), node3)\n",
"\n", "\n",
" print('Success: test_find_loop_start')\n", " print('Success: test_find_loop_start')\n",
"\n", "\n",
@@ -203,7 +197,6 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 4,
"metadata": { "metadata": {
"collapsed": false,
"scrolled": true "scrolled": true
}, },
"outputs": [ "outputs": [
@@ -241,9 +234,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@@ -1,25 +1,25 @@
from nose.tools import assert_equal import unittest
class TestFindLoopStart(object): class TestFindLoopStart(unittest.TestCase):
def test_find_loop_start(self): def test_find_loop_start(self):
print('Test: Empty list') print('Test: Empty list')
linked_list = MyLinkedList() linked_list = MyLinkedList()
assert_equal(linked_list.find_loop_start(), None) self.assertEqual(linked_list.find_loop_start(), None)
print('Test: Not a circular linked list: One element') print('Test: Not a circular linked list: One element')
head = Node(1) head = Node(1)
linked_list = MyLinkedList(head) linked_list = MyLinkedList(head)
assert_equal(linked_list.find_loop_start(), None) self.assertEqual(linked_list.find_loop_start(), None)
print('Test: Not a circular linked list: Two elements') print('Test: Not a circular linked list: Two elements')
linked_list.append(2) linked_list.append(2)
assert_equal(linked_list.find_loop_start(), None) self.assertEqual(linked_list.find_loop_start(), None)
print('Test: Not a circular linked list: Three or more elements') print('Test: Not a circular linked list: Three or more elements')
linked_list.append(3) linked_list.append(3)
assert_equal(linked_list.find_loop_start(), None) self.assertEqual(linked_list.find_loop_start(), None)
print('Test: General case: Circular linked list') print('Test: General case: Circular linked list')
node10 = Node(10) node10 = Node(10)
@@ -35,7 +35,7 @@ class TestFindLoopStart(object):
node0 = Node(0, node1) node0 = Node(0, node1)
node10.next = node3 node10.next = node3
linked_list = MyLinkedList(node0) linked_list = MyLinkedList(node0)
assert_equal(linked_list.find_loop_start(), node3) self.assertEqual(linked_list.find_loop_start(), node3)
print('Success: test_find_loop_start') print('Success: test_find_loop_start')

View File

@@ -79,9 +79,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"%run ../linked_list/linked_list.py\n", "%run ../linked_list/linked_list.py\n",
@@ -91,9 +89,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class MyLinkedList(LinkedList):\n", "class MyLinkedList(LinkedList):\n",
@@ -122,36 +118,34 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# %load test_kth_to_last_elem.py\n", "# %load test_kth_to_last_elem.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class Test(object):\n", "class Test(unittest.TestCase):\n",
"\n", "\n",
" def test_kth_to_last_elem(self):\n", " def test_kth_to_last_elem(self):\n",
" print('Test: Empty list')\n", " print('Test: Empty list')\n",
" linked_list = MyLinkedList(None)\n", " linked_list = MyLinkedList(None)\n",
" assert_equal(linked_list.kth_to_last_elem(0), None)\n", " self.assertEqual(linked_list.kth_to_last_elem(0), None)\n",
"\n", "\n",
" print('Test: k >= len(list)')\n", " print('Test: k >= len(list)')\n",
" assert_equal(linked_list.kth_to_last_elem(100), None)\n", " self.assertEqual(linked_list.kth_to_last_elem(100), None)\n",
"\n", "\n",
" print('Test: One element, k = 0')\n", " print('Test: One element, k = 0')\n",
" head = Node(2)\n", " head = Node(2)\n",
" linked_list = MyLinkedList(head)\n", " linked_list = MyLinkedList(head)\n",
" assert_equal(linked_list.kth_to_last_elem(0), 2)\n", " self.assertEqual(linked_list.kth_to_last_elem(0), 2)\n",
"\n", "\n",
" print('Test: General case')\n", " print('Test: General case')\n",
" linked_list.insert_to_front(1)\n", " linked_list.insert_to_front(1)\n",
" linked_list.insert_to_front(3)\n", " linked_list.insert_to_front(3)\n",
" linked_list.insert_to_front(5)\n", " linked_list.insert_to_front(5)\n",
" linked_list.insert_to_front(7)\n", " linked_list.insert_to_front(7)\n",
" assert_equal(linked_list.kth_to_last_elem(2), 3)\n", " self.assertEqual(linked_list.kth_to_last_elem(2), 3)\n",
"\n", "\n",
" print('Success: test_kth_to_last_elem')\n", " print('Success: test_kth_to_last_elem')\n",
"\n", "\n",
@@ -191,9 +185,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@@ -85,9 +85,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"%run ../linked_list/linked_list.py" "%run ../linked_list/linked_list.py"
@@ -96,9 +94,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class MyLinkedList(LinkedList):\n", "class MyLinkedList(LinkedList):\n",
@@ -134,9 +130,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@@ -148,30 +142,30 @@
], ],
"source": [ "source": [
"%%writefile test_kth_to_last_elem.py\n", "%%writefile test_kth_to_last_elem.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class Test(object):\n", "class Test(unittest.TestCase):\n",
"\n", "\n",
" def test_kth_to_last_elem(self):\n", " def test_kth_to_last_elem(self):\n",
" print('Test: Empty list')\n", " print('Test: Empty list')\n",
" linked_list = MyLinkedList(None)\n", " linked_list = MyLinkedList(None)\n",
" assert_equal(linked_list.kth_to_last_elem(0), None)\n", " self.assertEqual(linked_list.kth_to_last_elem(0), None)\n",
"\n", "\n",
" print('Test: k >= len(list)')\n", " print('Test: k >= len(list)')\n",
" assert_equal(linked_list.kth_to_last_elem(100), None)\n", " self.assertEqual(linked_list.kth_to_last_elem(100), None)\n",
"\n", "\n",
" print('Test: One element, k = 0')\n", " print('Test: One element, k = 0')\n",
" head = Node(2)\n", " head = Node(2)\n",
" linked_list = MyLinkedList(head)\n", " linked_list = MyLinkedList(head)\n",
" assert_equal(linked_list.kth_to_last_elem(0), 2)\n", " self.assertEqual(linked_list.kth_to_last_elem(0), 2)\n",
"\n", "\n",
" print('Test: General case')\n", " print('Test: General case')\n",
" linked_list.insert_to_front(1)\n", " linked_list.insert_to_front(1)\n",
" linked_list.insert_to_front(3)\n", " linked_list.insert_to_front(3)\n",
" linked_list.insert_to_front(5)\n", " linked_list.insert_to_front(5)\n",
" linked_list.insert_to_front(7)\n", " linked_list.insert_to_front(7)\n",
" assert_equal(linked_list.kth_to_last_elem(2), 3)\n", " self.assertEqual(linked_list.kth_to_last_elem(2), 3)\n",
"\n", "\n",
" print('Success: test_kth_to_last_elem')\n", " print('Success: test_kth_to_last_elem')\n",
"\n", "\n",
@@ -188,9 +182,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 4,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@@ -225,9 +217,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@@ -1,27 +1,27 @@
from nose.tools import assert_equal import unittest
class Test(object): class Test(unittest.TestCase):
def test_kth_to_last_elem(self): def test_kth_to_last_elem(self):
print('Test: Empty list') print('Test: Empty list')
linked_list = MyLinkedList(None) linked_list = MyLinkedList(None)
assert_equal(linked_list.kth_to_last_elem(0), None) self.assertEqual(linked_list.kth_to_last_elem(0), None)
print('Test: k >= len(list)') print('Test: k >= len(list)')
assert_equal(linked_list.kth_to_last_elem(100), None) self.assertEqual(linked_list.kth_to_last_elem(100), None)
print('Test: One element, k = 0') print('Test: One element, k = 0')
head = Node(2) head = Node(2)
linked_list = MyLinkedList(head) linked_list = MyLinkedList(head)
assert_equal(linked_list.kth_to_last_elem(0), 2) self.assertEqual(linked_list.kth_to_last_elem(0), 2)
print('Test: General case') print('Test: General case')
linked_list.insert_to_front(1) linked_list.insert_to_front(1)
linked_list.insert_to_front(3) linked_list.insert_to_front(3)
linked_list.insert_to_front(5) linked_list.insert_to_front(5)
linked_list.insert_to_front(7) linked_list.insert_to_front(7)
assert_equal(linked_list.kth_to_last_elem(2), 3) self.assertEqual(linked_list.kth_to_last_elem(2), 3)
print('Success: test_kth_to_last_elem') print('Success: test_kth_to_last_elem')

View File

@@ -103,9 +103,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class Node(object):\n", "class Node(object):\n",
@@ -173,31 +171,29 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# %load test_linked_list.py\n", "# %load test_linked_list.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class TestLinkedList(object):\n", "class TestLinkedList(unittest.TestCase):\n",
"\n", "\n",
" def test_insert_to_front(self):\n", " def test_insert_to_front(self):\n",
" print('Test: insert_to_front on an empty list')\n", " print('Test: insert_to_front on an empty list')\n",
" linked_list = LinkedList(None)\n", " linked_list = LinkedList(None)\n",
" linked_list.insert_to_front(10)\n", " linked_list.insert_to_front(10)\n",
" assert_equal(linked_list.get_all_data(), [10])\n", " self.assertEqual(linked_list.get_all_data(), [10])\n",
"\n", "\n",
" print('Test: insert_to_front on a None')\n", " print('Test: insert_to_front on a None')\n",
" linked_list.insert_to_front(None)\n", " linked_list.insert_to_front(None)\n",
" assert_equal(linked_list.get_all_data(), [10])\n", " self.assertEqual(linked_list.get_all_data(), [10])\n",
"\n", "\n",
" print('Test: insert_to_front general case')\n", " print('Test: insert_to_front general case')\n",
" linked_list.insert_to_front('a')\n", " linked_list.insert_to_front('a')\n",
" linked_list.insert_to_front('bc')\n", " linked_list.insert_to_front('bc')\n",
" assert_equal(linked_list.get_all_data(), ['bc', 'a', 10])\n", " self.assertEqual(linked_list.get_all_data(), ['bc', 'a', 10])\n",
"\n", "\n",
" print('Success: test_insert_to_front\\n')\n", " print('Success: test_insert_to_front\\n')\n",
"\n", "\n",
@@ -205,16 +201,16 @@
" print('Test: append on an empty list')\n", " print('Test: append on an empty list')\n",
" linked_list = LinkedList(None)\n", " linked_list = LinkedList(None)\n",
" linked_list.append(10)\n", " linked_list.append(10)\n",
" assert_equal(linked_list.get_all_data(), [10])\n", " self.assertEqual(linked_list.get_all_data(), [10])\n",
"\n", "\n",
" print('Test: append a None')\n", " print('Test: append a None')\n",
" linked_list.append(None)\n", " linked_list.append(None)\n",
" assert_equal(linked_list.get_all_data(), [10])\n", " self.assertEqual(linked_list.get_all_data(), [10])\n",
"\n", "\n",
" print('Test: append general case')\n", " print('Test: append general case')\n",
" linked_list.append('a')\n", " linked_list.append('a')\n",
" linked_list.append('bc')\n", " linked_list.append('bc')\n",
" assert_equal(linked_list.get_all_data(), [10, 'a', 'bc'])\n", " self.assertEqual(linked_list.get_all_data(), [10, 'a', 'bc'])\n",
"\n", "\n",
" print('Success: test_append\\n')\n", " print('Success: test_append\\n')\n",
"\n", "\n",
@@ -222,13 +218,13 @@
" print('Test: find on an empty list')\n", " print('Test: find on an empty list')\n",
" linked_list = LinkedList(None)\n", " linked_list = LinkedList(None)\n",
" node = linked_list.find('a')\n", " node = linked_list.find('a')\n",
" assert_equal(node, None)\n", " self.assertEqual(node, None)\n",
"\n", "\n",
" print('Test: find a None')\n", " print('Test: find a None')\n",
" head = Node(10)\n", " head = Node(10)\n",
" linked_list = LinkedList(head)\n", " linked_list = LinkedList(head)\n",
" node = linked_list.find(None)\n", " node = linked_list.find(None)\n",
" assert_equal(node, None)\n", " self.assertEqual(node, None)\n",
"\n", "\n",
" print('Test: find general case with matches')\n", " print('Test: find general case with matches')\n",
" head = Node(10)\n", " head = Node(10)\n",
@@ -236,11 +232,11 @@
" linked_list.insert_to_front('a')\n", " linked_list.insert_to_front('a')\n",
" linked_list.insert_to_front('bc')\n", " linked_list.insert_to_front('bc')\n",
" node = linked_list.find('a')\n", " node = linked_list.find('a')\n",
" assert_equal(str(node), 'a')\n", " self.assertEqual(str(node), 'a')\n",
"\n", "\n",
" print('Test: find general case with no matches')\n", " print('Test: find general case with no matches')\n",
" node = linked_list.find('aaa')\n", " node = linked_list.find('aaa')\n",
" assert_equal(node, None)\n", " self.assertEqual(node, None)\n",
"\n", "\n",
" print('Success: test_find\\n')\n", " print('Success: test_find\\n')\n",
"\n", "\n",
@@ -248,13 +244,13 @@
" print('Test: delete on an empty list')\n", " print('Test: delete on an empty list')\n",
" linked_list = LinkedList(None)\n", " linked_list = LinkedList(None)\n",
" linked_list.delete('a')\n", " linked_list.delete('a')\n",
" assert_equal(linked_list.get_all_data(), [])\n", " self.assertEqual(linked_list.get_all_data(), [])\n",
"\n", "\n",
" print('Test: delete a None')\n", " print('Test: delete a None')\n",
" head = Node(10)\n", " head = Node(10)\n",
" linked_list = LinkedList(head)\n", " linked_list = LinkedList(head)\n",
" linked_list.delete(None)\n", " linked_list.delete(None)\n",
" assert_equal(linked_list.get_all_data(), [10])\n", " self.assertEqual(linked_list.get_all_data(), [10])\n",
"\n", "\n",
" print('Test: delete general case with matches')\n", " print('Test: delete general case with matches')\n",
" head = Node(10)\n", " head = Node(10)\n",
@@ -262,25 +258,25 @@
" linked_list.insert_to_front('a')\n", " linked_list.insert_to_front('a')\n",
" linked_list.insert_to_front('bc')\n", " linked_list.insert_to_front('bc')\n",
" linked_list.delete('a')\n", " linked_list.delete('a')\n",
" assert_equal(linked_list.get_all_data(), ['bc', 10])\n", " self.assertEqual(linked_list.get_all_data(), ['bc', 10])\n",
"\n", "\n",
" print('Test: delete general case with no matches')\n", " print('Test: delete general case with no matches')\n",
" linked_list.delete('aa')\n", " linked_list.delete('aa')\n",
" assert_equal(linked_list.get_all_data(), ['bc', 10])\n", " self.assertEqual(linked_list.get_all_data(), ['bc', 10])\n",
"\n", "\n",
" print('Success: test_delete\\n')\n", " print('Success: test_delete\\n')\n",
"\n", "\n",
" def test_len(self):\n", " def test_len(self):\n",
" print('Test: len on an empty list')\n", " print('Test: len on an empty list')\n",
" linked_list = LinkedList(None)\n", " linked_list = LinkedList(None)\n",
" assert_equal(len(linked_list), 0)\n", " self.assertEqual(len(linked_list), 0)\n",
"\n", "\n",
" print('Test: len general case')\n", " print('Test: len general case')\n",
" head = Node(10)\n", " head = Node(10)\n",
" linked_list = LinkedList(head)\n", " linked_list = LinkedList(head)\n",
" linked_list.insert_to_front('a')\n", " linked_list.insert_to_front('a')\n",
" linked_list.insert_to_front('bc')\n", " linked_list.insert_to_front('bc')\n",
" assert_equal(len(linked_list), 3)\n", " self.assertEqual(len(linked_list), 3)\n",
"\n", "\n",
" print('Success: test_len\\n')\n", " print('Success: test_len\\n')\n",
"\n", "\n",
@@ -324,9 +320,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@@ -171,9 +171,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@@ -288,9 +286,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"%run linked_list.py" "%run linked_list.py"
@@ -306,9 +302,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@@ -320,25 +314,25 @@
], ],
"source": [ "source": [
"%%writefile test_linked_list.py\n", "%%writefile test_linked_list.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class TestLinkedList(object):\n", "class TestLinkedList(unittest.TestCase):\n",
"\n", "\n",
" def test_insert_to_front(self):\n", " def test_insert_to_front(self):\n",
" print('Test: insert_to_front on an empty list')\n", " print('Test: insert_to_front on an empty list')\n",
" linked_list = LinkedList(None)\n", " linked_list = LinkedList(None)\n",
" linked_list.insert_to_front(10)\n", " linked_list.insert_to_front(10)\n",
" assert_equal(linked_list.get_all_data(), [10])\n", " self.assertEqual(linked_list.get_all_data(), [10])\n",
"\n", "\n",
" print('Test: insert_to_front on a None')\n", " print('Test: insert_to_front on a None')\n",
" linked_list.insert_to_front(None)\n", " linked_list.insert_to_front(None)\n",
" assert_equal(linked_list.get_all_data(), [10])\n", " self.assertEqual(linked_list.get_all_data(), [10])\n",
"\n", "\n",
" print('Test: insert_to_front general case')\n", " print('Test: insert_to_front general case')\n",
" linked_list.insert_to_front('a')\n", " linked_list.insert_to_front('a')\n",
" linked_list.insert_to_front('bc')\n", " linked_list.insert_to_front('bc')\n",
" assert_equal(linked_list.get_all_data(), ['bc', 'a', 10])\n", " self.assertEqual(linked_list.get_all_data(), ['bc', 'a', 10])\n",
"\n", "\n",
" print('Success: test_insert_to_front\\n')\n", " print('Success: test_insert_to_front\\n')\n",
"\n", "\n",
@@ -346,16 +340,16 @@
" print('Test: append on an empty list')\n", " print('Test: append on an empty list')\n",
" linked_list = LinkedList(None)\n", " linked_list = LinkedList(None)\n",
" linked_list.append(10)\n", " linked_list.append(10)\n",
" assert_equal(linked_list.get_all_data(), [10])\n", " self.assertEqual(linked_list.get_all_data(), [10])\n",
"\n", "\n",
" print('Test: append a None')\n", " print('Test: append a None')\n",
" linked_list.append(None)\n", " linked_list.append(None)\n",
" assert_equal(linked_list.get_all_data(), [10])\n", " self.assertEqual(linked_list.get_all_data(), [10])\n",
"\n", "\n",
" print('Test: append general case')\n", " print('Test: append general case')\n",
" linked_list.append('a')\n", " linked_list.append('a')\n",
" linked_list.append('bc')\n", " linked_list.append('bc')\n",
" assert_equal(linked_list.get_all_data(), [10, 'a', 'bc'])\n", " self.assertEqual(linked_list.get_all_data(), [10, 'a', 'bc'])\n",
"\n", "\n",
" print('Success: test_append\\n')\n", " print('Success: test_append\\n')\n",
"\n", "\n",
@@ -363,13 +357,13 @@
" print('Test: find on an empty list')\n", " print('Test: find on an empty list')\n",
" linked_list = LinkedList(None)\n", " linked_list = LinkedList(None)\n",
" node = linked_list.find('a')\n", " node = linked_list.find('a')\n",
" assert_equal(node, None)\n", " self.assertEqual(node, None)\n",
"\n", "\n",
" print('Test: find a None')\n", " print('Test: find a None')\n",
" head = Node(10)\n", " head = Node(10)\n",
" linked_list = LinkedList(head)\n", " linked_list = LinkedList(head)\n",
" node = linked_list.find(None)\n", " node = linked_list.find(None)\n",
" assert_equal(node, None)\n", " self.assertEqual(node, None)\n",
"\n", "\n",
" print('Test: find general case with matches')\n", " print('Test: find general case with matches')\n",
" head = Node(10)\n", " head = Node(10)\n",
@@ -377,11 +371,11 @@
" linked_list.insert_to_front('a')\n", " linked_list.insert_to_front('a')\n",
" linked_list.insert_to_front('bc')\n", " linked_list.insert_to_front('bc')\n",
" node = linked_list.find('a')\n", " node = linked_list.find('a')\n",
" assert_equal(str(node), 'a')\n", " self.assertEqual(str(node), 'a')\n",
"\n", "\n",
" print('Test: find general case with no matches')\n", " print('Test: find general case with no matches')\n",
" node = linked_list.find('aaa')\n", " node = linked_list.find('aaa')\n",
" assert_equal(node, None)\n", " self.assertEqual(node, None)\n",
"\n", "\n",
" print('Success: test_find\\n')\n", " print('Success: test_find\\n')\n",
"\n", "\n",
@@ -389,13 +383,13 @@
" print('Test: delete on an empty list')\n", " print('Test: delete on an empty list')\n",
" linked_list = LinkedList(None)\n", " linked_list = LinkedList(None)\n",
" linked_list.delete('a')\n", " linked_list.delete('a')\n",
" assert_equal(linked_list.get_all_data(), [])\n", " self.assertEqual(linked_list.get_all_data(), [])\n",
"\n", "\n",
" print('Test: delete a None')\n", " print('Test: delete a None')\n",
" head = Node(10)\n", " head = Node(10)\n",
" linked_list = LinkedList(head)\n", " linked_list = LinkedList(head)\n",
" linked_list.delete(None)\n", " linked_list.delete(None)\n",
" assert_equal(linked_list.get_all_data(), [10])\n", " self.assertEqual(linked_list.get_all_data(), [10])\n",
"\n", "\n",
" print('Test: delete general case with matches')\n", " print('Test: delete general case with matches')\n",
" head = Node(10)\n", " head = Node(10)\n",
@@ -403,25 +397,25 @@
" linked_list.insert_to_front('a')\n", " linked_list.insert_to_front('a')\n",
" linked_list.insert_to_front('bc')\n", " linked_list.insert_to_front('bc')\n",
" linked_list.delete('a')\n", " linked_list.delete('a')\n",
" assert_equal(linked_list.get_all_data(), ['bc', 10])\n", " self.assertEqual(linked_list.get_all_data(), ['bc', 10])\n",
"\n", "\n",
" print('Test: delete general case with no matches')\n", " print('Test: delete general case with no matches')\n",
" linked_list.delete('aa')\n", " linked_list.delete('aa')\n",
" assert_equal(linked_list.get_all_data(), ['bc', 10])\n", " self.assertEqual(linked_list.get_all_data(), ['bc', 10])\n",
"\n", "\n",
" print('Success: test_delete\\n')\n", " print('Success: test_delete\\n')\n",
"\n", "\n",
" def test_len(self):\n", " def test_len(self):\n",
" print('Test: len on an empty list')\n", " print('Test: len on an empty list')\n",
" linked_list = LinkedList(None)\n", " linked_list = LinkedList(None)\n",
" assert_equal(len(linked_list), 0)\n", " self.assertEqual(len(linked_list), 0)\n",
"\n", "\n",
" print('Test: len general case')\n", " print('Test: len general case')\n",
" head = Node(10)\n", " head = Node(10)\n",
" linked_list = LinkedList(head)\n", " linked_list = LinkedList(head)\n",
" linked_list.insert_to_front('a')\n", " linked_list.insert_to_front('a')\n",
" linked_list.insert_to_front('bc')\n", " linked_list.insert_to_front('bc')\n",
" assert_equal(len(linked_list), 3)\n", " self.assertEqual(len(linked_list), 3)\n",
"\n", "\n",
" print('Success: test_len\\n')\n", " print('Success: test_len\\n')\n",
"\n", "\n",
@@ -442,9 +436,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 4,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@@ -485,25 +477,24 @@
} }
], ],
"metadata": { "metadata": {
"celltoolbar": "Edit 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.12" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@@ -1,22 +1,22 @@
from nose.tools import assert_equal import unittest
class TestLinkedList(object): class TestLinkedList(unittest.TestCase):
def test_insert_to_front(self): def test_insert_to_front(self):
print('Test: insert_to_front on an empty list') print('Test: insert_to_front on an empty list')
linked_list = LinkedList(None) linked_list = LinkedList(None)
linked_list.insert_to_front(10) linked_list.insert_to_front(10)
assert_equal(linked_list.get_all_data(), [10]) self.assertEqual(linked_list.get_all_data(), [10])
print('Test: insert_to_front on a None') print('Test: insert_to_front on a None')
linked_list.insert_to_front(None) linked_list.insert_to_front(None)
assert_equal(linked_list.get_all_data(), [10]) self.assertEqual(linked_list.get_all_data(), [10])
print('Test: insert_to_front general case') print('Test: insert_to_front general case')
linked_list.insert_to_front('a') linked_list.insert_to_front('a')
linked_list.insert_to_front('bc') linked_list.insert_to_front('bc')
assert_equal(linked_list.get_all_data(), ['bc', 'a', 10]) self.assertEqual(linked_list.get_all_data(), ['bc', 'a', 10])
print('Success: test_insert_to_front\n') print('Success: test_insert_to_front\n')
@@ -24,16 +24,16 @@ class TestLinkedList(object):
print('Test: append on an empty list') print('Test: append on an empty list')
linked_list = LinkedList(None) linked_list = LinkedList(None)
linked_list.append(10) linked_list.append(10)
assert_equal(linked_list.get_all_data(), [10]) self.assertEqual(linked_list.get_all_data(), [10])
print('Test: append a None') print('Test: append a None')
linked_list.append(None) linked_list.append(None)
assert_equal(linked_list.get_all_data(), [10]) self.assertEqual(linked_list.get_all_data(), [10])
print('Test: append general case') print('Test: append general case')
linked_list.append('a') linked_list.append('a')
linked_list.append('bc') linked_list.append('bc')
assert_equal(linked_list.get_all_data(), [10, 'a', 'bc']) self.assertEqual(linked_list.get_all_data(), [10, 'a', 'bc'])
print('Success: test_append\n') print('Success: test_append\n')
@@ -41,13 +41,13 @@ class TestLinkedList(object):
print('Test: find on an empty list') print('Test: find on an empty list')
linked_list = LinkedList(None) linked_list = LinkedList(None)
node = linked_list.find('a') node = linked_list.find('a')
assert_equal(node, None) self.assertEqual(node, None)
print('Test: find a None') print('Test: find a None')
head = Node(10) head = Node(10)
linked_list = LinkedList(head) linked_list = LinkedList(head)
node = linked_list.find(None) node = linked_list.find(None)
assert_equal(node, None) self.assertEqual(node, None)
print('Test: find general case with matches') print('Test: find general case with matches')
head = Node(10) head = Node(10)
@@ -55,11 +55,11 @@ class TestLinkedList(object):
linked_list.insert_to_front('a') linked_list.insert_to_front('a')
linked_list.insert_to_front('bc') linked_list.insert_to_front('bc')
node = linked_list.find('a') node = linked_list.find('a')
assert_equal(str(node), 'a') self.assertEqual(str(node), 'a')
print('Test: find general case with no matches') print('Test: find general case with no matches')
node = linked_list.find('aaa') node = linked_list.find('aaa')
assert_equal(node, None) self.assertEqual(node, None)
print('Success: test_find\n') print('Success: test_find\n')
@@ -67,13 +67,13 @@ class TestLinkedList(object):
print('Test: delete on an empty list') print('Test: delete on an empty list')
linked_list = LinkedList(None) linked_list = LinkedList(None)
linked_list.delete('a') linked_list.delete('a')
assert_equal(linked_list.get_all_data(), []) self.assertEqual(linked_list.get_all_data(), [])
print('Test: delete a None') print('Test: delete a None')
head = Node(10) head = Node(10)
linked_list = LinkedList(head) linked_list = LinkedList(head)
linked_list.delete(None) linked_list.delete(None)
assert_equal(linked_list.get_all_data(), [10]) self.assertEqual(linked_list.get_all_data(), [10])
print('Test: delete general case with matches') print('Test: delete general case with matches')
head = Node(10) head = Node(10)
@@ -81,25 +81,25 @@ class TestLinkedList(object):
linked_list.insert_to_front('a') linked_list.insert_to_front('a')
linked_list.insert_to_front('bc') linked_list.insert_to_front('bc')
linked_list.delete('a') linked_list.delete('a')
assert_equal(linked_list.get_all_data(), ['bc', 10]) self.assertEqual(linked_list.get_all_data(), ['bc', 10])
print('Test: delete general case with no matches') print('Test: delete general case with no matches')
linked_list.delete('aa') linked_list.delete('aa')
assert_equal(linked_list.get_all_data(), ['bc', 10]) self.assertEqual(linked_list.get_all_data(), ['bc', 10])
print('Success: test_delete\n') print('Success: test_delete\n')
def test_len(self): def test_len(self):
print('Test: len on an empty list') print('Test: len on an empty list')
linked_list = LinkedList(None) linked_list = LinkedList(None)
assert_equal(len(linked_list), 0) self.assertEqual(len(linked_list), 0)
print('Test: len general case') print('Test: len general case')
head = Node(10) head = Node(10)
linked_list = LinkedList(head) linked_list = LinkedList(head)
linked_list.insert_to_front('a') linked_list.insert_to_front('a')
linked_list.insert_to_front('bc') linked_list.insert_to_front('bc')
assert_equal(len(linked_list), 3) self.assertEqual(len(linked_list), 3)
print('Success: test_len\n') print('Success: test_len\n')

View File

@@ -91,9 +91,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class MyLinkedList(LinkedList):\n", "class MyLinkedList(LinkedList):\n",
@@ -122,30 +120,28 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# %load test_palindrome.py\n", "# %load test_palindrome.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class TestPalindrome(object):\n", "class TestPalindrome(unittest.TestCase):\n",
"\n", "\n",
" def test_palindrome(self):\n", " def test_palindrome(self):\n",
" print('Test: Empty list')\n", " print('Test: Empty list')\n",
" linked_list = MyLinkedList()\n", " linked_list = MyLinkedList()\n",
" assert_equal(linked_list.is_palindrome(), False)\n", " self.assertEqual(linked_list.is_palindrome(), False)\n",
"\n", "\n",
" print('Test: Single element list')\n", " print('Test: Single element list')\n",
" head = Node(1)\n", " head = Node(1)\n",
" linked_list = MyLinkedList(head)\n", " linked_list = MyLinkedList(head)\n",
" assert_equal(linked_list.is_palindrome(), False)\n", " self.assertEqual(linked_list.is_palindrome(), False)\n",
"\n", "\n",
" print('Test: Two element list, not a palindrome')\n", " print('Test: Two element list, not a palindrome')\n",
" linked_list.append(2)\n", " linked_list.append(2)\n",
" assert_equal(linked_list.is_palindrome(), False)\n", " self.assertEqual(linked_list.is_palindrome(), False)\n",
"\n", "\n",
" print('Test: General case: Palindrome with even length')\n", " print('Test: General case: Palindrome with even length')\n",
" head = Node('a')\n", " head = Node('a')\n",
@@ -153,7 +149,7 @@
" linked_list.append('b')\n", " linked_list.append('b')\n",
" linked_list.append('b')\n", " linked_list.append('b')\n",
" linked_list.append('a')\n", " linked_list.append('a')\n",
" assert_equal(linked_list.is_palindrome(), True)\n", " self.assertEqual(linked_list.is_palindrome(), True)\n",
"\n", "\n",
" print('Test: General case: Palindrome with odd length')\n", " print('Test: General case: Palindrome with odd length')\n",
" head = Node(1)\n", " head = Node(1)\n",
@@ -162,7 +158,7 @@
" linked_list.append(3)\n", " linked_list.append(3)\n",
" linked_list.append(2)\n", " linked_list.append(2)\n",
" linked_list.append(1)\n", " linked_list.append(1)\n",
" assert_equal(linked_list.is_palindrome(), True)\n", " self.assertEqual(linked_list.is_palindrome(), True)\n",
"\n", "\n",
" print('Success: test_palindrome')\n", " print('Success: test_palindrome')\n",
"\n", "\n",
@@ -202,9 +198,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@@ -89,9 +89,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"%run ../linked_list/linked_list.py" "%run ../linked_list/linked_list.py"
@@ -100,9 +98,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"from __future__ import division\n", "from __future__ import division\n",
@@ -146,9 +142,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@@ -160,24 +154,24 @@
], ],
"source": [ "source": [
"%%writefile test_palindrome.py\n", "%%writefile test_palindrome.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class TestPalindrome(object):\n", "class TestPalindrome(unittest.TestCase):\n",
"\n", "\n",
" def test_palindrome(self):\n", " def test_palindrome(self):\n",
" print('Test: Empty list')\n", " print('Test: Empty list')\n",
" linked_list = MyLinkedList()\n", " linked_list = MyLinkedList()\n",
" assert_equal(linked_list.is_palindrome(), False)\n", " self.assertEqual(linked_list.is_palindrome(), False)\n",
"\n", "\n",
" print('Test: Single element list')\n", " print('Test: Single element list')\n",
" head = Node(1)\n", " head = Node(1)\n",
" linked_list = MyLinkedList(head)\n", " linked_list = MyLinkedList(head)\n",
" assert_equal(linked_list.is_palindrome(), False)\n", " self.assertEqual(linked_list.is_palindrome(), False)\n",
"\n", "\n",
" print('Test: Two element list, not a palindrome')\n", " print('Test: Two element list, not a palindrome')\n",
" linked_list.append(2)\n", " linked_list.append(2)\n",
" assert_equal(linked_list.is_palindrome(), False)\n", " self.assertEqual(linked_list.is_palindrome(), False)\n",
"\n", "\n",
" print('Test: General case: Palindrome with even length')\n", " print('Test: General case: Palindrome with even length')\n",
" head = Node('a')\n", " head = Node('a')\n",
@@ -185,7 +179,7 @@
" linked_list.append('b')\n", " linked_list.append('b')\n",
" linked_list.append('b')\n", " linked_list.append('b')\n",
" linked_list.append('a')\n", " linked_list.append('a')\n",
" assert_equal(linked_list.is_palindrome(), True)\n", " self.assertEqual(linked_list.is_palindrome(), True)\n",
"\n", "\n",
" print('Test: General case: Palindrome with odd length')\n", " print('Test: General case: Palindrome with odd length')\n",
" head = Node(1)\n", " head = Node(1)\n",
@@ -194,7 +188,7 @@
" linked_list.append(3)\n", " linked_list.append(3)\n",
" linked_list.append(2)\n", " linked_list.append(2)\n",
" linked_list.append(1)\n", " linked_list.append(1)\n",
" assert_equal(linked_list.is_palindrome(), True)\n", " self.assertEqual(linked_list.is_palindrome(), True)\n",
"\n", "\n",
" print('Success: test_palindrome')\n", " print('Success: test_palindrome')\n",
"\n", "\n",
@@ -211,9 +205,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 4,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@@ -249,9 +241,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@@ -1,21 +1,21 @@
from nose.tools import assert_equal import unittest
class TestPalindrome(object): class TestPalindrome(unittest.TestCase):
def test_palindrome(self): def test_palindrome(self):
print('Test: Empty list') print('Test: Empty list')
linked_list = MyLinkedList() linked_list = MyLinkedList()
assert_equal(linked_list.is_palindrome(), False) self.assertEqual(linked_list.is_palindrome(), False)
print('Test: Single element list') print('Test: Single element list')
head = Node(1) head = Node(1)
linked_list = MyLinkedList(head) linked_list = MyLinkedList(head)
assert_equal(linked_list.is_palindrome(), False) self.assertEqual(linked_list.is_palindrome(), False)
print('Test: Two element list, not a palindrome') print('Test: Two element list, not a palindrome')
linked_list.append(2) linked_list.append(2)
assert_equal(linked_list.is_palindrome(), False) self.assertEqual(linked_list.is_palindrome(), False)
print('Test: General case: Palindrome with even length') print('Test: General case: Palindrome with even length')
head = Node('a') head = Node('a')
@@ -23,7 +23,7 @@ class TestPalindrome(object):
linked_list.append('b') linked_list.append('b')
linked_list.append('b') linked_list.append('b')
linked_list.append('a') linked_list.append('a')
assert_equal(linked_list.is_palindrome(), True) self.assertEqual(linked_list.is_palindrome(), True)
print('Test: General case: Palindrome with odd length') print('Test: General case: Palindrome with odd length')
head = Node(1) head = Node(1)
@@ -32,7 +32,7 @@ class TestPalindrome(object):
linked_list.append(3) linked_list.append(3)
linked_list.append(2) linked_list.append(2)
linked_list.append(1) linked_list.append(1)
assert_equal(linked_list.is_palindrome(), True) self.assertEqual(linked_list.is_palindrome(), True)
print('Success: test_palindrome') print('Success: test_palindrome')

View File

@@ -95,9 +95,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class MyLinkedList(LinkedList):\n", "class MyLinkedList(LinkedList):\n",
@@ -126,32 +124,30 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# %load test_partition.py\n", "# %load test_partition.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class TestPartition(object):\n", "class TestPartition(unittest.TestCase):\n",
"\n", "\n",
" def test_partition(self):\n", " def test_partition(self):\n",
" print('Test: Empty list')\n", " print('Test: Empty list')\n",
" linked_list = MyLinkedList(None)\n", " linked_list = MyLinkedList(None)\n",
" linked_list.partition(10)\n", " linked_list.partition(10)\n",
" assert_equal(linked_list.get_all_data(), [])\n", " self.assertEqual(linked_list.get_all_data(), [])\n",
"\n", "\n",
" print('Test: One element list, left list empty')\n", " print('Test: One element list, left list empty')\n",
" linked_list = MyLinkedList(Node(5))\n", " linked_list = MyLinkedList(Node(5))\n",
" linked_list.partition(0)\n", " linked_list.partition(0)\n",
" assert_equal(linked_list.get_all_data(), [5])\n", " self.assertEqual(linked_list.get_all_data(), [5])\n",
"\n", "\n",
" print('Test: Right list is empty')\n", " print('Test: Right list is empty')\n",
" linked_list = MyLinkedList(Node(5))\n", " linked_list = MyLinkedList(Node(5))\n",
" linked_list.partition(10)\n", " linked_list.partition(10)\n",
" assert_equal(linked_list.get_all_data(), [5])\n", " self.assertEqual(linked_list.get_all_data(), [5])\n",
"\n", "\n",
" print('Test: General case')\n", " print('Test: General case')\n",
" # Partition = 10\n", " # Partition = 10\n",
@@ -167,7 +163,7 @@
" linked_list.insert_to_front(3)\n", " linked_list.insert_to_front(3)\n",
" linked_list.insert_to_front(4)\n", " linked_list.insert_to_front(4)\n",
" partitioned_list = linked_list.partition(10)\n", " partitioned_list = linked_list.partition(10)\n",
" assert_equal(partitioned_list.get_all_data(),\n", " self.assertEqual(partitioned_list.get_all_data(),\n",
" [4, 3, 8, 1, 10, 10, 13, 14, 12])\n", " [4, 3, 8, 1, 10, 10, 13, 14, 12])\n",
"\n", "\n",
" print('Success: test_partition')\n", " print('Success: test_partition')\n",
@@ -208,9 +204,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@@ -90,9 +90,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"%run ../linked_list/linked_list.py" "%run ../linked_list/linked_list.py"
@@ -101,9 +99,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class MyLinkedList(LinkedList):\n", "class MyLinkedList(LinkedList):\n",
@@ -145,9 +141,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@@ -159,26 +153,26 @@
], ],
"source": [ "source": [
"%%writefile test_partition.py\n", "%%writefile test_partition.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class TestPartition(object):\n", "class TestPartition(unittest.TestCase):\n",
"\n", "\n",
" def test_partition(self):\n", " def test_partition(self):\n",
" print('Test: Empty list')\n", " print('Test: Empty list')\n",
" linked_list = MyLinkedList(None)\n", " linked_list = MyLinkedList(None)\n",
" linked_list.partition(10)\n", " linked_list.partition(10)\n",
" assert_equal(linked_list.get_all_data(), [])\n", " self.assertEqual(linked_list.get_all_data(), [])\n",
"\n", "\n",
" print('Test: One element list, left list empty')\n", " print('Test: One element list, left list empty')\n",
" linked_list = MyLinkedList(Node(5))\n", " linked_list = MyLinkedList(Node(5))\n",
" linked_list.partition(0)\n", " linked_list.partition(0)\n",
" assert_equal(linked_list.get_all_data(), [5])\n", " self.assertEqual(linked_list.get_all_data(), [5])\n",
"\n", "\n",
" print('Test: Right list is empty')\n", " print('Test: Right list is empty')\n",
" linked_list = MyLinkedList(Node(5))\n", " linked_list = MyLinkedList(Node(5))\n",
" linked_list.partition(10)\n", " linked_list.partition(10)\n",
" assert_equal(linked_list.get_all_data(), [5])\n", " self.assertEqual(linked_list.get_all_data(), [5])\n",
"\n", "\n",
" print('Test: General case')\n", " print('Test: General case')\n",
" # Partition = 10\n", " # Partition = 10\n",
@@ -194,7 +188,7 @@
" linked_list.insert_to_front(3)\n", " linked_list.insert_to_front(3)\n",
" linked_list.insert_to_front(4)\n", " linked_list.insert_to_front(4)\n",
" partitioned_list = linked_list.partition(10)\n", " partitioned_list = linked_list.partition(10)\n",
" assert_equal(partitioned_list.get_all_data(),\n", " self.assertEqual(partitioned_list.get_all_data(),\n",
" [4, 3, 8, 1, 10, 10, 13, 14, 12])\n", " [4, 3, 8, 1, 10, 10, 13, 14, 12])\n",
"\n", "\n",
" print('Success: test_partition')\n", " print('Success: test_partition')\n",
@@ -212,9 +206,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 4,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@@ -249,9 +241,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@@ -1,23 +1,23 @@
from nose.tools import assert_equal import unittest
class TestPartition(object): class TestPartition(unittest.TestCase):
def test_partition(self): def test_partition(self):
print('Test: Empty list') print('Test: Empty list')
linked_list = MyLinkedList(None) linked_list = MyLinkedList(None)
linked_list.partition(10) linked_list.partition(10)
assert_equal(linked_list.get_all_data(), []) self.assertEqual(linked_list.get_all_data(), [])
print('Test: One element list, left list empty') print('Test: One element list, left list empty')
linked_list = MyLinkedList(Node(5)) linked_list = MyLinkedList(Node(5))
linked_list.partition(0) linked_list.partition(0)
assert_equal(linked_list.get_all_data(), [5]) self.assertEqual(linked_list.get_all_data(), [5])
print('Test: Right list is empty') print('Test: Right list is empty')
linked_list = MyLinkedList(Node(5)) linked_list = MyLinkedList(Node(5))
linked_list.partition(10) linked_list.partition(10)
assert_equal(linked_list.get_all_data(), [5]) self.assertEqual(linked_list.get_all_data(), [5])
print('Test: General case') print('Test: General case')
# Partition = 10 # Partition = 10
@@ -33,7 +33,7 @@ class TestPartition(object):
linked_list.insert_to_front(3) linked_list.insert_to_front(3)
linked_list.insert_to_front(4) linked_list.insert_to_front(4)
partitioned_list = linked_list.partition(10) partitioned_list = linked_list.partition(10)
assert_equal(partitioned_list.get_all_data(), self.assertEqual(partitioned_list.get_all_data(),
[4, 3, 8, 1, 10, 10, 13, 14, 12]) [4, 3, 8, 1, 10, 10, 13, 14, 12])
print('Success: test_partition') print('Success: test_partition')

View File

@@ -89,9 +89,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class MyLinkedList(LinkedList):\n", "class MyLinkedList(LinkedList):\n",
@@ -120,26 +118,24 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# %load test_remove_duplicates.py\n", "# %load test_remove_duplicates.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class TestRemoveDupes(object):\n", "class TestRemoveDupes(unittest.TestCase):\n",
"\n", "\n",
" def test_remove_dupes(self, linked_list):\n", " def test_remove_dupes(self, linked_list):\n",
" print('Test: Empty list')\n", " print('Test: Empty list')\n",
" linked_list.remove_dupes()\n", " linked_list.remove_dupes()\n",
" assert_equal(linked_list.get_all_data(), [])\n", " self.assertEqual(linked_list.get_all_data(), [])\n",
"\n", "\n",
" print('Test: One element list')\n", " print('Test: One element list')\n",
" linked_list.insert_to_front(2)\n", " linked_list.insert_to_front(2)\n",
" linked_list.remove_dupes()\n", " linked_list.remove_dupes()\n",
" assert_equal(linked_list.get_all_data(), [2])\n", " self.assertEqual(linked_list.get_all_data(), [2])\n",
"\n", "\n",
" print('Test: General case, duplicates')\n", " print('Test: General case, duplicates')\n",
" linked_list.insert_to_front(1)\n", " linked_list.insert_to_front(1)\n",
@@ -150,11 +146,11 @@
" linked_list.insert_to_front(1)\n", " linked_list.insert_to_front(1)\n",
" linked_list.insert_to_front(1)\n", " linked_list.insert_to_front(1)\n",
" linked_list.remove_dupes()\n", " linked_list.remove_dupes()\n",
" assert_equal(linked_list.get_all_data(), [1, 3, 2])\n", " self.assertEqual(linked_list.get_all_data(), [1, 3, 2])\n",
"\n", "\n",
" print('Test: General case, no duplicates')\n", " print('Test: General case, no duplicates')\n",
" linked_list.remove_dupes()\n", " linked_list.remove_dupes()\n",
" assert_equal(linked_list.get_all_data(), [1, 3, 2])\n", " self.assertEqual(linked_list.get_all_data(), [1, 3, 2])\n",
"\n", "\n",
" print('Success: test_remove_dupes\\n')\n", " print('Success: test_remove_dupes\\n')\n",
"\n", "\n",
@@ -195,9 +191,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@@ -105,9 +105,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"%run ../linked_list/linked_list.py" "%run ../linked_list/linked_list.py"
@@ -116,9 +114,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [], "outputs": [],
"source": [ "source": [
"class MyLinkedList(LinkedList):\n", "class MyLinkedList(LinkedList):\n",
@@ -171,9 +167,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@@ -185,20 +179,20 @@
], ],
"source": [ "source": [
"%%writefile test_remove_duplicates.py\n", "%%writefile test_remove_duplicates.py\n",
"from nose.tools import assert_equal\n", "import unittest\n",
"\n", "\n",
"\n", "\n",
"class TestRemoveDupes(object):\n", "class TestRemoveDupes(unittest.TestCase):\n",
"\n", "\n",
" def test_remove_dupes(self, linked_list):\n", " def test_remove_dupes(self, linked_list):\n",
" print('Test: Empty list')\n", " print('Test: Empty list')\n",
" linked_list.remove_dupes()\n", " linked_list.remove_dupes()\n",
" assert_equal(linked_list.get_all_data(), [])\n", " self.assertEqual(linked_list.get_all_data(), [])\n",
"\n", "\n",
" print('Test: One element list')\n", " print('Test: One element list')\n",
" linked_list.insert_to_front(2)\n", " linked_list.insert_to_front(2)\n",
" linked_list.remove_dupes()\n", " linked_list.remove_dupes()\n",
" assert_equal(linked_list.get_all_data(), [2])\n", " self.assertEqual(linked_list.get_all_data(), [2])\n",
"\n", "\n",
" print('Test: General case, duplicates')\n", " print('Test: General case, duplicates')\n",
" linked_list.insert_to_front(1)\n", " linked_list.insert_to_front(1)\n",
@@ -209,11 +203,11 @@
" linked_list.insert_to_front(1)\n", " linked_list.insert_to_front(1)\n",
" linked_list.insert_to_front(1)\n", " linked_list.insert_to_front(1)\n",
" linked_list.remove_dupes()\n", " linked_list.remove_dupes()\n",
" assert_equal(linked_list.get_all_data(), [1, 3, 2])\n", " self.assertEqual(linked_list.get_all_data(), [1, 3, 2])\n",
"\n", "\n",
" print('Test: General case, no duplicates')\n", " print('Test: General case, no duplicates')\n",
" linked_list.remove_dupes()\n", " linked_list.remove_dupes()\n",
" assert_equal(linked_list.get_all_data(), [1, 3, 2])\n", " self.assertEqual(linked_list.get_all_data(), [1, 3, 2])\n",
"\n", "\n",
" print('Success: test_remove_dupes\\n')\n", " print('Success: test_remove_dupes\\n')\n",
"\n", "\n",
@@ -231,9 +225,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 4,
"metadata": { "metadata": {},
"collapsed": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@@ -269,9 +261,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.0" "version": "3.7.2"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 0 "nbformat_minor": 1
} }

View File

@@ -1,17 +1,17 @@
from nose.tools import assert_equal import unittest
class TestRemoveDupes(object): class TestRemoveDupes(unittest.TestCase):
def test_remove_dupes(self, linked_list): def test_remove_dupes(self, linked_list):
print('Test: Empty list') print('Test: Empty list')
linked_list.remove_dupes() linked_list.remove_dupes()
assert_equal(linked_list.get_all_data(), []) self.assertEqual(linked_list.get_all_data(), [])
print('Test: One element list') print('Test: One element list')
linked_list.insert_to_front(2) linked_list.insert_to_front(2)
linked_list.remove_dupes() linked_list.remove_dupes()
assert_equal(linked_list.get_all_data(), [2]) self.assertEqual(linked_list.get_all_data(), [2])
print('Test: General case, duplicates') print('Test: General case, duplicates')
linked_list.insert_to_front(1) linked_list.insert_to_front(1)
@@ -22,11 +22,11 @@ class TestRemoveDupes(object):
linked_list.insert_to_front(1) linked_list.insert_to_front(1)
linked_list.insert_to_front(1) linked_list.insert_to_front(1)
linked_list.remove_dupes() linked_list.remove_dupes()
assert_equal(linked_list.get_all_data(), [1, 3, 2]) self.assertEqual(linked_list.get_all_data(), [1, 3, 2])
print('Test: General case, no duplicates') print('Test: General case, no duplicates')
linked_list.remove_dupes() linked_list.remove_dupes()
assert_equal(linked_list.get_all_data(), [1, 3, 2]) self.assertEqual(linked_list.get_all_data(), [1, 3, 2])
print('Success: test_remove_dupes\n') print('Success: test_remove_dupes\n')