Skip to content

Commit

Permalink
tests: updating tests for structured grid datastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlangrose committed Jun 5, 2024
1 parent 3b8f8c3 commit 89554d7
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions tests/unit/datatypes/test__structured_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ def test_structured_grid_to_dict():
origin = np.array([0, 0, 0])
nsteps = np.array([10, 10, 10])
step_vector = np.array([1, 1, 1])
data = rng.random(size=(10, 10, 10))
data = {'rng': rng.random(size=(10, 10, 10))}
name = "grid_data"

grid = StructuredGrid(
origin=origin, step_vector=step_vector, nsteps=nsteps, data=data, name=name
origin=origin,
step_vector=step_vector,
nsteps=nsteps,
properties_vertex=data,
properties_cell={},
name=name,
)
grid_dict = grid.to_dict()

assert np.all(grid_dict["origin"] == origin)
assert np.all(grid_dict["nsteps"] == nsteps)
assert np.all(grid_dict["step_vector"] == step_vector)
assert np.all(grid_dict["data"] == data)
assert np.all(grid_dict["properties_vertex"] == data)
assert grid_dict["name"] == name


Expand All @@ -28,7 +33,14 @@ def test_structured_grid_maximum():
nsteps = np.array([10, 10, 10])
step_vector = np.array([1, 1, 1])

grid = StructuredGrid(origin, step_vector, nsteps, None, None)
grid = StructuredGrid(
origin=origin,
step_vector=step_vector,
nsteps=nsteps,
properties_cell={},
properties_vertex={},
name=None,
)
maximum = grid.maximum

expected_maximum = origin + nsteps * step_vector
Expand All @@ -43,10 +55,17 @@ def test_structured_grid_vtk():
origin = np.array([0, 0, 0])
nsteps = np.array([10, 10, 10])
step_vector = np.array([1, 1, 1])
data = rng.random(size=(10, 10, 10))
data = {'rng': rng.random(size=(10, 10, 10))}
name = "grid_data"

grid = StructuredGrid(origin, step_vector, nsteps, data, name)
grid = StructuredGrid(
origin=origin,
step_vector=step_vector,
nsteps=nsteps,
properties_vertex=data,
properties_cell={},
name=name,
)
vtk_grid = grid.vtk()
grid_points = vtk_grid.points
grid_origin = np.min(grid_points, axis=0)
Expand All @@ -55,7 +74,7 @@ def test_structured_grid_vtk():
assert isinstance(vtk_grid, pv.RectilinearGrid)
assert np.array_equal(vtk_grid.dimensions, nsteps)
assert np.array_equal(grid_origin, origin)
assert np.array_equal(vtk_grid[name], data.flatten(order="F"))
assert np.array_equal(vtk_grid['rng'], data['rng'].flatten(order="F"))


if __name__ == "__main__":
Expand Down

0 comments on commit 89554d7

Please sign in to comment.