// 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 java.util.Arrays;
import java.util.stream.Collectors;
import org.apache.commons.math3.complex.Complex;
import org.apache.commons.math3.transform.DftNormalization;
import org.apache.commons.math3.transform.FastFourierTransformer;
import org.apache.commons.math3.transform.TransformType;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import ro.hasna.ts.math.util.TimeSeriesPrecision;
    }

    @Test
    public void testTransformSineWave() throws Exception {
        double signalFrequency = 100;
        double amplitude = 30;
        double displacement = 17;
        double samplingFrequency = signalFrequency * 8; //it should be at least double (Shannon Theorem)
        int len = 1000;
        double[] v = new double[len];
        for (int i = 0; i < len; i++) {
            v[i] = amplitude * Math.sin(2 * Math.PI * signalFrequency * i / samplingFrequency) + displacement;
        }

        double[] result = new DiscreteFourierTransform().transform(v);

        double max = 0;
        int pos = 0;
        for (int i = 1; i < result.length; i++) {
            if (max < result[i]) {
                max = result[i];
                pos = i;
            }
        }

        int powerOfTwo = Integer.highestOneBit(len);
        if (len != powerOfTwo) {
            powerOfTwo = powerOfTwo << 1;
        }

// 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/representation/DiscreteFourierTransformTest.java
import java.util.Arrays;
import java.util.stream.Collectors;
import org.apache.commons.math3.complex.Complex;
import org.apache.commons.math3.transform.DftNormalization;
import org.apache.commons.math3.transform.FastFourierTransformer;
import org.apache.commons.math3.transform.TransformType;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import ro.hasna.ts.math.util.TimeSeriesPrecision;

    }

    @Test
    public void testTransformSineWave() throws Exception {
        double signalFrequency = 100;
        double amplitude = 30;
        double displacement = 17;
        double samplingFrequency = signalFrequency * 8; //it should be at least double (Shannon Theorem)
        int len = 1000;
        double[] v = new double[len];
        for (int i = 0; i < len; i++) {
            v[i] = amplitude * Math.sin(2 * Math.PI * signalFrequency * i / samplingFrequency) + displacement;
        }

        double[] result = new DiscreteFourierTransform().transform(v);

        double max = 0;
        int pos = 0;
        for (int i = 1; i < result.length; i++) {
            if (max < result[i]) {
                max = result[i];
                pos = i;
            }
        }

        int powerOfTwo = Integer.highestOneBit(len);
        if (len != powerOfTwo) {
            powerOfTwo = powerOfTwo << 1;
        }

        Assert.assertEquals(amplitude, max, TimeSeriesPrecision.EPSILON);