Skip to content

Commit 72a10a2

Browse files
committed
add test
1 parent fdbbb99 commit 72a10a2

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

tests/test_dss.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,35 @@ 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 with NO line noise at target frequency
191+
# Pure random noise - DSS should recognize it can't help
192+
x = rng.randn(n_samples, n_chans)
193+
194+
# Store original
195+
x_original = x.copy()
196+
197+
# Run DSS - should detect that it makes things worse on first iteration
198+
x_out, n_iters = dss.dss_line_iter(x, fline, sr, n_iter_max=10)
199+
200+
# Should return original data with 0 iterations
201+
assert n_iters == 0, f"Expected 0 iterations (no improvement), got {n_iters}"
202+
assert np.allclose(x_out, x_original), (
203+
"When DSS cannot improve signal, should return original data unchanged"
204+
)
205+
assert np.allclose(x, x_original), "Input data should never be mutated"
206+
207+
179208
def profile_dss_line(nkeep):
180209
"""Test line noise removal."""
181210
import cProfile

0 commit comments

Comments
 (0)