package net.heartshield.filter;

import junit.framework.TestCase;
import net.heartshield.filter.EveningResampler;
import net.heartshield.signal.DVec;
import net.heartshield.signal.IVec;

/**
 * @author David Madl (git@abanbytes.eu)
 * @date 2017-03-19
 */
public class EveningResamplerTests extends TestCase {
    private static final double EPS = 1e-6;

    public void setUp() throws Exception {
        super.setUp();
    }
    public void tearDown() throws Exception {
        super.tearDown();
    }

    public void testAddUneven() {
        EveningResampler res = new EveningResampler(1.0);

        double[] times  = { 0.5, 2.5, 6.5, 8.0 };
        double[] frames = { 0.0, 2.0, 3.0, 3.0 };

        // the last entry is NOT expected, even if rounded onto that int.
        double[] expect_times  = new double[]{ 0.0, 1.0, 2.0, 3.0,   4.0,   5.0,   6.0,   7.0 }; // , 8.0
        double[] expect_frames = new double[]{ 0.0, 0.5, 1.5, 2.125, 2.375, 2.625, 2.875, 3.0 }; // , 3.0

        for(int i = 0; i < frames.length; i++) {
            res.addUneven(times[i], frames[i]);
        }

        double[] ts = res.getEvenTimes();
        double[] fs = res.getEvenFrames();

        if(!IVec.all(DVec.eqt(ts, expect_times, EPS)))
            throw new IllegalStateException("test failed");
        if(!IVec.all(DVec.eqt(fs, expect_frames, EPS)))
            throw new IllegalStateException("test failed");
    }
}
