mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-09 10:58:02 +00:00
@@ -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):
|
||||
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])
|
||||
self.assertEqual(linked_list.get_all_data(), [10])
|
||||
|
||||
print('Test: insert_to_front on a 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')
|
||||
linked_list.insert_to_front('a')
|
||||
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')
|
||||
|
||||
@@ -24,16 +24,16 @@ class TestLinkedList(object):
|
||||
print('Test: append on an empty list')
|
||||
linked_list = LinkedList(None)
|
||||
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')
|
||||
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')
|
||||
linked_list.append('a')
|
||||
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')
|
||||
|
||||
@@ -41,13 +41,13 @@ class TestLinkedList(object):
|
||||
print('Test: find on an empty list')
|
||||
linked_list = LinkedList(None)
|
||||
node = linked_list.find('a')
|
||||
assert_equal(node, None)
|
||||
self.assertEqual(node, None)
|
||||
|
||||
print('Test: find a None')
|
||||
head = Node(10)
|
||||
linked_list = LinkedList(head)
|
||||
node = linked_list.find(None)
|
||||
assert_equal(node, None)
|
||||
self.assertEqual(node, None)
|
||||
|
||||
print('Test: find general case with matches')
|
||||
head = Node(10)
|
||||
@@ -55,11 +55,11 @@ class TestLinkedList(object):
|
||||
linked_list.insert_to_front('a')
|
||||
linked_list.insert_to_front('bc')
|
||||
node = linked_list.find('a')
|
||||
assert_equal(str(node), 'a')
|
||||
self.assertEqual(str(node), 'a')
|
||||
|
||||
print('Test: find general case with no matches')
|
||||
node = linked_list.find('aaa')
|
||||
assert_equal(node, None)
|
||||
self.assertEqual(node, None)
|
||||
|
||||
print('Success: test_find\n')
|
||||
|
||||
@@ -67,13 +67,13 @@ class TestLinkedList(object):
|
||||
print('Test: delete on an empty list')
|
||||
linked_list = LinkedList(None)
|
||||
linked_list.delete('a')
|
||||
assert_equal(linked_list.get_all_data(), [])
|
||||
self.assertEqual(linked_list.get_all_data(), [])
|
||||
|
||||
print('Test: delete a None')
|
||||
head = Node(10)
|
||||
linked_list = LinkedList(head)
|
||||
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')
|
||||
head = Node(10)
|
||||
@@ -81,25 +81,25 @@ class TestLinkedList(object):
|
||||
linked_list.insert_to_front('a')
|
||||
linked_list.insert_to_front('bc')
|
||||
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')
|
||||
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')
|
||||
|
||||
def test_len(self):
|
||||
print('Test: len on an empty list')
|
||||
linked_list = LinkedList(None)
|
||||
assert_equal(len(linked_list), 0)
|
||||
self.assertEqual(len(linked_list), 0)
|
||||
|
||||
print('Test: len general case')
|
||||
head = Node(10)
|
||||
linked_list = LinkedList(head)
|
||||
linked_list.insert_to_front('a')
|
||||
linked_list.insert_to_front('bc')
|
||||
assert_equal(len(linked_list), 3)
|
||||
self.assertEqual(len(linked_list), 3)
|
||||
|
||||
print('Success: test_len\n')
|
||||
|
||||
@@ -114,4 +114,4 @@ def main():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user