J
jimgardener
hi
i am comparing elements of two double[] .one is an expected set like
double[] expected=new double[]{ 1.246,2.343,4.568};
while the second array is result of some calculation
public double[] mycalculations(){
double[] res=null;
......//calculate the array
....
return res;
}
and can be
{ 1.246,2.3430000001,4.56800002 }
for practical purposes these two are equal,when you round off the
elements to 3 decimal places.if i want to unit test my code i need to
compare elements of both arrays .How do i do the rounding off?
DecimalFormat only helps me to print or display the numbers.I need
some way to compare like
for(int i=0;i<expected.length;i++){
assertEquals( roundoff( expected ),roundoff( result[ i] ) );
}
can anybody suggest a way to do this?
thanks
jim
i am comparing elements of two double[] .one is an expected set like
double[] expected=new double[]{ 1.246,2.343,4.568};
while the second array is result of some calculation
public double[] mycalculations(){
double[] res=null;
......//calculate the array
....
return res;
}
and can be
{ 1.246,2.3430000001,4.56800002 }
for practical purposes these two are equal,when you round off the
elements to 3 decimal places.if i want to unit test my code i need to
compare elements of both arrays .How do i do the rounding off?
DecimalFormat only helps me to print or display the numbers.I need
some way to compare like
for(int i=0;i<expected.length;i++){
assertEquals( roundoff( expected ),roundoff( result[ i] ) );
}
can anybody suggest a way to do this?
thanks
jim