import unittest
from node import Node
from dlinkedlist import DLinkedList
class testNode(unittest.TestCase):
def test_init(self):
a = Node(3)
self.assertEqual(a.get_data(), 3)
class testDLinkedList(unittest.TestCase):
def test_init(self):
x = DLinkedList()
x.add(1)
x.add(2)
x.add(3)
self.assertFalse(x.is_empty())
def test_search(self):
x = DLinkedList()
x.add(1)
x.add(2)
x.add(3)
self.assertTrue(x.search(2))
def test_get_last(self):
x = DLinkedList()
x.add(1)
x.add(2)
x.add(3)
self.assertEqual(x.get_last().get_data(), 1)
def test_append(self):
x = DLinkedList()
x.add(1)
x.add(2)
x.add(3)
x.append(4)
self.assertEqual(str(x), "[3, 2, 1, 4]")
def test_insert(self):
x = DLinkedList()
x.add(1)
x.add(2)
x.add(3)
x.insert(10,1)
self.assertEqual(str(x), "[3, 10, 2, 1]")
def test_pop(self):
x = DLinkedList()
x.add(1)
x.add(2)
x.add(3)
self.assertEqual(x.pop(), 1)
self.assertEqual(str(x), "[3, 2]")
if __name__ == "__main__":
unittest.main()