Ejemplo n.º 1
0
 def test_len(self, init_vals: list):
     expected = len(init_vals)
     LList = LinkedList2.create(init_vals)
     print('init state:', LList.vals)
     print('expected (len):', expected)
     result = LList.len()
     print('result:', result)
     assert result == expected
Ejemplo n.º 2
0
 def test_clean(self, init_vals: list):
     LList = LinkedList2.create(init_vals)
     print('init state:', LList.vals)
     print('expected (clean):', [])
     LList.clean()
     result = LList.vals
     print('result:', result)
     assert result == []
Ejemplo n.º 3
0
 def test_find_all(self, init_vals: list, val):
     expected = self.get_correct_findall_nodes_vals(init_vals, val)
     LList = LinkedList2.create(init_vals)
     print('init state:', LList.vals)
     print('find all nodes with "{val}"'.format(val=val))
     print('expected:', expected)
     nodes = LList.find_all(val)
     result = [(n.prev_vals(), n.value, n.next_vals()) for n in nodes]
     print('result:', result)
     assert result == expected
Ejemplo n.º 4
0
 def test_find(self, init_vals: list, val):
     expected = self.get_correct_find_node_vals(init_vals, val)
     LList = LinkedList2.create(init_vals)
     print('init state:', LList.vals)
     print('find 1-st node with "{val}"'.format(val=val))
     print('expected:', expected)
     node = LList.find(val)
     result = ((node.prev_vals(), val, node.next_vals()) if node else None)
     print('result:', result)
     assert result == expected
Ejemplo n.º 5
0
 def test_add_in_head(self, init_vals: list, val):
     expected = list(init_vals)
     expected.insert(0, val)
     LList = LinkedList2.create(init_vals)
     print('init state:', LList.vals)
     print('insert "{val}" at the beginning'.format(val=val))
     print('expected:', expected)
     LList.add_in_head(Node(val))
     result = LList.vals
     print('result:', result)
     assert result == expected
Ejemplo n.º 6
0
 def test_delete(self, init_vals: list, del_val, del_all: bool):
     expected = self.get_correct_delete_vals(init_vals, del_val, del_all)
     LList = LinkedList2.create(init_vals)
     print('init state:', LList.vals)
     print('del {all_} with "{del_val}"'.format(
         del_val=del_val, all_="ALL nodes" if del_all else "1-st node"))
     print('expected:', expected)
     LList.delete(del_val, all=del_all)
     result = [(n.prev_vals(), n.value, n.next_vals()) for n in LList.nodes]
     print('result:', result)
     assert result == expected
Ejemplo n.º 7
0
 def test_insert(self, init_vals: list, after_val, val):
     LList = LinkedList2.create(init_vals)
     print('init state:', LList.vals)
     print('after node with "{after_val}" ins node with "{val}"'.format(
         after_val=after_val, val=val))
     afterNode = LList.find(after_val)
     expected = self.get_correct_insert_vals(init_vals, afterNode, val)
     print('expected:', expected)
     LList.insert(afterNode, Node(val))
     result = [(n.prev_vals(), n.value, n.next_vals()) for n in LList.nodes]
     print('result:', result)
     assert result == expected
Ejemplo n.º 8
0
 def test_add_in_head(self, init_vals: list, val):
     expected = list(init_vals)
     expected.insert(0, val)
     expected = [get_node_vals_view(expected, i)
                 for i, v in enumerate(expected)]
     LList = LinkedList2.create(init_vals)
     print('init state:', LList.vals)
     print('insert "{val}" at the beginning'.format(val=val))
     print('expected:', expected)
     LList.add_in_head(Node(val))
     result = [(n.prev_vals(), n.value, n.next_vals())
               for n in LList.nodes]
     print('result:', result)
     assert result == expected
Ejemplo n.º 9
0
import pytest
from itertools import product

from bidirectional_list_2.linkedList2 import Node, LinkedList2


# linked objects, can be used in tests' params
d = dict((i, v)for i, v in enumerate([1, None, [], 'test']))
l_list = LinkedList2()
[l_list.add_in_tail(Node(v)) for v in [0, None, d, 2]]

INIT_VALS = ([], [2], [1, 2, 2, 3, 2, 5],
             [None, None, None], [2, 2, 2, 2],
             [0, 0, 0], [None, 1, 4, 1, 1],
             [2, 1, 3, 2, 2], [2, 1, 2, 3, 2],
             [0, 1, 4, 3, 2], [2, 2, 0, 3, 2],
             [0, d, l_list, 3, 2], [d, 2, 0, 3, 2],
             [l_list, 0, 0], [None, 1, 4, d, l_list],)
VALS_ARGS = (None, 0, l_list, 'not listed', 2)


def get_node_vals_view(l_vals: list, ind: int):
    prev_vals = l_vals[:ind]
    next_vals = l_vals[ind+1:]
    return prev_vals, l_vals[ind], next_vals


# --------------------------- pytest settings -----------------------

class BaseTest:
    @classmethod