Skip to content

Commit 82f97b2

Browse files
test: update tests
1 parent 66e3ef5 commit 82f97b2

4 files changed

Lines changed: 32 additions & 28 deletions

File tree

tests/test_qc/test_behavior.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,37 +43,26 @@ def test_calculate_lick_intervals_detects_artifacts():
4343
assert result["ArtifactPercent"] > 0
4444

4545

46-
def test_compute_side_bias_balanced_and_all_ignore():
47-
"""Bias is right-minus-left over responses; all-ignore gives nan."""
48-
assert _behavior.compute_side_bias(np.array([0, 1, 0, 1])) == 0.0
49-
assert _behavior.compute_side_bias(np.array([1, 1, 1, 0])) == pytest.approx(0.5)
50-
assert np.isnan(_behavior.compute_side_bias(np.array([2, 2, 2])))
51-
52-
53-
def test_compute_rolling_bias_shapes_and_empty_window():
54-
"""Rolling bias is nan where a window has no responses, set otherwise."""
55-
responses = np.array([2, 1, 1, 0]) # first trial is ignore -> nan
56-
bias, ci = _behavior.compute_rolling_bias(responses, window=2)
57-
assert bias.shape == (4,)
58-
assert ci.shape == (4, 2)
59-
assert np.isnan(bias[0])
60-
assert not np.isnan(bias[1])
61-
62-
6346
def test_side_bias_result_pass_and_fail():
64-
"""Side-bias result passes under 0.5 absolute bias and fails above it."""
65-
passing = _behavior.side_bias_result(np.array([0, 1, 0, 1]))
47+
"""Side-bias result averages the column; passes under 0.5 absolute bias."""
48+
passing = _behavior.side_bias_result(np.array([-0.2, 0.1, np.nan, 0.1]))
6649
assert passing.passed is True
50+
assert passing.value == pytest.approx(0.0)
6751
assert passing.reference == _behavior.SIDE_BIAS_PLOT
6852
assert passing.tags == {"behavior": "average side bias"}
6953

70-
failing = _behavior.side_bias_result(np.array([1, 1, 1, 1]))
54+
failing = _behavior.side_bias_result(np.array([0.8, 0.9, 1.0]))
7155
assert failing.passed is False
56+
assert failing.value == pytest.approx(0.9)
7257

73-
no_response = _behavior.side_bias_result(np.array([2, 2, 2]))
58+
no_response = _behavior.side_bias_result(np.array([np.nan, np.nan]))
7459
assert no_response.passed is False
7560
assert np.isnan(no_response.value)
7661

62+
empty = _behavior.side_bias_result(np.array([]))
63+
assert empty.passed is False
64+
assert np.isnan(empty.value)
65+
7766

7867
def test_lick_interval_results_names_and_count():
7968
"""Four lick-interval results are produced with the expected names/tags."""

