<commit_before>import meshplex
import numpy as np


def test_degenerate_cell(tol=1.0e-14):
    points = [
        [0.0, 0.0],
        [0.5, 0.0],
        [1.0, 0.0],
    ]
    cells = [[0, 1, 2]]
    mesh = meshplex.Mesh(points, cells)

    ref = np.array([0.0])
    assert np.all(np.abs(mesh.cell_volumes - ref) < tol * (1.0 + ref))

    ref = np.array([[0.0], [0.0], [0.0]])
    assert np.all(np.abs(mesh.cell_volumes - ref) < tol * (1.0 + ref))

    # those are nan
    assert np.all(np.isnan(mesh.cell_circumradius))
    assert np.all(np.isnan(mesh.cell_circumcenters))


def test_degenerate_flip():
    # almost degenerate
    points = [
        [0.0, 0.0],
        [0.5, -1.0e-5],
        [1.0, 0.0],
        [0.5, 0.5],
    ]
    cells = [[0, 2, 1], [0, 2, 3]]
    mesh = meshplex.MeshTri(points, cells)
    num_flips = mesh.flip_until_delaunay()
    assert num_flips == 1
    ref = np.array([[1, 0, 3], [1, 3, 2]])
    assert np.all(mesh.cells("points") == ref)

    # make sure the same thing happens if the cell is exactly degenerate
    points = [
        [0.0, 0.0],
        [0.5, 0.0],
        [1.0, 0.0],
        [0.5, 0.5],
    ]
    cells = [[0, 2, 1], [0, 2, 3]]
    mesh = meshplex.MeshTri(points, cells)
    num_flips = mesh.flip_until_delaunay()
    assert num_flips == 1
    ref = np.array([[1, 0, 3], [1, 3, 2]])
    assert np.all(mesh.cells("points") == ref)

    exit(1)<commit_msg>more degeneracy tests<commit_after>import meshplex
import numpy as np


def test_degenerate_cell(tol=1.0e-14):
    points = [
        [0.0, 0.0],
        [0.5, 0.0],
        [1.0, 0.0],
    ]
    cells = [[0, 1, 2]]
    mesh = meshplex.Mesh(points, cells)

    ref = np.array([0.0])
    assert np.all(np.abs(mesh.cell_volumes - ref) < tol * (1.0 + ref))

    ref = np.array([[0.0], [0.0], [0.0]])
    assert np.all(np.abs(mesh.cell_volumes - ref) < tol * (1.0 + ref))

    ref = np.array([[0.0], [0.0], [0.0]])
    assert np.all(np.abs(mesh.cell_heights - ref) < tol * (1.0 + ref))

    # inf, not nan
    assert np.all(mesh.cell_circumradius == [np.inf])
    assert np.all(mesh.circumcenter_facet_distances == [[np.inf], [-np.inf], [np.inf]])
    assert np.all(
        mesh.cell_partitions
        == [[[np.inf], [-np.inf], [np.inf]], [[np.inf], [-np.inf], [np.inf]]]
    )

    # those are nan
    assert np.all(np.isnan(mesh.cell_circumcenters))


def test_degenerate_flip():
    # almost degenerate
    points = [
        [0.0, 0.0],
        [0.5, -1.0e-5],
        [1.0, 0.0],
        [0.5, 0.5],
    ]
    cells = [[0, 2, 1], [0, 2, 3]]
    mesh = meshplex.MeshTri(points, cells)
    num_flips = mesh.flip_until_delaunay()
    assert num_flips == 1
    ref = np.array([[1, 0, 3], [1, 3, 2]])
    assert np.all(mesh.cells("points") == ref)

    # make sure the same thing happens if the cell is exactly degenerate
    points = [
        [0.0, 0.0],
        [0.5, 0.0],
        [1.0, 0.0],
        [0.5, 0.5],
    ]
    cells = [[0, 2, 1], [0, 2, 3]]
    mesh = meshplex.MeshTri(points, cells)
    num_flips = mesh.flip_until_delaunay()
    assert num_flips == 1
    ref = np.array([[1, 0, 3], [1, 3, 2]])
    assert np.all(mesh.cells("points") == ref)
{'fraction_non_alphanumeric': 0.1979133733797028, 'fraction_numerical': 0.0597533986721467, 'mean_word_length': 2.2024291497975708, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7452064', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1306, 'n_words': 292}