def test_cast_linked_list_to_list(self):
        linked_list = LinkedList()
        third = Node(3)
        second = Node(2, third)
        first = Node(1, second)
        linked_list.head = first

        assert linked_list.to_list() == [1, 2, 3]
def test_linked_list_head():
    value = 10
    node = Node(10)
    ll = LinkedList(node)
    actual = ll.head
    expected = node
    assert actual == expected
def test_linked_list_includes_true():
    value = 10
    node = Node(10)
    ll = LinkedList(node)
    actual = ll.includes(value)
    expected = True
    assert actual == expected
def test_linked_list_includes_false():
    value = 10
    other_value = 11
    node = Node(10)
    ll = LinkedList(node)
    actual = ll.includes(other_value)
    expected = False
    assert actual == expected
Esempio n. 5
0
class TestNode:
    n1 = Node(3)
    n2 = Node('test')
    n3 = Node({'key': 'value'})
    n4 = Node(False)

    def test_node1_pass(self):
        assert (self.n1.val == 3 and self.n1.next is None)

    def test_node2_pass(self):
        assert (self.n2.val == 'test' and self.n2.next is None)

    def test_node3_pass(self):
        assert (self.n3.val == {'key': 'value'} and self.n3.next is None)

    def test_node4_pass(self):
        assert (self.n4.val == False and self.n4.next is None)
    def test_create_linked_list_with_three_nodes(self):
        linked_list = LinkedList()

        linked_list.head = Node(1)
        second = Node(2)
        third = Node(3)

        assert linked_list.head.data == 1
        assert not linked_list.head.next
        assert not second.next
        assert not third.next

        linked_list.head.next = second
        second.next = third

        assert linked_list.head.next.data == 2
        assert linked_list.head.next.next.key == 3
        assert not linked_list.head.next.next.next
def test_linked_list_insert_multiple():
    value1 = 'Monday'
    value2 = 'Tuesday'
    value3 = 'Wednesday'
    ll = LinkedList(Node(value1))
    ll.insert(value2)
    ll.insert(value3)
    actual = ll.head.value
    expected = value3
    assert actual == expected
Esempio n. 8
0
def test_insert():
    newNode = Node(12)
    linked.insert(newNode.value)
    actual = linked.head.value
    expected = 12
    assert actual == expected

    actual = linked.head.next.value
    expected = 6
    assert actual == expected
Esempio n. 9
0
def test_insertAfter():
    node = Node(6)
    linked2 = LinkedList(node)
    linked2.insert(5)
    linked2.insert(4)
    linked2.insertAfter(5,9)

    actual = str(linked2)
    expected = '{4} -> {5} -> {9} -> {6} -> Null'

    assert actual == expected
Esempio n. 10
0
def test_insertBefore():
    node = Node(6)
    linked1 = LinkedList(node)
    linked1.insert(5)
    linked1.insert(4)
    linked1.insertBefore(5,9)

    actual = str(linked1)
    expected = '{4} -> {9} -> {5} -> {6} -> Null'

    assert actual == expected
Esempio n. 11
0
def test_str():
    node = Node(9)
    linked_test = LinkedList(node)
    linked_test.insert(8)
    linked_test.insert(7)
    linked_test.insert(6)

    actual = str(linked_test)
    expected = '{6} -> {7} -> {8} -> {9} -> Null'

    assert actual == expected
 def test_linked_list_with_head(self):
     node = Node("foo")
     linked_list = LinkedList(head=node)
     assert linked_list.head == node
 def test_node_connects_to_other_nodes(self):
     bar_node = Node("bar")
     foo_node = Node("foo", _next=bar_node)
     assert foo_node.next == bar_node
     assert not bar_node.next
 def test_node_has_value(self):
     node = Node("foo")
     assert node.data == "foo"
 def test_initialization(self):
     node = Node()
     assert isinstance(node, Node)
def test_node_next_is_none():
    node = Node("app")
    assert node.next is None
def test_node_value():
    node = Node("a")
    assert node.value == "a"
Esempio n. 18
0
def test_void():
    linked = LinkedList()
    actual = linked.insert(Node(None))
    value = None
    assert actual == value
def test_Node_created():
    assert "f" == Node('f').value
    assert None == Node('f').next
Esempio n. 20
0
from data_structures.linked_list.linked_list import LinkedList, Node


def test_import():
    assert LinkedList


def test_void():
    linked = LinkedList()
    actual = linked.insert(Node(None))
    value = None
    assert actual == value

node = Node(6)
linked = LinkedList(node)

def test_head():
    actual = linked.head.value
    expected = 6
    assert actual == expected

def test_insert():
    newNode = Node(12)
    linked.insert(newNode.value)
    actual = linked.head.value
    expected = 12
    assert actual == expected

    actual = linked.head.next.value
    expected = 6