Esempio n. 1
0
def test_append() -> None:
    dim = 4
    multilist = VectorLinkedList(dimension=dim)

    new_node = VectorNode(dim)
    multilist.append(new_node, 0)

    for i in range(1, dim):
        assert new_node.next[i] is new_node
        assert new_node.prev[i] is new_node
        assert multilist.sentinel.next[i] is multilist.sentinel
        assert multilist.sentinel.prev[i] is multilist.sentinel

    assert new_node.next[0] is multilist.sentinel
    assert new_node.prev[0] is multilist.sentinel
    assert multilist.sentinel.next[0] is new_node
    assert multilist.sentinel.prev[0] is new_node

    another_node = VectorNode(dim)
    multilist.append(another_node, 0)
    for i in range(1, dim):
        assert new_node.next[i] is new_node
        assert new_node.prev[i] is new_node
        assert multilist.sentinel.next[i] is multilist.sentinel
        assert multilist.sentinel.prev[i] is multilist.sentinel

    assert new_node.next[0] is another_node
    assert new_node.prev[0] is multilist.sentinel
    assert multilist.sentinel.next[0] is new_node
    assert multilist.sentinel.prev[0] is another_node
Esempio n. 2
0
def test_reinsert() -> None:
    dim = 2
    multilist = VectorLinkedList(dimension=dim)

    new_node = VectorNode(dim)
    another_node = VectorNode(dim)

    multilist.append(new_node, 0)
    multilist.append(another_node, 0)

    multilist.append(another_node, 1)
    multilist.append(new_node, 1)

    popped_node = multilist.pop(new_node, 1 + 1)

    multilist.reinsert(new_node, 0 + 1)
    assert multilist.chain_length(0) == 2
    assert multilist.chain_length(1) == 1
    assert new_node.next[0] is another_node
    assert new_node.prev[0] is multilist.sentinel
    assert another_node.prev[0] is new_node
    assert another_node.next[0] is multilist.sentinel
    assert another_node.prev[1] is multilist.sentinel
    assert another_node.next[1] is multilist.sentinel

    multilist.reinsert(popped_node, 1 + 1)
    assert multilist.chain_length(0) == 2
    assert multilist.chain_length(1) == 2
    assert another_node.prev[1] is multilist.sentinel
    assert another_node.next[1] is new_node
    assert new_node.prev[1] is another_node
    assert new_node.next[1] is multilist.sentinel
Esempio n. 3
0
def test_chain_length() -> None:
    dim = 3
    multilist = VectorLinkedList(dimension=dim)

    new_node = VectorNode(dim)
    multilist.append(new_node, 0)
    assert multilist.chain_length(0) == 1
    assert multilist.chain_length(1) == 0
    assert multilist.chain_length(2) == 0

    another_node = VectorNode(dim)
    multilist.append(another_node, 0)
    assert multilist.chain_length(0) == 2
    assert multilist.chain_length(1) == 0
    assert multilist.chain_length(2) == 0

    multilist.append(another_node, 1)
    assert multilist.chain_length(0) == 2
    assert multilist.chain_length(1) == 1
    assert multilist.chain_length(2) == 0

    multilist.append(new_node, 2)
    assert multilist.chain_length(0) == 2
    assert multilist.chain_length(1) == 1
    assert multilist.chain_length(2) == 1
Esempio n. 4
0
def test_initialize_node() -> None:
    dim = 4
    coordinates = [1.0, 2.0, 3.0]
    node = VectorNode(dim, coordinates=coordinates)

    assert isinstance(node.coordinates, np.ndarray)
    assert list(node.coordinates) == coordinates
    for entry in node.next:
        assert entry is node
    for entry in node.prev:
        assert entry is node

    assert list(node.area) == [0.0] * dim
    assert list(node.volume) == [0.0] * dim
    assert str(node) == "[1. 2. 3.]"

    node.configure_area(0)
    assert node.area[0] == 1.0
    assert node.area[1] == 0.0
    assert node.area[2] == 0.0

    node.configure_area(1)
    assert node.area[0] == 1.0
    assert node.area[1] == -1.0
    assert node.area[2] == 0.0

    node.configure_area(2)
    assert node.area[0] == 1.0
    assert node.area[1] == -1.0
    assert node.area[2] == 2.0
