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());
}