Skip to content

Commit

Permalink
Ref: Refactor tests to not use the deprecated numpy.random.random fun…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
clemens-fricke committed Feb 20, 2024
1 parent c0bfe4b commit dcfde08
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
import gustaf as gus


@pytest.fixture
def np_rng():
return np.random.default_rng()


@pytest.fixture
def vertices_3d():
V = np.array(
Expand Down
16 changes: 8 additions & 8 deletions tests/test_vertices_and_element_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ def volumes_hexa333():


@pytest.mark.parametrize("grid", all_grids)
def test_unique_vertices(grid, request):
def test_unique_vertices(grid, np_rng, request):
"""Test unique_vertices. requires scipy."""
grid = request.getfixturevalue(grid)

# random vertices
n_ran = 50
random_vertices = np.random.random((n_ran, grid.vertices.shape[1]))
random_vertices = np_rng.random((n_ran, grid.vertices.shape[1]))
# copy original
n_original_vertices = len(grid.vertices)
original_vertices = grid.vertices.copy()
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_unique_vertices(grid, request):


@pytest.mark.parametrize("grid", all_grids)
def test_bounds(grid, request):
def test_bounds(grid, np_rng, request):
"""bounds should give you AABB"""
grid = request.getfixturevalue(grid)

Expand All @@ -123,7 +123,7 @@ def test_bounds(grid, request):
# add some random values of [0, 1)
n_original_vs = len(grid.vertices)
n_ran = 50
random_vertices = np.random.random((n_ran, grid.vertices.shape[1]))
random_vertices = np_rng.random((n_ran, grid.vertices.shape[1]))
grid.vertices = np.vstack((grid.vertices, random_vertices))

# bound shouldn't change
Expand All @@ -137,7 +137,7 @@ def test_bounds(grid, request):


@pytest.mark.parametrize("grid", all_grids)
def test_update_vertices(grid, request):
def test_update_vertices(grid, np_rng, request):
"""update vertices should keep only masked values"""
grid = request.getfixturevalue(grid)

Expand All @@ -147,7 +147,7 @@ def test_update_vertices(grid, request):
# int based mask - let's keep 3 vertices
n_original_vs = len(grid.vertices)
n_vertices_to_keep = 3
int_mask = np.random.default_rng().choice(
int_mask = np_rng.choice(
np.arange(n_original_vs),
n_vertices_to_keep,
replace=False,
Expand Down Expand Up @@ -192,13 +192,13 @@ def test_update_vertices(grid, request):


@pytest.mark.parametrize("grid", update_elements_params)
def test_update_elements(grid, request):
def test_update_elements(grid, np_rng, request):
"""keep masked elements"""
grid = request.getfixturevalue(grid)

n_original_es = len(grid.elements)
n_elements_to_keep = 3
int_mask = np.random.default_rng().choice(
int_mask = np_rng.choice(
np.arange(n_original_es),
n_elements_to_keep,
replace=False,
Expand Down

0 comments on commit dcfde08

Please sign in to comment.