def setUp(self):

        print("\n----New test----\nList before the test:")
        self.stringList = LinkedList()
        # Prepare a test set
        s1 = Node("abc")
        s2 = Node("aBc")
        s3 = Node("ABC")
        self.stringList.sorted_list_insert(s1)
        self.stringList.sorted_list_insert(s2)
        self.stringList.sorted_list_insert(s3)
        self.stringList.print_list()
    def test_add_largest_string(self):

        largest_string = Node("zzz")
        self.assertEqual(self.stringList.sorted_list_insert(largest_string), 0)
        self.assertEqual(self.stringList.head.next.next.next, largest_string)

        self.stringList.print_list()
    def test_add_smallest_string(self):

        smallest_string = Node("AAA")

        self.assertEqual(self.stringList.sorted_list_insert(smallest_string),
                         0)
        self.assertEqual(self.stringList.head, smallest_string)
Exemple #4
0
    def assign(self, key, value):
        array_index = self.compress(self.hash(key))
        list_at_array = self.array[array_index]
        payload = Node([key, value])
        list_at_array.insert(payload)

        for item in list_at_array:
            if key == item[0]:
                key = item[0]
    def test_add_intermediate_string(self):

        intermediate_string = Node("aBc")
        expected_location = 1
        self.assertEqual(
            self.stringList.sorted_list_insert(intermediate_string), 0)

        temp = self.stringList.head
        index = 0
        while temp is not None:

            if temp != intermediate_string:
                index = index + 1
                temp = temp.next
                continue
            else:
                break
        self.assertEqual(index, expected_location)
    def test_remove_not_in_the_list(self):

        temp = Node("Not in the list")
        self.assertEqual(self.stringList.sorted_list_remove(temp), -1)
    def setUpClass(cls):

        cls.nodeTestObject = Node("A")
from Linked_list import LinkedList, Node

if __name__ == '__main__':

    stringList = LinkedList()
    # Prepare a test set
    s1 = Node("afe")
    s2 = Node("aBc")
    s3 = Node("ABC")
    # Prepare a test object
    sTest = Node("afe")
    # Prepare the list
    stringList.sorted_list_insert(s1)
    stringList.sorted_list_insert(s2)
    stringList.sorted_list_insert(s3)
    # Print initial list
    stringList.print_list()
    # add the test object
    stringList.sorted_list_insert(sTest)
    # Display the list again
    stringList.print_list()
    # Remove a certain node
    stringList.sorted_list_remove(s1)
    stringList.print_list()