Esempio n. 5
0
def test_sort_by_index() -> None:
    nodes = [
        VectorNode(3, [1, 2, 3]),
        VectorNode(3, [2, 3, 1]),
        VectorNode(3, [3, 1, 2])
    ]
    new_nodes = VectorLinkedList.sort_by_index(nodes, 0)
    assert new_nodes == nodes

    new_nodes = VectorLinkedList.sort_by_index(nodes, 1)
    assert new_nodes == [nodes[2], nodes[0], nodes[1]]

    new_nodes = VectorLinkedList.sort_by_index(nodes, 2)
    assert new_nodes == [nodes[1], nodes[2], nodes[0]]
Esempio n. 6
0
def test_extend() -> None:
    dim = 1
    multilist = VectorLinkedList(dimension=dim)
    another_multilist = VectorLinkedList(dimension=dim)

    new_node = VectorNode(dim)
    another_node = VectorNode(dim)

    multilist.append(new_node, 0)
    multilist.append(another_node, 0)

    another_multilist.extend([new_node, another_node], 0)
    assert another_multilist.chain_length(0) == 2
    assert another_multilist.sentinel.next[0] is multilist.sentinel.next[0]
    assert another_multilist.sentinel.next[0].next[
        0] is multilist.sentinel.next[0].next[0]
Esempio n. 7
0
def test_update_coordinate_bounds() -> None:
    bounds = np.array([-1.0, -1.0, -1.0])
    node = VectorNode(3, coordinates=[1.0, -2.0, -1.0])
    bounds = VectorLinkedList.update_coordinate_bounds(bounds, node, 0 + 1)
    assert list(bounds) == [-1, -1, -1]
    bounds = VectorLinkedList.update_coordinate_bounds(bounds, node, 1 + 1)
    assert list(bounds) == [-1, -2, -1]
    bounds = VectorLinkedList.update_coordinate_bounds(bounds, node, 2 + 1)
    assert list(bounds) == [-1, -2, -1]
Esempio n. 8
0
def test_iterate() -> None:
    dim = 1
    multilist = VectorLinkedList(dimension=dim)

    new_node = VectorNode(dim)
    another_node = VectorNode(dim)

    multilist.append(new_node, 0)
    multilist.append(another_node, 0)
    gen = multilist.iterate(0)
    assert next(gen) is new_node
    assert next(gen) is another_node

    yet_another_node = VectorNode(dim)
    multilist.append(yet_another_node, 0)
    gen = multilist.iterate(0, start=another_node)
    assert next(gen) is another_node
    assert next(gen) is yet_another_node
Esempio n. 9
0
def test_initialize_empty_node() -> None:
    dim = 4
    node = VectorNode(dim)

    assert isinstance(node.coordinates, np.ndarray)
    for entry in node.next:
        assert entry is node
    for entry in node.prev:
        assert entry is node

    assert list(node.area) == [0.0] * dim
    assert list(node.volume) == [0.0] * dim
    assert str(node) == "None"
Esempio n. 10
0
def test_pop() -> None:
    dim = 4
    multilist = VectorLinkedList(dimension=dim)

    new_node = VectorNode(dim)
    multilist.append(new_node, 0)

    popped_node = multilist.pop(new_node, 0 + 1)
    assert popped_node is new_node
    assert new_node.next[0] is multilist.sentinel
    assert new_node.prev[0] is multilist.sentinel
    for i in range(dim):
        assert multilist.sentinel.next[i] is multilist.sentinel
        assert multilist.sentinel.prev[i] is multilist.sentinel