// Path: src/main/java/ro/hasna/ts/math/util/TimeSeriesPrecision.java
// public class TimeSeriesPrecision {
//     public static final double EPSILON = FastMath.pow(2, -30);
// 
//     /**
//      * Private constructor.
//      */
//     private TimeSeriesPrecision() {
//     }
// }


import org.apache.commons.math3.exception.DimensionMismatchException;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import ro.hasna.ts.math.util.TimeSeriesPrecision;
/*
 * Copyright 2015 Octavian Hasna
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ro.hasna.ts.math.filter;


public class MovingAverageFilterTest {

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @Test
    public void testConstructor1() throws Exception {
        thrown.expect(DimensionMismatchException.class);
        thrown.expectMessage("0 != 5");

        new MovingAverageFilter(2, true, new double[]{});
    }

    @Test
    public void testConstructor2() throws Exception {
        thrown.expect(DimensionMismatchException.class);
        thrown.expectMessage("0 != 2");

        new MovingAverageFilter(2, false, new double[]{});
    }

    @Test
    public void testFilterSymmetricWithoutWeights() throws Exception {
        double[] v = {1, 1, 2, 2, 3, 3, 4, 4, 5};
        double[] expected = {1, 1, 1.8, 2.2, 2.8, 3.2, 3.8, 4, 5};

        Filter filter = new MovingAverageFilter(2);
        double[] result = filter.filter(v);

// Path: src/main/java/ro/hasna/ts/math/util/TimeSeriesPrecision.java
// public class TimeSeriesPrecision {
//     public static final double EPSILON = FastMath.pow(2, -30);
// 
//     /**
//      * Private constructor.
//      */
//     private TimeSeriesPrecision() {
//     }
// }


// Path: src/test/java/ro/hasna/ts/math/filter/MovingAverageFilterTest.java
import org.apache.commons.math3.exception.DimensionMismatchException;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import ro.hasna.ts.math.util.TimeSeriesPrecision;

/*
 * Copyright 2015 Octavian Hasna
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ro.hasna.ts.math.filter;


public class MovingAverageFilterTest {

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @Test
    public void testConstructor1() throws Exception {
        thrown.expect(DimensionMismatchException.class);
        thrown.expectMessage("0 != 5");

        new MovingAverageFilter(2, true, new double[]{});
    }

    @Test
    public void testConstructor2() throws Exception {
        thrown.expect(DimensionMismatchException.class);
        thrown.expectMessage("0 != 2");

        new MovingAverageFilter(2, false, new double[]{});
    }

    @Test
    public void testFilterSymmetricWithoutWeights() throws Exception {
        double[] v = {1, 1, 2, 2, 3, 3, 4, 4, 5};
        double[] expected = {1, 1, 1.8, 2.2, 2.8, 3.2, 3.8, 4, 5};

        Filter filter = new MovingAverageFilter(2);
        double[] result = filter.filter(v);

        Assert.assertArrayEquals(expected, result, TimeSeriesPrecision.EPSILON);