コード例 #1
0
class TestLinkedListAddNode(unittest.TestCase):
    def setUp(self):
        head_node = LinkedList.create_node()
        self.list_without_head = LinkedList()
        self.list_with_head_node = LinkedList(head_node=head_node)

    def test_can_add_node_without_head_node(self):
        self.list_without_head.add_node()
        self.assertEqual(type(self.list_without_head.head_node), Node)

    def test_can_add_node_with_head_node(self):
        #other test cases ensure that add works however leaving this in
        #case by throwing an exception it helps track down something else
        self.list_with_head_node.add_node()
コード例 #2
0
class TestCountNodesInList(unittest.TestCase):
    def setUp(self):
        self.linked_list_without_head = LinkedList()
        self.linked_list_with_head = LinkedList(head_node=Node())
    
    def test_linked_list_without_head_has_size_zero(self):
        self.assertEqual(self.linked_list_without_head.get_size(), 0)

    def test_linked_list_with_head_only_has_size_one(self):
        self.assertEqual(self.linked_list_with_head.get_size(), 1)

    def test_linked_list_with_added_values_reports_size_correctly(self):
        self.linked_list_with_head.add_node("some data")
        self.linked_list_with_head.add_node("another node")
        self.assertEqual(self.linked_list_with_head.get_size(), 3)
        
    def tearDown(self):
        self.linked_list_without_head = None
        self.linked_list_with_head = None
コード例 #3
0
class TestLinkedListGetLastNode(unittest.TestCase):
    def setUp(self):
        self.head_node = Node()
        self.list_without_head = LinkedList()
        self.list_with_head_node = LinkedList(head_node=self.head_node)
        
    def test_list_without_head_node_returns_none(self):
        self.assertIsNone(self.list_without_head.get_last_node())

    def test_list_with_only_head_node_returns_head_node(self):
        self.assertEqual(self.list_with_head_node.get_last_node(), self.head_node)

    def test_list_with_more_than_one_node_returns_last_node(self):
        guid1 = str(uuid4())
        guid2 = str(uuid4())
        self.list_with_head_node.add_node(guid1)
        self.list_with_head_node.add_node(guid2)
        self.assertEqual(self.list_with_head_node.get_last_node().data, guid2)
    
    def tearDown(self):
        self.head_node = None
        self.list_without_head = None
        self.list_with_head_node = None