Skip to content

Commit

Permalink
TST: Fix missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jwboth committed Oct 9, 2023
1 parent ac31f7a commit 9e50304
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
20 changes: 10 additions & 10 deletions tests/unit/test_arithmetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,42 @@

def test_scalar_weight_3d():

image = darsia.Image(np.ones((3, 4, 5), dtype=float), dim=3)
image = darsia.Image(np.ones((3, 4, 5), dtype=float), space_dim=3)
weight = 2.0
weighted_image = darsia.weight(image, weight)
assert np.allclose(weighted_image.img, 2 * np.ones((3, 4, 5)))


def test_array_weight_2d():

image = darsia.Image(np.ones((3, 4), dtype=float), dim=2)
weight = darsia.Image(np.random.rand(3, 4), dim=2)
image = darsia.Image(np.ones((3, 4), dtype=float), space_dim=2)
weight = darsia.Image(np.random.rand(3, 4), space_dim=2)
weighted_image = darsia.weight(image, weight)
assert np.allclose(weighted_image.img, weight.img)


def test_incompatible_weight_2d():

image = darsia.Image(np.ones((6, 8), dtype=float), dim=2, dimensions=[6, 8])
weight = darsia.Image(2 * np.ones((3, 4)), dim=2, dimensions=[6, 8])
image = darsia.Image(np.ones((6, 8), dtype=float), space_dim=2, dimensions=[6, 8])
weight = darsia.Image(2 * np.ones((3, 4)), space_dim=2, dimensions=[6, 8])

weighted_image = darsia.weight(image, weight)
assert np.allclose(weighted_image.img, 2 * np.ones((6, 8)))


def test_array_weight_3d():

image = darsia.Image(np.ones((3, 4, 5), dtype=float), dim=3)
weight = darsia.Image(np.random.rand(3, 4, 5), dim=3)
image = darsia.Image(np.ones((3, 4, 5), dtype=float), space_dim=3)
weight = darsia.Image(np.random.rand(3, 4, 5), space_dim=3)
weighted_image = darsia.weight(image, weight)
assert np.allclose(weighted_image.img, weight.img)


def test_superposition_2d():

image1 = darsia.ScalarImage(np.ones((3, 4), dtype=float), dim=2)
image2 = darsia.ScalarImage(2 * np.ones((3, 4), dtype=float), dim=2)
image3 = darsia.ScalarImage(3 * np.ones((3, 4), dtype=float), dim=2)
image1 = darsia.ScalarImage(np.ones((3, 4), dtype=float), space_dim=2)
image2 = darsia.ScalarImage(2 * np.ones((3, 4), dtype=float), space_dim=2)
image3 = darsia.ScalarImage(3 * np.ones((3, 4), dtype=float), space_dim=2)
superposed_image = darsia.superpose([image1, image2, image3])
assert np.allclose(superposed_image.img, 6 * np.ones((3, 4)))

Expand Down
24 changes: 12 additions & 12 deletions tests/unit/test_dimension_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ def test_axis_averaging_x():

image_3d = darsia.Image(
np.ones((3, 4, 5), dtype=float),
dim=3,
space_dim=3,
dimensions=[2, 3, 4],
series=False,
scalar=True,
)

averaging_axis = darsia.AxisReduction(axis="x", dim=3, mode = "sum")
averaging_index = darsia.AxisReduction(axis=2, dim=3, mode = "sum")
averaging_axis = darsia.AxisReduction(axis="x", dim=3, mode="sum")
averaging_index = darsia.AxisReduction(axis=2, dim=3, mode="sum")

image_2d_via_axis = averaging_axis(image_3d)
image_2d_via_index = averaging_index(image_3d)
Expand All @@ -39,14 +39,14 @@ def test_axis_averaging_y():

image_3d = darsia.Image(
np.ones((3, 4, 5), dtype=float),
dim=3,
space_dim=3,
dimensions=[2, 3, 4],
series=False,
scalar=True,
)

averaging_axis = darsia.AxisReduction(axis="y", dim=3, mode = "sum")
averaging_index = darsia.AxisReduction(axis=1, dim=3, mode = "sum")
averaging_axis = darsia.AxisReduction(axis="y", dim=3, mode="sum")
averaging_index = darsia.AxisReduction(axis=1, dim=3, mode="sum")

image_2d_via_axis = averaging_axis(image_3d)
image_2d_via_index = averaging_index(image_3d)
Expand All @@ -66,14 +66,14 @@ def test_axis_averaging_z():

image_3d = darsia.Image(
np.ones((3, 4, 5), dtype=float),
dim=3,
space_dim=3,
dimensions=[2, 3, 4],
series=False,
scalar=True,
)

averaging_axis = darsia.AxisReduction(axis="z", dim=3, mode = "sum")
averaging_index = darsia.AxisReduction(axis=0, dim=3, mode = "sum")
averaging_axis = darsia.AxisReduction(axis="z", dim=3, mode="sum")
averaging_index = darsia.AxisReduction(axis=0, dim=3, mode="sum")

image_2d_via_axis = averaging_axis(image_3d)
image_2d_via_index = averaging_index(image_3d)
Expand All @@ -96,15 +96,15 @@ def test_axis_averaging_series_x():

image_3d = darsia.Image(
np.ones((3, 4, 5, 6), dtype=float),
dim=3,
space_dim=3,
dimensions=[2, 3, 4],
series=True,
scalar=True,
time=[0, 1, 2, 3, 4, 5],
)

averaging_axis = darsia.AxisReduction(axis="x", dim=3, mode = "sum")
averaging_index = darsia.AxisReduction(axis=2, dim=3, mode = "sum")
averaging_axis = darsia.AxisReduction(axis="x", dim=3, mode="sum")
averaging_index = darsia.AxisReduction(axis=2, dim=3, mode="sum")

image_2d_via_axis = averaging_axis(image_3d)
image_2d_via_index = averaging_index(image_3d)
Expand Down

0 comments on commit 9e50304

Please sign in to comment.