Example #1
0
    def test_get_value_at_index(self):
        linkedList = LinkedList([1,2,3,4])
        try:
            linkedlist.at(1)
            print("test_get_value_at_index: PASS")
        except:
            print("test_get_value_at_index: FAIL")

        self.assertEqual(linkedList.at(1), 2)
Example #2
0
 def test_remove(self):
     linkedList = LinkedList([1,2,3,4])
     linkedList.remove(1)
     self.assertEqual(linkedList.size(), 3)
     self.assertEqual(linkedList.at(1), 3)
Example #3
0
 def test_replace(self):
     linkedList = LinkedList([1,2,3,4])
     linkedList.replace(1, 5)
     self.assertEqual(linkedList.at(1), 5)
     self.assertEqual(linkedList.size(), 4)
Example #4
0
 def test_insert(self):
     linkedList = LinkedList([2,3,4])
     linkedList.insert(0, 1)
     self.assertEqual(linkedList.at(0), 1)
     self.assertEqual(linkedList.size(), 4)
Example #5
0
 def test_append(self):
     emptyList = LinkedList()
     emptyList.append(2)
     self.assertEqual(emptyList.at(0), 2)
Example #6
0
 def test_is_empty_with_populated_list(self):
     linkedList = LinkedList([1,2,3,4])
     self.assertFalse(linkedList.is_empty())
Example #7
0
 def test_is_empty(self):
     emptyList = LinkedList()
     self.assertTrue(emptyList.is_empty())
Example #8
0
 def test_size(self):
     linkedList = LinkedList([1,2,3,4])
     self.assertEqual(linkedList.size(), 4)
Example #9
0
 def test_size_empty(self):
     emptyList = LinkedList()
     self.assertEqual(emptyList.size(), 0)
Example #10
0
 def test_constructor_multiple_data_types(self):
     self.assertRaises(TypeError, LinkedList([1,'a', None]))
Example #11
0
 def test_constructor_with_data(self):
     try:
         linkedList = LinkedList([1,2,3,4,5])
         print("test_constructor_with_data: PASS")
     except:
         print("test_constructor_with_data: FAIL")
Example #12
0
 def test_empty_constructor(self):
     try:
         linkedList = LinkedList()
         print("test_constructor: PASS")
     except:
         print("test_constructor: FAIL")
Example #13
0
    def test_is_empty_with_populated_list(self):
        linkedList = LinkedList([1,2,3,4])
        self.assertFalse(linkedList.is_empty())

    def test_append(self):
        emptyList = LinkedList()
        emptyList.append(2)
        self.assertEqual(emptyList.at(0), 2)

    def test_insert(self):
        linkedList = LinkedList([2,3,4])
        linkedList.insert(0, 1)
        self.assertEqual(linkedList.at(0), 1)
        self.assertEqual(linkedList.size(), 4)

    def test_replace(self):
        linkedList = LinkedList([1,2,3,4])
        linkedList.replace(1, 5)
        self.assertEqual(linkedList.at(1), 5)
        self.assertEqual(linkedList.size(), 4)

    def test_remove(self):
        linkedList = LinkedList([1,2,3,4])
        linkedList.remove(1)
        self.assertEqual(linkedList.size(), 3)
        self.assertEqual(linkedList.at(1), 3)

    def test_clear(self)
        linkedList = LinkedList([1,2,3,4])
        linkedList.clear()
        self.assertTrue(linkedList.is_empty())