Package org.jExigo

Examples of org.jExigo.FixedDecimalNumber


}


public void testTruncate()
{
  FixedDecimalNumber fda = new FixedDecimalNumber("1");
  try {
    fda.truncate(9)// too big but not an error
  } catch (Exception e) {
    fail(e.getMessage());
  }
  assertEquals("1",  fda.get());
 
  fda = new FixedDecimalNumber("1");
  try {
    fda.truncate(-9);
    fail("should throw exception");
  } catch (Exception e) {
   
  }
 
  fda = new FixedDecimalNumber("1.0");
  try {
    fda.truncate(9)// too big but not an error
  } catch (Exception e) {
    fail(e.getMessage());
  }
  assertEquals("1.0",  fda.get());
 
  fda = new FixedDecimalNumber("1.0");
  try {
    fda.truncate(0);
  } catch (Exception e) {
    fail(e.getMessage());
  }
  assertEquals("1",  fda.get())
 
  fda = new FixedDecimalNumber("1.0");
  try {
    fda.truncate(9)// too big but not an error
  } catch (Exception e) {
    fail(e.getMessage());
  }
  assertEquals("1.0",  fda.get());
 
  fda = new FixedDecimalNumber("1.00000000000000");
  try {
    fda.truncate(0);
  } catch (Exception e) {
    fail(e.getMessage());
  }
  assertEquals("1",  fda.get());
 
  fda = new FixedDecimalNumber("1.09");
  try {
    fda.truncate(1)
  } catch (Exception e) {
    fail(e.getMessage());
  }
  assertEquals("1.0",  fda.get());
 
  fda = new FixedDecimalNumber("1.09");
  try {
    fda.truncate(2);
  } catch (Exception e) {
    fail(e.getMessage());
  }
  assertEquals("1.09",  fda.get());
 
 
}
View Full Code Here


 


public void testRound()
{
  FixedDecimalNumber fda = new FixedDecimalNumber("1");
  try {
    fda.round(9)// too big but not an error
  } catch (Exception e) {
    fail(e.getMessage());
  }
  assertEquals("1", fda.get());
 
  fda = new FixedDecimalNumber("1");
  try {
    fda.round(-9);
    fail("should throw exception");
  } catch (Exception e) {
   
  }
 
  fda = new FixedDecimalNumber("1.0");
  try {
    fda.round(9)// too big but not an error
  } catch (Exception e) {
    fail(e.getMessage());
  }
  assertEquals("1.0",  fda.get());
 
  fda = new FixedDecimalNumber("1.0");
  try {
    fda.round(0);
  } catch (Exception e) {
    fail(e.getMessage());
  }
  assertEquals("1",  fda.get())
 
  fda = new FixedDecimalNumber("1.0");
  try {
    fda.round(9)// too big but not an error
  } catch (Exception e) {
    fail(e.getMessage());
  }
  assertEquals("1.0",  fda.get());
 
  fda = new FixedDecimalNumber("1.00000000000000");
  try {
    fda.round(0);
  } catch (Exception e) {
    fail(e.getMessage());
  }
  assertEquals("1",  fda.get())
 
  fda = new FixedDecimalNumber("1.09");
  try {
    fda.round(1)
  } catch (Exception e) {
    fail(e.getMessage());
  }
  assertEquals("1.1",  fda.get());
 
  fda = new FixedDecimalNumber("1.09");
  try {
    fda.round(2);
  } catch (Exception e) {
    fail(e.getMessage());
  }
  assertEquals("1.09",  fda.get())
 
 
}
View Full Code Here




public void testPower() {
    FixedDecimalNumber fda = new FixedDecimalNumber("2");
    try {
      FixedDecimalArithmetic.power(fda, -1);
      fail("should be throw exception");
    }
    catch (org.jExigo.Exception e)
    {
      ;
    }

    try {
    fda = FixedDecimalArithmetic.power(fda, 0);
    assertEquals("1", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
   
  fda = new FixedDecimalNumber("2");
    try {
    fda = FixedDecimalArithmetic.power(fda, 0)//2^0
    assertEquals("1", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
   
  fda = new FixedDecimalNumber("2");
    try {
    fda = FixedDecimalArithmetic.power(fda, 2)//2^2
    assertEquals("4", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
   
    try {
    fda = FixedDecimalArithmetic.power(fda, 2); // 4^2
    assertEquals("16", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
   
    try {
    fda = FixedDecimalArithmetic.power(fda, 4); // 16^4
    assertEquals("65536", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
   
  fda = new FixedDecimalNumber("2.0");
    try {
    fda = FixedDecimalArithmetic.power(fda, 1); //2.0^1
    assertEquals("2.0", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
   
    try {
    fda = FixedDecimalArithmetic.power(fda, 2); //2.0^2
    assertEquals("4.0", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
   
    try {
    fda = FixedDecimalArithmetic.power(fda, 2);//4.0^2
    assertEquals("16.0", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
   
    try {
    fda = FixedDecimalArithmetic.power(fda, 4);//16.0^4
    assertEquals("65536.0", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
   
  fda = new FixedDecimalNumber("2.2");

    try {
    fda = FixedDecimalArithmetic.power(fda, 0); //2.2^0
    assertEquals("1", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
   
  fda = new FixedDecimalNumber("2.2");
 
    try {
    fda = FixedDecimalArithmetic.power(fda, 1); //2.2^1
    assertEquals("2.2", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
 
    try {
    fda = FixedDecimalArithmetic.power(fda, 3); //2.2^3
    assertEquals("10.6", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
 
  fda = new FixedDecimalNumber("2.029");
 
    try {
    fda = FixedDecimalArithmetic.power(fda, 1);//2.029^1
    assertEquals("2.029", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
 
    try {
    fda = FixedDecimalArithmetic.power(fda, 5);//2.029^5
    assertEquals("34.388", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
 
  fda = new FixedDecimalNumber("2.029");
 
    try {
    fda = FixedDecimalArithmetic.power(fda, 5, 5); //2.029^5 to 5 places
    assertEquals("34.38826", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }

   
  fda = new FixedDecimalNumber(.13);
    try {
    fda = FixedDecimalArithmetic.power(fda, 1); //.13^1
    assertEquals("0.13", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
 
  fda = new FixedDecimalNumber(-.13);
    try {
    fda = FixedDecimalArithmetic.power(fda, 2, 4); //(-.13)^2 to 4 places
    assertEquals("0.0169", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
 
  fda = new FixedDecimalNumber(-.13);
    try {
    fda = FixedDecimalArithmetic.power(fda, 3, 5); //(-.13)^3 to 5 places
    assertEquals("-0.00219", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
 
  fda = new FixedDecimalNumber(-.13);
    try {
    fda = FixedDecimalArithmetic.power(fda, 3, 2); //0.00 (-.13)^2 to to places look for truncation and dropped negative sign.
    assertEquals("0.00", fda.get());
  } catch (Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
 
View Full Code Here

TOP

Related Classes of org.jExigo.FixedDecimalNumber

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.