mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-07 18:08:01 +00:00
@@ -95,9 +95,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class MyLinkedList(LinkedList):\n",
|
||||
@@ -126,32 +124,30 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# %load 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",
|
||||
@@ -167,7 +163,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",
|
||||
@@ -208,9 +204,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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
from nose.tools import assert_equal
|
||||
import unittest
|
||||
|
||||
|
||||
class TestPartition(object):
|
||||
class TestPartition(unittest.TestCase):
|
||||
|
||||
def test_partition(self):
|
||||
print('Test: Empty list')
|
||||
linked_list = MyLinkedList(None)
|
||||
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')
|
||||
linked_list = MyLinkedList(Node(5))
|
||||
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')
|
||||
linked_list = MyLinkedList(Node(5))
|
||||
linked_list.partition(10)
|
||||
assert_equal(linked_list.get_all_data(), [5])
|
||||
self.assertEqual(linked_list.get_all_data(), [5])
|
||||
|
||||
print('Test: General case')
|
||||
# Partition = 10
|
||||
@@ -33,7 +33,7 @@ class TestPartition(object):
|
||||
linked_list.insert_to_front(3)
|
||||
linked_list.insert_to_front(4)
|
||||
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])
|
||||
|
||||
print('Success: test_partition')
|
||||
@@ -45,4 +45,4 @@ def main():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user