예제 #1
0
def test_deleteNode2():
    ll = LinkedList()
    ll.append("1")
    ll.append("3")
    ll.append("2")
    ll.deleteNode("1")
    assert ll.deleteNode("4") == "Node 4 does not exists in Linked List"
    assert ll.deleteNode("8") == "Node 8 does not exists in Linked List"
    assert ll.__str__() == "{3}->{2}->None"
예제 #2
0
def test_kth_from_end_size_one():
    '''
     Where the linked list is of a size 1 

    '''
    ll = LinkedList()
    ll.append(1)
    expected = 1
    actual =ll.kth_from_end(0)
    assert expected == actual
예제 #3
0
def test_includes():
    ll = LinkedList()
    ll.insert("apples")
    ll.insert("bananas")
    ll.insert("cherries")
    assert ll.includes("bananas")
    assert ll.includes("oranges") == False
def test_to_string():
    cities = LinkedList()
    cities.insert("Beijing")
    cities.insert("Guangzhou")
    cities.insert("Chengdu")

    assert cities.__str__() == "{ Chengdu } -> { Guangzhou } -> { Beijing } -> NULL"
def test_not_includes():
    cities = LinkedList()
    cities.insert("Beijing")
    cities.insert("Guangzhou")
    cities.insert("Chengdu")

    assert not cities.includes("Shanghai")
예제 #6
0
def test_two():
    drinks = LinkedList()
    drinks.append("Coffee")
    drinks.append("Ice_Tea")
    drinks.includes("Lemonade")
    expected = False
    actual = drinks.includes("Milk")
    assert expected == actual
예제 #7
0
def test_one():
    drinks = LinkedList()
    drinks.append("Coffee")
    drinks.append("Ice_Tea")
    drinks.includes("Lemonade")
    expected = 'Coffee -> Ice_Tea -> Lemonade -> None'
    actual = drinks.__str__()
    assert expected == actual
예제 #8
0
def test_ten():
    drinks = LinkedList()
    drinks.append('Coffee')
    drinks.append('Ice_Tea')
    drinks.append('Lemonade')
    # drinks.append('Mocha')
    # drinks.insertBefore('Mocha', 'milkcheck')
    # drinks.insertAfter('Ice_Tea', 'Cocktail')
    # drinks.deleteNode('Mocha')
    drinks.get_kth_from_end_ll(0)
    expected = 'Not found, Location is less than the length of LinkedList'
    actual = expected
    assert expected == actual
예제 #9
0
def test_nine():
    drinks = LinkedList()
    drinks.append('Coffee')
    drinks.append('Ice_Tea')
    drinks.append('Lemonade')
    # drinks.append('Mocha')
    # drinks.insertBefore('Mocha', 'milkcheck')
    # drinks.insertAfter('Ice_Tea', 'Cocktail')
    # drinks.deleteNode('Mocha')
    drinks.get_kth_from_end_ll(3)
    expected = 'Coffee '
    actual = expected
    assert expected == actual
예제 #10
0
def test_kth_Happy_Path():
    test = LinkedList()
    test.append(0)
    test.append(1)
    test.append(2)
    test.append(3)
    test.append(4)
    expected = 2
    actual =test.kth_from_end(2)
    assert expected == actual
예제 #11
0
def test_insertAfter_at_middle():
    test = LinkedList()
    test.append(0)
    test.append(1)
    test.append(2)
    test.append(3)
    test.insertAfter(1,'im middle')
    expected = "{ 0 } -> { 1 } -> { im middle } -> { 2 } -> { 3 } -> { Null } -> "
    actual = test.__str__()
    assert expected == actual
예제 #12
0
def test_insertBefore_at_middle():
    test = LinkedList()
    test.append(0)
    test.append(1)
    test.append(2)
    test.append(3)
    test.insertBefore(2,'at_middle')
    expected = "{ 0 } -> { 1 } -> { at_middle } -> { 2 } -> { 3 } -> { Null } -> "
    actual = test.__str__()
    assert expected == actual
예제 #13
0
def test_insertAfter_at_last():
    test = LinkedList()
    test.append(0)
    test.append(1)
    test.append(2)
    test.append(3)
    test.insertAfter(3,'at last')
    expected = "{ 0 } -> { 1 } -> { 2 } -> { 3 } -> { at last } -> { Null } -> "
    actual = test.__str__()
    assert expected == actual
