def test_resampling_2d():
    """Test up- and down-sampling a 2D stimulus."""
    np.random.seed(0)
    stim_size = (1000, 5)
    resample_factor = 3
    dt = 0.1
    stim = np.random.randn(*stim_size)
    time = np.arange(stim_size[0]) * dt
    stim_us, time_us = stimulustools.upsample(
            stim, resample_factor, time=time)
    stim_ds, time_ds = stimulustools.downsample(
            stim_us, resample_factor, time=time_us)

    assert np.all(stim == stim_us[::resample_factor, ...]), 'Upsampling failed'
    assert np.all(stim == stim_ds), 'Downsampling failed'
def test_resampling_1d():
    """Test up- and down-sampling a 1D stimulus."""
    np.random.seed(0)
    stim_size = 1000
    resample_factor = 3
    dt = 0.1
    stim = np.random.randn(stim_size,)
    time = np.arange(stim_size) * dt
    stim_us, time_us = stimulustools.upsample(
            stim, resample_factor, time=time)
    stim_ds, time_ds = stimulustools.downsample(
            stim_us, resample_factor, time=time_us)

    assert np.all(stim == stim_us[::resample_factor]), 'Upsampling failed'
    assert np.all(stim == stim_ds), 'Downsampling failed'

    _, time_us = stimulustools.upsample(stim, resample_factor)
    assert time_us is None