Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelkusch committed Jan 17, 2025
1 parent 9a099b9 commit e9ba724
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/test_clustered_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Test the clustered_inference module
"""

import pytest
import numpy as np
from numpy.testing import assert_almost_equal
from sklearn.cluster import FeatureAgglomeration
Expand Down Expand Up @@ -51,6 +52,12 @@ def test_clustered_inference():
n_clusters=n_clusters, connectivity=connectivity, linkage="ward"
)

# test exception
with pytest.raises(ValueError, match="Unknow method"):
beta_hat, pval, pval_corr, one_minus_pval, one_minus_pval_corr = (
clustered_inference(X_init, y, ward, n_clusters, method="test")
)

beta_hat, pval, pval_corr, one_minus_pval, one_minus_pval_corr = (
clustered_inference(X_init, y, ward, n_clusters)
)
Expand Down
33 changes: 33 additions & 0 deletions test/test_noise_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Test the noise_std module
"""

import pytest
import numpy as np
from numpy.testing import assert_almost_equal
from scipy.linalg import toeplitz
Expand Down Expand Up @@ -129,6 +130,38 @@ def test_group_reid():
assert_almost_equal(np.log(np.min(error_ratio)), 0.0, decimal=1)


def test_reid_exception():
"test the exceptions of reid"
n_samples, n_features = 50, 30
n_times = 10
sigma = 1.0
rho = 0.9

# First expe
# ##########
support_size = 2

X, y, beta, noise = multivariate_temporal_simulation(
n_samples=n_samples,
n_features=n_features,
n_times=n_times,
support_size=support_size,
sigma=sigma,
rho_noise=rho,
)

with pytest.raises(
ValueError, match="Unknown method for estimating the covariance matrix"
):
_, _ = reid(X, y, method="test", group=True)
with pytest.raises(
ValueError, match="The AR method is not compatible with the non-stationary"
):
_, _ = reid(X, y, method="AR", stationary=False, group=True)
with pytest.raises(ValueError, match="The requested AR order is to high with"):
_, _ = reid(X, y, method="AR", order=1e4, group=True)


def test_empirical_snr():
"""Computing empirical signal to noise ratio from the target `y`,
the data `X` and the true parameter vector `beta` in a simple
Expand Down

0 comments on commit e9ba724

Please sign in to comment.