Skip to content

Commit 1bdbef5

Browse files
Randomidousnbara
authored andcommitted
add test
1 parent 4d5176c commit 1bdbef5

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

tests/test_dss.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,30 @@ def _plot(before, after):
176176
plt.close("all")
177177

178178

179+
def test_dss_line_iter_no_noise():
180+
"""
181+
Test that dss_line_iter returns original data unchanged when DSS
182+
cannot improve the signal.
183+
"""
184+
sr = 200
185+
fline = 50
186+
n_samples = 9000
187+
n_chans = 10
188+
rng = np.random.RandomState(42)
189+
190+
# create data without line noise at target frequency
191+
x = rng.randn(n_samples, n_chans)
192+
x_original = x.copy()
193+
194+
x_out, n_iters = dss.dss_line_iter(x, fline, sr, n_iter_max=10)
195+
196+
assert n_iters == 0, f"Expected 0 iterations (no improvement), got {n_iters}"
197+
assert np.allclose(x_out, x_original), (
198+
"When DSS cannot improve signal, should return original data unchanged"
199+
)
200+
assert np.allclose(x, x_original), "Input data should never be mutated"
201+
202+
179203
def profile_dss_line(nkeep):
180204
"""Test line noise removal."""
181205
import cProfile

0 commit comments

Comments
 (0)