package st.extreme.math;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.math.BigInteger;

import org.junit.Test;

public class BigFractionConstructionTest {

  private static final BigInteger MINUS_THREE = new BigInteger("-3");
  private static final BigInteger MINUS_TWO = new BigInteger("-2");
  private static final BigInteger ZERO = new BigInteger("0");
  private static final BigInteger ONE = new BigInteger("1");
  private static final BigInteger TWO = new BigInteger("2");
  private static final BigInteger THREE = new BigInteger("3");

  @Test
  public void testStringConstructor_IllegalCharacter() {
    try {
      new BigFraction(".", "4");
      fail("NumberFormatException expected");
    } catch (NumberFormatException nfe) {
      // ok
    }
    try {
      new BigFraction("4", ".");
      fail("NumberFormatException expected");
    } catch (NumberFormatException nfe) {
      // ok
    }
  }

  @Test
  public void testStringConstructor_divisionByZero() {
    try {
      new BigFraction("1", "0");
      fail("ArithmeticException expected");
    } catch (ArithmeticException ae) {
      assertTrue(ae.getMessage().contains("division by zero"));
    }
  }

  @Test
  public void testStringConstructor_Sign() {
    BigFraction bf = new BigFraction("2", "-3");
    // expect the sign in the numerator
    assertEquals(MINUS_TWO, bf.getNumerator());
    assertEquals(THREE, bf.getDenominator());
  }

  @Test
  public void testStringConstructor() {
    BigFraction bf = new BigFraction("2", "3");
    assertEquals(TWO, bf.getNumerator());
    assertEquals(THREE, bf.getDenominator());
  }

  @Test
  public void testBigIntegerConstructor() {
    BigFraction bf = new BigFraction(TWO, THREE);
    assertEquals(TWO, bf.getNumerator());
    assertEquals(THREE, bf.getDenominator());
  }

  @Test
  public void testBigIntegerConstructor_divisionByZero() {
    try {
      new BigFraction(ONE, ZERO);
      fail("ArithmeticException expected");
    } catch (ArithmeticException ae) {
      assertTrue(ae.getMessage().contains("division by zero"));
    }
  }

  @Test
  public void testBigIntegerConstructor_Sign() {
    BigFraction bf = new BigFraction(TWO, MINUS_THREE);
    // expect the sign in the numerator
    assertEquals(MINUS_TWO, bf.getNumerator());
    assertEquals(THREE, bf.getDenominator());
  }

}

@@ -1322,32 +1322,41 @@
     BigFraction 
+bf;%0A%0A    
 bf = new BigFrac
@@ -1368,24 +1368,24 @@
 %222%22, %22-3%22);%0A
-
     // expec
@@ -1498,32 +1498,228 @@
 Denominator());%0A
+    assertEquals(-1, bf.signum());%0A%0A    bf = new BigFraction(%22-2%22, %22-3%22);%0A    assertEquals(TWO, bf.getNumerator());%0A    assertEquals(THREE, bf.getDenominator());%0A    assertEquals(1, bf.signum());%0A
   %7D%0A%0A  @Test%0A  p
@@ -2425,32 +2425,41 @@
     BigFraction 
+bf;%0A%0A    
 bf = new BigFrac
@@ -2562,32 +2562,32 @@
 etNumerator());%0A
-
     assertEquals
@@ -2612,19 +2612,227 @@
 minator());%0A
+    assertEquals(-1, bf.signum());%0A%0A    bf = new BigFraction(MINUS_TWO, MINUS_THREE);%0A    assertEquals(TWO, bf.getNumerator());%0A    assertEquals(THREE, bf.getDenominator());%0A    assertEquals(1, bf.signum());%0A
   %7D%0A%0A%7D%0A

test both numerator and denominator negative