def test_delete_polyhedra(polyhedral_solid, builder):
    to_delete = [False] * polyhedral_solid.nb_polyhedra()
    to_delete[0] = True
    builder.delete_polyhedra(to_delete)
    if polyhedral_solid.nb_polyhedra() != 1:
        raise ValueError("[Test] PolyhedralSolid should have 1 polyhedron")
    if polyhedral_solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 0)) != 3:
        raise ValueError("[Test] PolyhedralSolid vertex index is not correct")
    if polyhedral_solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 1)) != 4:
        raise ValueError("[Test] PolyhedralSolid vertex index is not correct")
    if polyhedral_solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 2)) != 5:
        raise ValueError("[Test] PolyhedralSolid vertex index is not correct")
    if polyhedral_solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 3)) != 6:
        raise ValueError("[Test] PolyhedralSolid vertex index is not correct")
    if polyhedral_solid.nb_facets() != 4:
        raise ValueError("[Test] PolyhedralSolid should have 4 facets")
    if polyhedral_solid.nb_edges() != 6:
        raise ValueError("[Test] PolyhedralSolid should have 6 edges")
    attribute = polyhedral_solid.edge_attribute_manager().find_attribute_uint(
        "test")
    if attribute.value(0) != 9:
        raise ValueError(
            "[Test] Wrong value for attribute on edge 0 after vertex deletion")
    if attribute.value(1) != 10:
        raise ValueError(
            "[Test] Wrong value for attribute on edge 1 after vertex deletion")
def test_set_polyhedron_vertex(polyhedral_solid, builder):
    facet_id = polyhedral_solid.polyhedron_facet(mesh.PolyhedronFacet(0, 1))
    builder.set_polyhedron_vertex(mesh.PolyhedronVertex(0, 2), 1)
    builder.delete_isolated_facets()

    if polyhedral_solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 2)) != 1:
        raise ValueError(
            "[Test] PolyhedronVertex after set_polyhedron_vertex is wrong")
    if polyhedral_solid.polyhedron_facet_vertex(
            mesh.PolyhedronFacetVertex(mesh.PolyhedronFacet(0, 1), 1)) != 1:
        raise ValueError(
            "[Test] PolyhedronFacetVertex after set_polyhedron_vertex is wrong"
        )
    if polyhedral_solid.polyhedron_facet(mesh.PolyhedronFacet(0,
                                                              1)) != facet_id:
        raise ValueError(
            "[Test] Polyhedron facet id after set_polyhedron_vertex is wrong")
def test_delete_polyhedron(solid, builder):
    to_delete = [False] * solid.nb_polyhedra()
    to_delete[0] = True
    builder.delete_polyhedra(to_delete)
    if solid.nb_polyhedra() != 1:
        raise ValueError("[Test] TetrahedralSolid should have 1 polyhedron")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 0)) != 2:
        raise ValueError(
            "[Test] TetrahedralSolid facet vertex index is not correct")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 1)) != 1:
        raise ValueError(
            "[Test] TetrahedralSolid facet vertex index is not correct")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 2)) != 4:
        raise ValueError(
            "[Test] TetrahedralSolid facet vertex index is not correct")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 3)) != 0:
        raise ValueError(
            "[Test] TetrahedralSolid facet vertex index is not correct")
def test_permutation(solid, builder):
    builder.permute_vertices([4, 2, 1, 5, 0, 3])
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 0)) != 4:
        raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 1)) != 2:
        raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 2)) != 1:
        raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 3)) != 5:
        raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(1, 0)) != 2:
        raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(1, 1)) != 1:
        raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(1, 2)) != 5:
        raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(1, 3)) != 0:
        raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(2, 0)) != 2:
        raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(2, 1)) != 0:
        raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(2, 2)) != 5:
        raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(2, 3)) != 3:
        raise ValueError("[Test] Wrong PolyhedronVertex after vertex permute")

    builder.permute_polyhedra([2, 0, 1])
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 0)) != 2:
        raise ValueError(
            "[Test] Wrong PolyhedronVertex after polyhedron permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 1)) != 0:
        raise ValueError(
            "[Test] Wrong PolyhedronVertex after polyhedron permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 2)) != 5:
        raise ValueError(
            "[Test] Wrong PolyhedronVertex after polyhedron permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(0, 3)) != 3:
        raise ValueError(
            "[Test] Wrong PolyhedronVertex after polyhedron permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(1, 0)) != 4:
        raise ValueError(
            "[Test] Wrong PolyhedronVertex after polyhedron permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(1, 1)) != 2:
        raise ValueError(
            "[Test] Wrong PolyhedronVertex after polyhedron permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(1, 2)) != 1:
        raise ValueError(
            "[Test] Wrong PolyhedronVertex after polyhedron permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(1, 3)) != 5:
        raise ValueError(
            "[Test] Wrong PolyhedronVertex after polyhedron permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(2, 0)) != 2:
        raise ValueError(
            "[Test] Wrong PolyhedronVertex after polyhedron permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(2, 1)) != 1:
        raise ValueError(
            "[Test] Wrong PolyhedronVertex after polyhedron permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(2, 2)) != 5:
        raise ValueError(
            "[Test] Wrong PolyhedronVertex after polyhedron permute")
    if solid.polyhedron_vertex(mesh.PolyhedronVertex(2, 3)) != 0:
        raise ValueError(
            "[Test] Wrong PolyhedronVertex after polyhedron permute")

    if solid.polyhedron_adjacent(mesh.PolyhedronFacet(0, 2)):
        raise ValueError("[Test] Wrong Adjacency after polyhedron permute")
    if solid.polyhedron_adjacent(mesh.PolyhedronFacet(2, 3)) != 1:
        raise ValueError("[Test] Wrong Adjacency after polyhedron permute")
    if solid.polyhedron_adjacent(mesh.PolyhedronFacet(0, 3)) != 2:
        raise ValueError("[Test] Wrong Adjacency after polyhedron permute")
    if solid.polyhedron_adjacent(mesh.PolyhedronFacet(1, 0)) != 2:
        raise ValueError("[Test] Wrong Adjacency after polyhedron permute")

    polyhedra_5 = solid.polyhedra_around_vertex(5)
    if len(polyhedra_5) != 3:
        raise ValueError("[Test] Wrong polyhedra_5 after polyhedron permute")
    if polyhedra_5[0].polyhedron_id != 0:
        raise ValueError("[Test] Wrong polyhedra_5 after polyhedron permute")
    if polyhedra_5[0].vertex_id != 2:
        raise ValueError("[Test] Wrong polyhedra_5 after polyhedron permute")
    if polyhedra_5[1].polyhedron_id != 2:
        raise ValueError("[Test] Wrong polyhedra_5 after polyhedron permute")
    if polyhedra_5[1].vertex_id != 2:
        raise ValueError("[Test] Wrong polyhedra_5 after polyhedron permute")
    if polyhedra_5[2].polyhedron_id != 1:
        raise ValueError("[Test] Wrong polyhedra_5 after polyhedron permute")
    if polyhedra_5[2].vertex_id != 3:
        raise ValueError("[Test] Wrong polyhedra_5 after polyhedron permute")