Skip to content

Commit

Permalink
Update assertion accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
WeilerP committed Apr 12, 2024
1 parent d384414 commit 7dd3d9f
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions tests/preprocessing/test_moments.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_first_moments(
f"-layer={layer}-mode={mode}_first_moment.npy"
)
)
np.testing.assert_almost_equal(first_order_moment, ground_truth)
np.testing.assert_almost_equal(first_order_moment, ground_truth, decimal=3)

@pytest.mark.parametrize("dataset", ["pancreas", "dentategyrus"])
@pytest.mark.parametrize("n_obs", [50, 100])
Expand Down Expand Up @@ -84,7 +84,7 @@ def test_second_moments(
f"-layer={layer}-mode={mode}_second_moment.npy"
)
)
np.testing.assert_almost_equal(second_order_moment, ground_truth)
np.testing.assert_almost_equal(second_order_moment, ground_truth, decimal=2)

@pytest.mark.parametrize("dataset", ["pancreas", "dentategyrus"])
@pytest.mark.parametrize("n_obs", [50, 100])
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_passing_array_for_layer(
f"-layer={layer}-mode={mode}_first_moment.npy"
)
)
np.testing.assert_almost_equal(first_order_moment, ground_truth)
np.testing.assert_almost_equal(first_order_moment, ground_truth, decimal=3)

@pytest.mark.parametrize("sparse", [True, False])
def test_analytic_example(self, sparse: bool):
Expand Down Expand Up @@ -187,7 +187,7 @@ def _compare_adatas(self, adata_1, adata_2):
)
assert issparse(adata_1.obsp["distances"])
np.testing.assert_almost_equal(
adata_1.obsp["distances"].A, adata_2.obsp["distances"].A, decimal=4
adata_1.obsp["distances"].A, adata_2.obsp["distances"].A, decimal=3
)

# Check `.uns` is unchanged
Expand Down Expand Up @@ -266,7 +266,7 @@ def test_moment_calculation(
)
)
np.testing.assert_almost_equal(
returned_adata.layers["Mu"], ground_truth_unspliced
returned_adata.layers["Mu"], ground_truth_unspliced, decimal=4
)

ground_truth_spliced = np.load(
Expand All @@ -276,7 +276,7 @@ def test_moment_calculation(
)
)
np.testing.assert_almost_equal(
returned_adata.layers["Ms"], ground_truth_spliced
returned_adata.layers["Ms"], ground_truth_spliced, decimal=4
)

@pytest.mark.parametrize("dataset", ["pancreas", "dentategyrus"])
Expand Down Expand Up @@ -327,10 +327,10 @@ def test_neighbors_and_moments_calculation(
self._compare_adatas(returned_adata, original_adata)

np.testing.assert_almost_equal(
returned_adata.layers["Mu"], original_adata.layers["Mu"]
returned_adata.layers["Mu"], original_adata.layers["Mu"], decimal=4
)
np.testing.assert_almost_equal(
returned_adata.layers["Ms"], original_adata.layers["Ms"]
returned_adata.layers["Ms"], original_adata.layers["Ms"], decimal=4
)

expected_log = "computing neighbors\n finished ("
Expand Down Expand Up @@ -369,15 +369,19 @@ def test_raw_input(self, adata, dataset: str, n_obs: int):
f"first_moment_unspliced.npy"
)
)
np.testing.assert_almost_equal(adata.layers["Mu"], ground_truth_unspliced)
np.testing.assert_almost_equal(
adata.layers["Mu"], ground_truth_unspliced, decimal=4
)

ground_truth_spliced = np.load(
file=(
f"tests/_data/test_moments/moments/dataset={dataset}-n_obs={n_obs}"
f"first_moment_spliced.npy"
)
)
np.testing.assert_almost_equal(adata.layers["Ms"], ground_truth_spliced)
np.testing.assert_almost_equal(
adata.layers["Ms"], ground_truth_spliced, decimal=4
)


class TestSecondOrderMoments:
Expand Down Expand Up @@ -413,7 +417,7 @@ def test_output(self, adata, dataset: str, n_obs: int):
)
)
np.testing.assert_almost_equal(
second_order_moment_spliced, ground_truth_spliced
second_order_moment_spliced, ground_truth_spliced, decimal=2
)

ground_truth_mixed = np.load(
Expand All @@ -422,7 +426,9 @@ def test_output(self, adata, dataset: str, n_obs: int):
f"-n_obs={n_obs}-mode=connectivities_second_moment_mixed.npy"
)
)
np.testing.assert_almost_equal(second_order_moment_mixed, ground_truth_mixed)
np.testing.assert_almost_equal(
second_order_moment_mixed, ground_truth_mixed, decimal=5
)

@pytest.mark.parametrize("dataset", ["pancreas", "dentategyrus"])
@pytest.mark.parametrize("n_obs", [50, 100])
Expand Down Expand Up @@ -454,7 +460,9 @@ def test_adjusted(self, adata, dataset: str, n_obs: int):
)
)
np.testing.assert_almost_equal(
second_order_moment_spliced, 2 * second_order_spliced - adata.layers["Ms"]
second_order_moment_spliced,
2 * second_order_spliced - adata.layers["Ms"],
decimal=2,
)

second_order_mixed = np.load(
Expand All @@ -464,7 +472,9 @@ def test_adjusted(self, adata, dataset: str, n_obs: int):
)
)
np.testing.assert_almost_equal(
second_order_moment_mixed, 2 * second_order_mixed - adata.layers["Mu"]
second_order_moment_mixed,
2 * second_order_mixed - adata.layers["Mu"],
decimal=2,
)


Expand Down Expand Up @@ -497,4 +507,4 @@ def test_output(self, adata, dataset: str, n_obs: int):
f"-layer=unspliced-mode=connectivities_second_moment.npy"
)
)
np.testing.assert_almost_equal(second_order_moment, ground_truth)
np.testing.assert_almost_equal(second_order_moment, ground_truth, decimal=3)

0 comments on commit 7dd3d9f

Please sign in to comment.