예제 #14
0
def test_zip_second_linked_list_isEmpty():
    fruits = LinkedList()
    fruits.append('apple')
    fruits.append('orange')
    fruits.append('grap')

    people = LinkedList()

    actual = zip(fruits, people)
    expexted = "{ apple } -> { orange } -> { grap } -> NULL"
    assert actual == expexted
예제 #15
0
def test_zip_first_linked_list_isEmpty():
    fruits = LinkedList()

    people = LinkedList()
    people.append('yazan')
    people.append('rami')
    people.append('hamza')

    actual = zip(fruits, people)
    expexted = "{ yazan } -> { rami } -> { hamza } -> NULL"
    assert actual == expexted
예제 #16
0
def test_insert_more():
    ll = LinkedList()
    ll.insert("apples")
    ll.insert("bananas")
    ll.insert("cherries")
    assert ll.head.value == "cherries"
    assert ll.head.next.value == "bananas"
    assert ll.head.next.next.value == "apples"
예제 #17
0
def test_instantiate_linked_list():
    """
    empty linked list
    """
    ll = LinkedList()
    
    assert ll.head == None
def test_insert():
    cities = LinkedList()
    cities.insert("Beijing")
    cities.insert("Guangzhou")
    cities.insert("Chengdu")

    assert cities.head.val == "Chengdu"
    assert cities.head.next.val == "Guangzhou"
    assert cities.head.next.next.val == "Beijing"
 def add(self, key, info):
     hashed_key = self.hash(key)
     contained = self.contains(key)
     if self.map[hashed_key] == None:
         self.map[hashed_key] = LinkedList()
     elif contained:
         self.current.info[1] = info
     return self.map[hashed_key].add((key, info))
예제 #20
0
def test_insert_after_middle():
    """
      to check if Can successfully insert after a node in the middle of the linked list
    """
    ll = LinkedList()
    ll.append('rania')
    ll.append('Moh')
    ll.append('aml')
    ll.insert_after('Moh', 33)
    assert ll.head.next.next.value == 33   
예제 #21
0
def test_insert_before_middle():
    """
      to check if Can successfully insert a node before a node located in the middle of a linked list
    """
    ll = LinkedList()
    ll.append('rania')
    ll.append('Moh')
    ll.append('aml')
    ll.insert_before('Moh', 33)
    assert ll.head.next.value == 33
예제 #22
0
def test_includes():
    ll = LinkedList()
    ll.insert(3)
    ll.insert(2)
    ll.insert(1)
    ll.insert(0)
    assert ll.includes(3) == True
    assert ll.includes(5) == False
예제 #23
0
def test_kth_with_greater_length():
    test = LinkedList()
    test.append(0)
    test.append(1)
    test.append(2)
    test.append(3)
    expected = "ValueError:your value not found"
    actual =test.kth_from_end(4)
    assert expected == actual
예제 #24
0
def test_kth_with_same_length():
    test = LinkedList()
    test.append(0)
    test.append(1)
    test.append(2)
    test.append(3)
    expected = 0
    actual =test.kth_from_end(3)
    assert expected == actual
예제 #25
0
def test_kth_from_end_at_zero():
    test = LinkedList()
    test.append(0)
    test.append(1)
    test.append(2)
    test.append(3)
    expected = 3
    actual =test.kth_from_end(0)
    assert expected == actual
예제 #26
0
def test_kth_not_positive_integer():
    test = LinkedList()
    test.append(0)
    test.append(1)
    test.append(2)
    test.append(3)
    expected = "ValueError:your value not found"
    actual =test.kth_from_end(-1)
    assert expected == actual
예제 #27
0
def test_insert():
    test = LinkedList()
    test.insert(0)
    test.insert(1)
    test.insert(2)
    test.insert(3)
    expected = "{ 3 } -> { 2 } -> { 1 } -> { 0 } -> { Null } -> "
    actual = test.__str__()
    assert expected == actual
예제 #28
0
def test_includes():
    test = LinkedList()
    test.insert(0)
    test.insert(1)
    test.insert(2)
    test.insert(3)
    expected = True
    actual = test.includes(3)
    assert expected == actual
예제 #29
0
def test_append_and_multiple_append():
    test = LinkedList()
    test.append(0)
    test.append(1)
    test.append(2)
    test.append(3)
    expected = "{ 0 } -> { 1 } -> { 2 } -> { 3 } -> { Null } -> "
    actual = test.__str__()
    assert expected == actual
예제 #30
0
def test_head():
    test = LinkedList()
    test.insert(0)
    test.insert(1)
    test.insert(2)
    test.insert(3)
    assert test.head.value == 3