WitnessBox / tests /test_stance.py
Farseen0's picture
Deploy WitnessBox
c519923 verified
Raw
History Blame Contribute Delete
1.13 kB
"""Stance must degrade gracefully and score in the intuitive direction."""
import numpy as np
from witnessbox import stance
from witnessbox.stance import analyze, _score
def test_silence_is_neutral_low_certainty():
y = np.zeros(16000, dtype=np.float32)
r = analyze(y, 16000)
assert r.tier == "NEUTRAL" and r.certainty < 0.5
def test_empty_and_none_are_neutral():
assert analyze(np.array([], dtype=np.float32), 16000).tier == "NEUTRAL"
assert analyze(None, 16000).tier == "NEUTRAL"
def test_always_returns_valid_result():
y = (0.2 * np.random.RandomState(0).randn(16000)).astype(np.float32)
r = analyze(y, 16000)
assert r.tier in {"CONFIDENT", "NEUTRAL", "HESITANT"}
assert 0.0 <= r.confidence <= 100.0
def test_score_direction():
# Fluent + steady should read more confident than halting + swooping.
fluent, _ = _score(pause_ratio=0.10, rate_hz=4.2, pitch_std_semitones=1.0)
halting, _ = _score(pause_ratio=0.60, rate_hz=1.5, pitch_std_semitones=5.5)
assert fluent > halting
assert stance._tier(fluent) == "CONFIDENT"
assert stance._tier(halting) == "HESITANT"