I have written a java code for scientific calculator and also written jUnit test for it.Below is the method for calculating cubeRoot.
public <T> Double cubeRoot(T number){
Double result= Math.cbrt((Double)number);
return Math.abs(result);
}
Method returns proper result integer and double types,but when i invoke method for decimal,argument i pass is double type.Following are the JUint Test for above method.
public void testCalculateCubeRootWhenNegative(){
Integer number=-64;
assertEquals(-4.0,sci.cubeRoot(number));
}
public void testCalculateCubeRootOfdecimal(){
Double number=0.40;
assertEquals(0.736,sci.cubeRoot(number));
}
And this the interface i am using
public interface iScientific extends iMaths {
<T>Double squareRoot(T number);
<T>Double cubeRoot(T number);
Unable to find solution for getting error "java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double"