From 8466b9ab93c1f497de108546297dbfa231f8875f Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Thu, 23 Aug 2018 23:51:26 -0700 Subject: [PATCH] Add tests for subsampling --- tests/test_channel.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/test_channel.py diff --git a/tests/test_channel.py b/tests/test_channel.py new file mode 100644 index 0000000..42fcdf8 --- /dev/null +++ b/tests/test_channel.py @@ -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