package net.ranides.assira.math;

import org.junit.Test;

import java.math.BigDecimal;
import java.math.BigInteger;

import static org.junit.Assert.assertEquals;

public class NumberPairTest {

    @Test
    public void widen() {
        assertEquals(new NumberPair(1.0d, 1.0d), new NumberPair(1.0f, 1.0d).widen());
        assertEquals(new NumberPair(10.0d, 1.0d), new NumberPair(10, 1.0d).widen());
        assertEquals(new NumberPair(10L, 100L), new NumberPair(10, 100L).widen());

        assertEquals(
            new NumberPair(BigInteger.valueOf(10), BigInteger.valueOf(15)),
            new NumberPair(10, BigInteger.valueOf(15)).widen()
        );
        assertEquals(
            new NumberPair(BigDecimal.valueOf(10), BigDecimal.valueOf(15)),
            new NumberPair(10.0f, BigInteger.valueOf(15)).widen()
        );
        assertEquals(
            new NumberPair(BigDecimal.valueOf(10.5), BigDecimal.valueOf(15)),
            new NumberPair(10.5f, BigInteger.valueOf(15)).widen()
        );
    }

    @Test
    public void add() {
        assertEquals(2.0d, new NumberPair(1.0f, 1.0d).add());
        assertEquals(11.0d, new NumberPair(10, 1.0d).add());
        assertEquals(110L, new NumberPair(10, 100L).add());

        assertEquals(
            BigInteger.valueOf(25), new NumberPair(10, BigInteger.valueOf(15)).add()
        );
        assertEquals(
            BigDecimal.valueOf(25), new NumberPair(10.0f, BigInteger.valueOf(15)).add()
        );
        assertEquals(
            BigDecimal.valueOf(25.5), new NumberPair(10.5f, BigInteger.valueOf(15)).add()
        );
    }

    @Test
    public void subtract() {
        assertEquals(2.0d, new NumberPair(3.0f, 1.0d).subtract());
        assertEquals(19.0d, new NumberPair(20, 1.0d).subtract());
        assertEquals(20L, new NumberPair(30, 10L).subtract());

        assertEquals(
            BigInteger.valueOf(25), new NumberPair(40, BigInteger.valueOf(15)).subtract()
        );
        assertEquals(
            BigDecimal.valueOf(25), new NumberPair(40.0f, BigInteger.valueOf(15)).subtract()
        );
        assertEquals(
            BigDecimal.valueOf(25.5), new NumberPair(40.5f, BigInteger.valueOf(15)).subtract()
        );
    }

    @Test
    public void multiply() {
        assertEquals(3.0d, new NumberPair(3.0f, 1.0d).multiply());
        assertEquals(30.0d, new NumberPair(20, 1.5d).multiply());
        assertEquals(300L, new NumberPair(30, 10L).multiply());

        assertEquals(
            BigInteger.valueOf(60), new NumberPair(4, BigInteger.valueOf(15)).multiply()
        );
        assertEquals(
            BigDecimal.valueOf(60), new NumberPair(4.0f, BigInteger.valueOf(15)).multiply()
        );
        assertEquals(
            BigDecimal.valueOf(67.5), new NumberPair(4.5f, BigInteger.valueOf(15)).multiply()
        );
    }

    @Test
    public void divide() {
        assertEquals(1.5d, new NumberPair(3.0f, 2.0d).divide());
        assertEquals(15.0d, new NumberPair(30, 2.0d).divide());
        assertEquals(3L, new NumberPair(30, 10L).divide());

        assertEquals(
            BigInteger.valueOf(3), new NumberPair(45, BigInteger.valueOf(15)).divide()
        );
        assertEquals(
            BigDecimal.valueOf(3), new NumberPair(45.0f, BigInteger.valueOf(15)).divide()
        );
        assertEquals(
            BigDecimal.valueOf(4.75), new NumberPair(9.5f, BigInteger.valueOf(2)).divide()
        );
    }
}