tests/test_qc/test_builder.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
def test_behavior_qc_results_without_plots():
1515
"""Five behavior results are produced and no plots are written."""
1616
results = _results.behavior_qc_results(
17-
np.array([0, 1, 2, 1]), np.array([1.0, 1.01]), np.array([2.0, 2.01])
17+
np.array([0, 1, 2, 1]),
18+
np.array([-0.1, 0.0, np.nan, 0.1]),
19+
np.array([1.0, 1.01]),
20+
np.array([2.0, 2.01]),
1821
)
1922
assert len(results) == 5
2023
assert results[0].name == "average side bias"
@@ -24,6 +27,7 @@ def test_behavior_qc_results_writes_plots(tmp_path):
2427
"""Supplying a results folder writes both behavior plots."""
2528
results = _results.behavior_qc_results(
2629
np.array([0, 1, 2, 1]),
30+
np.array([-0.1, 0.0, np.nan, 0.1]),
2731
np.array([1.0, 1.01]),
2832
np.array([2.0, 2.01]),
2933
str(tmp_path),
@@ -36,7 +40,9 @@ def test_behavior_qc_results_writes_plots(tmp_path):
3640
def test_build_quality_control_defaults():
3741
"""Defaults fill in the standard grouping and an empty failure allowlist."""
3842
metrics = to_metrics(
39-
_results.behavior_qc_results(np.array([0, 1]), np.array([1.0]), np.array([2.0]))
43+
_results.behavior_qc_results(
44+
np.array([0, 1]), np.array([0.1, -0.1]), np.array([1.0]), np.array([2.0])
45+
)
4046
)
4147
qc = _builder.build_quality_control(metrics)
4248
assert isinstance(qc, QualityControl)
@@ -47,7 +53,9 @@ def test_build_quality_control_defaults():
4753
def test_build_quality_control_overrides():
4854
"""Explicit grouping / allowlist / metadata are passed through."""
4955
metrics = to_metrics(
50-
_results.behavior_qc_results(np.array([0, 1]), np.array([1.0]), np.array([2.0]))
56+
_results.behavior_qc_results(
57+
np.array([0, 1]), np.array([0.1, -0.1]), np.array([1.0]), np.array([2.0])
58+
)
5159
)
5260
qc = _builder.build_quality_control(
5361
metrics,

tests/test_qc/test_plots.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ def test_time_to_trial_index_covers_all_branches():
2828
def test_plot_side_bias_full_inputs(tmp_path):
2929
"""All optional panels render when every per-trial array is supplied."""
3030
animal_response = np.array([0, 1, 2, 1, 0, 1])
31+
side_bias = np.array([-0.2, 0.0, np.nan, 0.3, 0.1, 0.2])
3132
name = _plots.plot_side_bias(
3233
animal_response,
34+
side_bias,
3335
str(tmp_path),
3436
lickspout_x=np.array([1.0, 1.1, 1.0, 1.2, 1.1, 1.0]),
3537
lickspout_y1=np.array([2.0, 2.0, 2.1, 2.0, 2.0, 2.1]),
@@ -44,19 +46,20 @@ def test_plot_side_bias_full_inputs(tmp_path):
4446
autowater_right=np.array([0, 0, 0, 1, 0, 0]),
4547
manual_left_times=np.array([0.1, 3.6]), # 0.1 -> -1, 3.6 -> trial index
4648
manual_right_times=np.array([5.6]),
47-
bias_window=3,
4849
)
4950
assert name == _plots.SIDE_BIAS_PLOT
5051
assert os.path.exists(tmp_path / name)
5152

5253

5354
def test_plot_side_bias_minimal_inputs(tmp_path):
5455
"""With only choices supplied, the optional panels are skipped cleanly."""
55-
name = _plots.plot_side_bias(np.array([]), str(tmp_path))
56+
name = _plots.plot_side_bias(np.array([]), np.array([]), str(tmp_path))
5657
assert os.path.exists(tmp_path / name)
5758

5859

5960
def test_plot_side_bias_empty_position_array(tmp_path):
6061
"""An empty lickspout-position array is skipped without plotting."""
61-
name = _plots.plot_side_bias(np.array([0, 1]), str(tmp_path), lickspout_x=np.array([]))
62+
name = _plots.plot_side_bias(
63+
np.array([0, 1]), np.array([0.1, -0.1]), str(tmp_path), lickspout_x=np.array([])
64+
)
6265
assert os.path.exists(tmp_path / name)

tests/test_qc/test_stages.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ def _fake_contract_qc_metrics(dataset, results_folder):
4646
def test_processed_qc_run_returns_metrics():
4747
"""``ProcessedQC.run`` produces the five behavior metrics."""
4848
metrics = ProcessedQC().run(
49-
np.array([0, 1, 2, 1]), np.array([1.0, 1.01]), np.array([2.0, 2.01])
49+
np.array([0, 1, 2, 1]),
50+
np.array([-0.1, 0.0, np.nan, 0.1]),
51+
np.array([1.0, 1.01]),
52+
np.array([2.0, 2.01]),
5053
)
5154
assert len(metrics) == 5
5255
assert all(isinstance(m, QCMetric) for m in metrics)
@@ -57,6 +60,7 @@ def test_processed_qc_run_writes_plots(tmp_path):
5760
"""Supplying a results folder writes the supporting plots."""
5861
metrics = ProcessedQC().run(
5962
np.array([0, 1, 2, 1]),
63+
np.array([-0.1, 0.0, np.nan, 0.1]),
6064
np.array([1.0, 1.01]),
6165
np.array([2.0, 2.01]),
6266
str(tmp_path),

0 commit comments

Comments
 (0)