/*
 * SPDX-License-Identifier: MIT
 */
package org.ta4j.core.indicators;

import org.junit.Before;
import org.junit.Test;
import org.ta4j.core.BarSeries;
import org.ta4j.core.Indicator;
import org.ta4j.core.mocks.MockBarSeriesBuilder;
import org.ta4j.core.num.Num;
import org.ta4j.core.num.NumFactory;

import static org.ta4j.core.TestUtils.assertNumEquals;

public class KRIIndicatorTest extends AbstractIndicatorTest<Indicator<Num>, Num> {
    private BarSeries series;

    public KRIIndicatorTest(NumFactory numFactory) {
        super(numFactory);
    }

    @Before
    public void setUp() {
        // Values borrowed from HMAIndicatorTest
        series = new MockBarSeriesBuilder().withNumFactory(numFactory)
                .withData(84.53, 87.39, 84.55, 82.83, 82.58, 83.74, 83.33, 84.57, 86.98, 87.10, 83.11, 83.60, 83.66,
                        82.76, 79.22, 79.03, 78.18, 77.42, 74.65, 77.48, 76.87)
                .build();
    }

    @Test
    public void kriIndicatorTest() {
        KRIIndicator kriIndicator = new KRIIndicator(series, 10);

        assertNumEquals(-1.78212, kriIndicator.getValue(10));
        assertNumEquals(-0.75855, kriIndicator.getValue(11));
        assertNumEquals(-0.58229, kriIndicator.getValue(12));
        assertNumEquals(-1.64363, kriIndicator.getValue(13));
        assertNumEquals(-5.47328, kriIndicator.getValue(14));
        assertNumEquals(-5.16703, kriIndicator.getValue(15));
        assertNumEquals(-5.60365, kriIndicator.getValue(16));
        assertNumEquals(-5.70725, kriIndicator.getValue(17));
        assertNumEquals(-7.69478, kriIndicator.getValue(18));
        assertNumEquals(-3.04213, kriIndicator.getValue(19));
        assertNumEquals(-3.04841, kriIndicator.getValue(20));
    }
}
