package ee.ut.ga.test;

import java.math.BigDecimal;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

import ee.ut.ga.util.MathUtil;

public class MathUtilTest {
  public static Logger log = Logger.getLogger(MathUtilTest.class);

  public static void main(String[] args) {
    BasicConfigurator.configure();

    log.info("***** FACTORIAL TESTS *****");

    try {
      MathUtil.factorial(new BigDecimal("-1"));
    } catch (IllegalArgumentException e) {
      log.debug("Factorial of -1: " + e.getMessage());
    }

    try {
      MathUtil.factorial(new BigDecimal("9273"));
    } catch (IllegalArgumentException e) {
      log.debug("Factorial of 9273: " + e.getMessage());
    }

    log.debug("Factorial of 10: " + MathUtil.factorial(new BigDecimal("10")));
    log.debug("Factorial of 500: " + MathUtil.factorial(new BigDecimal("500")));
    log.debug("Factorial of 1000: " + MathUtil.factorial(new BigDecimal("1000")));
    log.debug("Factorial of 5000: " + MathUtil.factorial(new BigDecimal("5000")));
    log.debug("Factorial of 8000: " + MathUtil.factorial(new BigDecimal("8000")));
    log.debug("Factorial of 9272: " + MathUtil.factorial(new BigDecimal("9272")));

    log.info("***** COMBINATION TESTS *****");

    try {
      MathUtil.combination(new BigDecimal("-1"), new BigDecimal("100"));
    } catch (IllegalArgumentException e) {
      log.debug("Combination C^(100)[-1]: " + e.getMessage());
    }
    try {
      MathUtil.combination(new BigDecimal("-1"), new BigDecimal("-23"));
    } catch (IllegalArgumentException e) {
      log.debug("Combination C^(-23)[-1]: " + e.getMessage());
    }
    try {
      MathUtil.combination(new BigDecimal("9273"), new BigDecimal("3"));
    } catch (IllegalArgumentException e) {
      log.debug("Combination C^(3)[9273]: " + e.getMessage());
    }
    try {
      MathUtil.combination(new BigDecimal("12"), new BigDecimal("15"));
    } catch (IllegalArgumentException e) {
      log.debug("Combination C^(15)[12]: " + e.getMessage());
    }

    log.debug("Combination C^(9272)[9272]: " + MathUtil.combination(new BigDecimal("9272"), new BigDecimal("9272")));
    log.debug("Combination C^(5000)[5000]: " + MathUtil.combination(new BigDecimal("5000"), new BigDecimal("5000")));

    log.debug("Combination C^(24)[25]: " + MathUtil.combination(new BigDecimal("25"), new BigDecimal("24")));
    log.debug("Combination C^(1)[25]: " + MathUtil.combination(new BigDecimal("25"), new BigDecimal("1")));

    log.debug("Combination C^(3)[25]: " + MathUtil.combination(new BigDecimal("25"), new BigDecimal("3")));
    log.debug("Combination C^(22)[25]: " + MathUtil.combination(new BigDecimal("25"), new BigDecimal("22")));

    log.info("***** pVALUE TESTS *****");

    log.debug("pValue(2100, 2100, 0, 7000): "
        + MathUtil.pValue(new BigDecimal("2100"), new BigDecimal("2100"), new BigDecimal("0"), new BigDecimal("7000")));
    log.debug("pValue(2000, 2100, 100, 7000): "
        + MathUtil.pValue(new BigDecimal("2000"), new BigDecimal("2100"), new BigDecimal("100"), new BigDecimal("7000")));
    log.debug("pValue(1500, 2100, 600, 7000): "
        + MathUtil.pValue(new BigDecimal("1500"), new BigDecimal("2100"), new BigDecimal("600"), new BigDecimal("7000")));
    log.debug("pValue(1000, 2100, 1100, 7000): "
        + MathUtil.pValue(new BigDecimal("999"), new BigDecimal("2100"), new BigDecimal("1101"), new BigDecimal("7000")));
    log.debug("pValue(500, 2100, 1600, 7000): "
        + MathUtil.pValue(new BigDecimal("500"), new BigDecimal("2100"), new BigDecimal("1600"), new BigDecimal("7000")));
    log.debug("pValue(100, 2100, 2000, 7000): "
        + MathUtil.pValue(new BigDecimal("100"), new BigDecimal("2100"), new BigDecimal("2000"), new BigDecimal("7000")));
    log.debug("pValue(0, 2100, 2100, 7000): "
        + MathUtil.pValue(new BigDecimal("0"), new BigDecimal("2100"), new BigDecimal("2100"), new BigDecimal("7000")));
    log.debug("pValue(450, 2100, 450, 7000): "
        + MathUtil.pValue(new BigDecimal("450"), new BigDecimal("2100"), new BigDecimal("450"), new BigDecimal("7000")));
    log.debug("pValue(500, 2100, 400, 7000): "
        + MathUtil.pValue(new BigDecimal("500"), new BigDecimal("2100"), new BigDecimal("400"), new BigDecimal("7000")));
    log.debug("pValue(501, 2100, 399, 7000): "
        + MathUtil.pValue(new BigDecimal("501"), new BigDecimal("2100"), new BigDecimal("399"), new BigDecimal("7000")));
    log.debug("pValue(502, 2100, 398, 7000): "
        + MathUtil.pValue(new BigDecimal("502"), new BigDecimal("2100"), new BigDecimal("398"), new BigDecimal("7000")));
    log.debug("pValue(503, 2100, 397, 7000): "
        + MathUtil.pValue(new BigDecimal("503"), new BigDecimal("2100"), new BigDecimal("397"), new BigDecimal("7000")));
    log.debug("pValue(503, 2100, 397, 7000): "
        + MathUtil.pValue(new BigDecimal("900"), new BigDecimal("2100"), new BigDecimal("0"), new BigDecimal("7000")));

    log.info("***** pVALUE TESTS 2 *****");

    for (int i = 0; i < 51; i++) {
      log.debug("pValue(" + i + ", 3731, " + (50 - i) + ", 1746): "
          + MathUtil.pValue(new BigDecimal(i), new BigDecimal("3731"), new BigDecimal(50 - i), new BigDecimal("1746")));
    }

    log.debug("pValue(25, 3740, 25, 1735): "
        + MathUtil.pValue(new BigDecimal("25"), new BigDecimal("3740"), new BigDecimal("25"), new BigDecimal("1735")));

    log.info("***** pVALUE TESTS 3 *****");

    for (int i = 1000; i < 4801; i = i + 100) {
      log.debug("pValue(350, " + i + ", 150, " + (5000 - i) + "): "
          + MathUtil.pValue(new BigDecimal("350"), new BigDecimal(i), new BigDecimal("150"), new BigDecimal(5000 - i)));
    }
    
    log.debug("pValue(9, 31, 9, 9): "
              + MathUtil.pValue(new BigDecimal("9"), new BigDecimal("31"), new BigDecimal("9"), new BigDecimal("9")));
    
    
    log.debug("pValue(8, 18, 21, 22): "
              + MathUtil.pValue(new BigDecimal("8"), new BigDecimal("18"), new BigDecimal("21"), new BigDecimal("22")));
    
    for (int i = 0; i < 18; i++) {
      log.debug("pValue(" + i + ", 18, " + (21 - i) + ", 21): "
          + MathUtil.pValue(new BigDecimal(i), new BigDecimal("18"), new BigDecimal(21 - i), new BigDecimal("21")));
    }
  }
}
