Add tests for subsampling

pull/357/head
nyanpasu64 2018-08-23 23:51:26 -07:00
rodzic b5c49e5649
commit 8466b9ab93
1 zmienionych plików z 37 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,37 @@
import pytest
from hypothesis import given, example
from hypothesis.strategies import integers
from ovgenpy.channel import ChannelConfig, Channel
from ovgenpy.ovgenpy import default_config
positive = integers(min_value=1)
@given(subsampling=positive, trigger_width_ratio=positive, render_width_ratio=positive)
def test_channel_subsampling(
subsampling: int,
trigger_width_ratio: int,
render_width_ratio: int,
):
""" Ensure nsamp and trigger/render subsampling are computed correctly. """
ccfg = ChannelConfig(
'tests/sine440.wav',
trigger_width_ratio=trigger_width_ratio,
render_width_ratio=render_width_ratio,
)
cfg = default_config(subsampling=subsampling)
channel = Channel(ccfg, cfg)
assert channel.wave.smp_s == 48000
ideal_nsamp = round(cfg.render_width_s * channel.wave.smp_s / subsampling)
assert channel.nsamp == pytest.approx(ideal_nsamp, 1)
assert channel.trigger_subsampling == subsampling * trigger_width_ratio
assert channel.render_subsampling == subsampling * render_width_ratio
# line_color is tested in test_renderer.py
# todo test ChannelConfig.ampl_ratio