/*
 * Copyright (c) 2012, 2018, Werner Keil, Anatole Tresch and others.
 *
 * 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.
 *
 * Contributors: @atsticks, @keilw
 */
package org.javamoney.calc.common;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

/**
 * Tests for discount factor.
 */
public class DiscountFactorTest {

    /**
     * Calculate negative.
     */
    @Test
	public void calculate_Negative() {
        assertEquals(1, DiscountFactor.calculate(RateAndPeriods.of(-0.05,0)).doubleValue(), 0.0d);
        assertEquals(1.0526315789473684, DiscountFactor.calculate(RateAndPeriods.of(-0.05,1)).doubleValue(), 0.0d);
        assertEquals(1.422382169222759, DiscountFactor.calculate(RateAndPeriods.of(-0.05,10)).doubleValue(), 0.0d);
    }

    /**
     * Calculate zero.
     */
    @Test
	public void calculate_Zero() {
        assertEquals(1, DiscountFactor.calculate(RateAndPeriods.of(0.00,0)).intValueExact());
        assertEquals(1, DiscountFactor.calculate(RateAndPeriods.of(0.00,1)).intValueExact());
        assertEquals(1, DiscountFactor.calculate(RateAndPeriods.of(0.00,10)).intValueExact());
    }

    /**
     * Calculate positive.
     */
    @Test
	public void calculate_Positive() {
        assertEquals(1.0, DiscountFactor.calculate(RateAndPeriods.of(0.05,0)).doubleValue(), 0.0d);
        assertEquals(0.95, DiscountFactor.calculate(RateAndPeriods.of(0.05,1)).doubleValue(), 0.0d);
        assertEquals(0.37110537322255859375, DiscountFactor.calculate(RateAndPeriods.of(0.05,10)).doubleValue(), 0.0d);
	}

    /**
     * Calculate negative periods.
     */
    @Test(expected = IllegalArgumentException.class)
	public void calculate_negativePeriods() {
		DiscountFactor.calculate(RateAndPeriods.of(-0.05, -1));
    }
}