mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-07 18:08:01 +00:00
@@ -90,9 +90,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%run ../linked_list/linked_list.py"
|
||||
@@ -101,9 +99,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class MyLinkedList(LinkedList):\n",
|
||||
@@ -145,9 +141,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
@@ -159,26 +153,26 @@
|
||||
],
|
||||
"source": [
|
||||
"%%writefile test_partition.py\n",
|
||||
"from nose.tools import assert_equal\n",
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestPartition(object):\n",
|
||||
"class TestPartition(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_partition(self):\n",
|
||||
" print('Test: Empty list')\n",
|
||||
" linked_list = MyLinkedList(None)\n",
|
||||
" linked_list.partition(10)\n",
|
||||
" assert_equal(linked_list.get_all_data(), [])\n",
|
||||
" self.assertEqual(linked_list.get_all_data(), [])\n",
|
||||
"\n",
|
||||
" print('Test: One element list, left list empty')\n",
|
||||
" linked_list = MyLinkedList(Node(5))\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",
|
||||
" print('Test: Right list is empty')\n",
|
||||
" linked_list = MyLinkedList(Node(5))\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",
|
||||
" print('Test: General case')\n",
|
||||
" # Partition = 10\n",
|
||||
@@ -194,7 +188,7 @@
|
||||
" linked_list.insert_to_front(3)\n",
|
||||
" linked_list.insert_to_front(4)\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",
|
||||
"\n",
|
||||
" print('Success: test_partition')\n",
|
||||
@@ -212,9 +206,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
@@ -249,9 +241,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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user