mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-07 09:58:03 +00:00
Changed discussions of NULL to None to be more Pythonic.
This commit is contained in:
@@ -52,26 +52,26 @@
|
||||
"\n",
|
||||
"### Insert to Front\n",
|
||||
"\n",
|
||||
"* Insert a NULL\n",
|
||||
"* Insert a None\n",
|
||||
"* Insert in an empty list\n",
|
||||
"* Insert in a list with one element or more elements\n",
|
||||
"\n",
|
||||
"### Append\n",
|
||||
"\n",
|
||||
"* Append a NULL\n",
|
||||
"* Append a None\n",
|
||||
"* Append in an empty list\n",
|
||||
"* Insert in a list with one element or more elements\n",
|
||||
"\n",
|
||||
"### Find\n",
|
||||
"\n",
|
||||
"* Find a NULL\n",
|
||||
"* Find a None\n",
|
||||
"* Find in an empty list\n",
|
||||
"* Find in a list with one element or more matching elements\n",
|
||||
"* Find in a list with no matches\n",
|
||||
"\n",
|
||||
"### Delete\n",
|
||||
"\n",
|
||||
"* Delete a NULL\n",
|
||||
"* Delete a None\n",
|
||||
"* Delete in an empty list\n",
|
||||
"* Delete in a list with one element or more matching elements\n",
|
||||
"* Delete in a list with no matches\n",
|
||||
@@ -191,7 +191,7 @@
|
||||
" linked_list.insert_to_front(10)\n",
|
||||
" assert_equal(linked_list.get_all_data(), [10])\n",
|
||||
"\n",
|
||||
" print('Test: insert_to_front on a NULL')\n",
|
||||
" print('Test: insert_to_front on a None')\n",
|
||||
" linked_list.insert_to_front(None)\n",
|
||||
" assert_equal(linked_list.get_all_data(), [10])\n",
|
||||
"\n",
|
||||
@@ -208,7 +208,7 @@
|
||||
" linked_list.append(10)\n",
|
||||
" assert_equal(linked_list.get_all_data(), [10])\n",
|
||||
"\n",
|
||||
" print('Test: append a NULL')\n",
|
||||
" print('Test: append a None')\n",
|
||||
" linked_list.append(None)\n",
|
||||
" assert_equal(linked_list.get_all_data(), [10])\n",
|
||||
"\n",
|
||||
@@ -225,7 +225,7 @@
|
||||
" node = linked_list.find('a')\n",
|
||||
" assert_equal(node, None)\n",
|
||||
"\n",
|
||||
" print('Test: find a NULL')\n",
|
||||
" print('Test: find a None')\n",
|
||||
" head = Node(10)\n",
|
||||
" linked_list = LinkedList(head)\n",
|
||||
" node = linked_list.find(None)\n",
|
||||
@@ -251,7 +251,7 @@
|
||||
" linked_list.delete('a')\n",
|
||||
" assert_equal(linked_list.get_all_data(), [])\n",
|
||||
"\n",
|
||||
" print('Test: delete a NULL')\n",
|
||||
" print('Test: delete a None')\n",
|
||||
" head = Node(10)\n",
|
||||
" linked_list = LinkedList(head)\n",
|
||||
" linked_list.delete(None)\n",
|
||||
|
||||
@@ -51,26 +51,26 @@
|
||||
"\n",
|
||||
"### Insert to Front\n",
|
||||
"\n",
|
||||
"* Insert a NULL\n",
|
||||
"* Insert a None\n",
|
||||
"* Insert in an empty list\n",
|
||||
"* Insert in a list with one element or more elements\n",
|
||||
"\n",
|
||||
"### Append\n",
|
||||
"\n",
|
||||
"* Append a NULL\n",
|
||||
"* Append a None\n",
|
||||
"* Append in an empty list\n",
|
||||
"* Insert in a list with one element or more elements\n",
|
||||
"\n",
|
||||
"### Find\n",
|
||||
"\n",
|
||||
"* Find a NULL\n",
|
||||
"* Find a None\n",
|
||||
"* Find in an empty list\n",
|
||||
"* Find in a list with one element or more matching elements\n",
|
||||
"* Find in a list with no matches\n",
|
||||
"\n",
|
||||
"### Delete\n",
|
||||
"\n",
|
||||
"* Delete a NULL\n",
|
||||
"* Delete a None\n",
|
||||
"* Delete in an empty list\n",
|
||||
"* Delete in a list with one element or more matching elements\n",
|
||||
"* Delete in a list with no matches\n",
|
||||
@@ -93,7 +93,7 @@
|
||||
"\n",
|
||||
"### Insert to Front\n",
|
||||
"\n",
|
||||
"* If the data we are inserting is NULL, return\n",
|
||||
"* If the data we are inserting is None, return\n",
|
||||
"* Create a node with the input data\n",
|
||||
"* If this is an empty list\n",
|
||||
" * Assign the head to the node\n",
|
||||
@@ -107,7 +107,7 @@
|
||||
"\n",
|
||||
"### Append\n",
|
||||
"\n",
|
||||
"* If the data we are inserting is NULL, return\n",
|
||||
"* If the data we are inserting is None, return\n",
|
||||
"* Create a node with the input data\n",
|
||||
"* If this is an empty list\n",
|
||||
" * Assign the head to the node\n",
|
||||
@@ -121,7 +121,7 @@
|
||||
"\n",
|
||||
"### Find\n",
|
||||
"\n",
|
||||
"* If data we are finding is NULL, return\n",
|
||||
"* If data we are finding is None, return\n",
|
||||
"* If the list is empty, return\n",
|
||||
"* For each node\n",
|
||||
" * If the value is a match, return it\n",
|
||||
@@ -133,7 +133,7 @@
|
||||
"\n",
|
||||
"### Delete\n",
|
||||
"\n",
|
||||
"* If data we are deleting is NULL, return\n",
|
||||
"* If data we are deleting is None, return\n",
|
||||
"* If the list is empty, return\n",
|
||||
"* For each node, keep track of previous and current node\n",
|
||||
" * If the value we are deleting is a match in the current node\n",
|
||||
@@ -323,7 +323,7 @@
|
||||
" linked_list.insert_to_front(10)\n",
|
||||
" assert_equal(linked_list.get_all_data(), [10])\n",
|
||||
"\n",
|
||||
" print('Test: insert_to_front on a NULL')\n",
|
||||
" print('Test: insert_to_front on a None')\n",
|
||||
" linked_list.insert_to_front(None)\n",
|
||||
" assert_equal(linked_list.get_all_data(), [10])\n",
|
||||
"\n",
|
||||
@@ -340,7 +340,7 @@
|
||||
" linked_list.append(10)\n",
|
||||
" assert_equal(linked_list.get_all_data(), [10])\n",
|
||||
"\n",
|
||||
" print('Test: append a NULL')\n",
|
||||
" print('Test: append a None')\n",
|
||||
" linked_list.append(None)\n",
|
||||
" assert_equal(linked_list.get_all_data(), [10])\n",
|
||||
"\n",
|
||||
@@ -357,7 +357,7 @@
|
||||
" node = linked_list.find('a')\n",
|
||||
" assert_equal(node, None)\n",
|
||||
"\n",
|
||||
" print('Test: find a NULL')\n",
|
||||
" print('Test: find a None')\n",
|
||||
" head = Node(10)\n",
|
||||
" linked_list = LinkedList(head)\n",
|
||||
" node = linked_list.find(None)\n",
|
||||
@@ -383,7 +383,7 @@
|
||||
" linked_list.delete('a')\n",
|
||||
" assert_equal(linked_list.get_all_data(), [])\n",
|
||||
"\n",
|
||||
" print('Test: delete a NULL')\n",
|
||||
" print('Test: delete a None')\n",
|
||||
" head = Node(10)\n",
|
||||
" linked_list = LinkedList(head)\n",
|
||||
" linked_list.delete(None)\n",
|
||||
@@ -441,23 +441,23 @@
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Test: insert_to_front on an empty list\n",
|
||||
"Test: insert_to_front on a NULL\n",
|
||||
"Test: insert_to_front on a None\n",
|
||||
"Test: insert_to_front general case\n",
|
||||
"Success: test_insert_to_front\n",
|
||||
"\n",
|
||||
"Test: append on an empty list\n",
|
||||
"Test: append a NULL\n",
|
||||
"Test: append a None\n",
|
||||
"Test: append general case\n",
|
||||
"Success: test_append\n",
|
||||
"\n",
|
||||
"Test: find on an empty list\n",
|
||||
"Test: find a NULL\n",
|
||||
"Test: find a None\n",
|
||||
"Test: find general case with matches\n",
|
||||
"Test: find general case with no matches\n",
|
||||
"Success: test_find\n",
|
||||
"\n",
|
||||
"Test: delete on an empty list\n",
|
||||
"Test: delete a NULL\n",
|
||||
"Test: delete a None\n",
|
||||
"Test: delete general case with matches\n",
|
||||
"Test: delete general case with no matches\n",
|
||||
"Success: test_delete\n",
|
||||
|
||||
@@ -2,14 +2,14 @@ from nose.tools import assert_equal
|
||||
|
||||
|
||||
class TestLinkedList(object):
|
||||
|
||||
|
||||
def test_insert_to_front(self):
|
||||
print('Test: insert_to_front on an empty list')
|
||||
linked_list = LinkedList(None)
|
||||
linked_list.insert_to_front(10)
|
||||
assert_equal(linked_list.get_all_data(), [10])
|
||||
|
||||
print('Test: insert_to_front on a NULL')
|
||||
print('Test: insert_to_front on a None')
|
||||
linked_list.insert_to_front(None)
|
||||
assert_equal(linked_list.get_all_data(), [10])
|
||||
|
||||
@@ -17,16 +17,16 @@ class TestLinkedList(object):
|
||||
linked_list.insert_to_front('a')
|
||||
linked_list.insert_to_front('bc')
|
||||
assert_equal(linked_list.get_all_data(), ['bc', 'a', 10])
|
||||
|
||||
|
||||
print('Success: test_insert_to_front\n')
|
||||
|
||||
|
||||
def test_append(self):
|
||||
print('Test: append on an empty list')
|
||||
linked_list = LinkedList(None)
|
||||
linked_list.append(10)
|
||||
assert_equal(linked_list.get_all_data(), [10])
|
||||
|
||||
print('Test: append a NULL')
|
||||
print('Test: append a None')
|
||||
linked_list.append(None)
|
||||
assert_equal(linked_list.get_all_data(), [10])
|
||||
|
||||
@@ -34,16 +34,16 @@ class TestLinkedList(object):
|
||||
linked_list.append('a')
|
||||
linked_list.append('bc')
|
||||
assert_equal(linked_list.get_all_data(), [10, 'a', 'bc'])
|
||||
|
||||
|
||||
print('Success: test_append\n')
|
||||
|
||||
|
||||
def test_find(self):
|
||||
print('Test: find on an empty list')
|
||||
linked_list = LinkedList(None)
|
||||
node = linked_list.find('a')
|
||||
assert_equal(node, None)
|
||||
|
||||
print('Test: find a NULL')
|
||||
print('Test: find a None')
|
||||
head = Node(10)
|
||||
linked_list = LinkedList(head)
|
||||
node = linked_list.find(None)
|
||||
@@ -60,16 +60,16 @@ class TestLinkedList(object):
|
||||
print('Test: find general case with no matches')
|
||||
node = linked_list.find('aaa')
|
||||
assert_equal(node, None)
|
||||
|
||||
|
||||
print('Success: test_find\n')
|
||||
|
||||
|
||||
def test_delete(self):
|
||||
print('Test: delete on an empty list')
|
||||
linked_list = LinkedList(None)
|
||||
linked_list.delete('a')
|
||||
assert_equal(linked_list.get_all_data(), [])
|
||||
|
||||
print('Test: delete a NULL')
|
||||
print('Test: delete a None')
|
||||
head = Node(10)
|
||||
linked_list = LinkedList(head)
|
||||
linked_list.delete(None)
|
||||
@@ -86,9 +86,9 @@ class TestLinkedList(object):
|
||||
print('Test: delete general case with no matches')
|
||||
linked_list.delete('aa')
|
||||
assert_equal(linked_list.get_all_data(), ['bc', 10])
|
||||
|
||||
|
||||
print('Success: test_delete\n')
|
||||
|
||||
|
||||
def test_len(self):
|
||||
print('Test: len on an empty list')
|
||||
linked_list = LinkedList(None)
|
||||
@@ -100,7 +100,7 @@ class TestLinkedList(object):
|
||||
linked_list.insert_to_front('a')
|
||||
linked_list.insert_to_front('bc')
|
||||
assert_equal(len(linked_list), 3)
|
||||
|
||||
|
||||
print('Success: test_len\n')
|
||||
|
||||
def main():
|
||||
@@ -110,6 +110,6 @@ def main():
|
||||
test.test_find()
|
||||
test.test_delete()
|
||||
test.test_len()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user