def test_get_next(): """Test node module get next method.""" from linked_list import Node test_node1 = Node(data[0]) test_node2 = Node(data[1]) test_node1.set_next(test_node2) assert test_node1.get_next() == test_node2
def test_get_next_and_get_next(self): """should be ok""" node1 = Node(1) node2 = Node(2) node1.set_next(node2) node = node1.get_next() assert node.get_data() == 2
def test_detect_cycle(): list_ = LinkedList() node1 = Node(100) node2 = Node(100) node3 = Node(100) for node in (node1, node2, node3): list_.add_to_tail(node) node3.set_next(node2) assert list_.detect_cycle() == node2
def enqueue(self, item): new_node = Node(item) if self.storage.head: new_node.set_next(self.storage.head) self.storage.head = new_node else: new_node.set_next(None) self.storage.tail = new_node self.storage.head = new_node pass
def insert_in_a_sorted_list(self, data): node = Node(data) self.length += 1 if not self.head: self.head = node return prev = None curr = self.head while (curr and curr.get_value() < data): prev = curr curr = curr.get_next() if prev: prev.set_next(node) else: self.head = node node.set_next(curr)
def test_get_next(self): ''' Tests Node method: get_next(self). ''' initial_node = Node({ 'first_name': ' Keith', 'last_name': 'LICHTEN', 'rank': 'A14', 'team': 'EBFG ' }) self.assertEqual( initial_node.get_next(), None, 'The next_node property should not be set upon init.') new_node = Node({ 'first_name': ' Tomas', 'last_name': 'STRAKA', 'rank': 'A12', 'team': '' }) initial_node.set_next(new_node) self.assertEqual(initial_node.get_next(), new_node, 'Should return the next_node property.')
def test_set_next(self): ''' Tests Node method: set_next(self, new_next). ''' initial_node = Node({ 'first_name': ' Keith', 'last_name': 'LICHTEN', 'rank': 'A14', 'team': 'EBFG ' }) self.assertEqual(initial_node.next_node, None, 'Check for next_node == None.') new_node = Node({ 'first_name': ' Tomas', 'last_name': 'STRAKA', 'rank': 'A12', 'team': '' }) initial_node.set_next(new_node) self.assertEqual(initial_node.next_node, new_node, 'The next_node property sets correctly.') self.assertEqual(new_node.next_node, None, 'The next_node property does not set recursively.')
from linked_list import Node node = Node(9) print(node) print(node.get_data()) node.set_data(10) print(node.get_data()) print("------------") print(node.get_next()) other_node = Node(0) node.set_next(other_node) print(node.get_next()) print(node.get_next().get_data())
def test_node_set_next(): node1 = Node(value=100, next=None) node2 = Node(value=200, next=None) node1.set_next(node2) assert node1.next == node2
def test_set_next(): """Test get_next method.""" from linked_list import Node new_node = Node("word", "chimichanga") new_node.set_next("next") assert new_node.get_next() == "next"