verifyApproxEquals()
Purpose
Checks that two variables have the same value within a given margin.
Syntax
verifyApproxEquals( [<string>, ] <variable1>, <variable2>, <precision> )
where:
<string> is an optional message
<variable1> and <variable2> are two Java type variables
<precision> is a precision argument
Description
The corresponding test result is Passed if the assertApproxEquals() condition is True and Failed if the condition is False.
Compared variables may be of any Java type: Boolean, float, double, short, byte, char, int, long or object. <variable1> and <variable2> must be of the same type.
An optional <string> message can be logged and displayed in the test report.
The <precision> argument specifies an acceptable margin.
If an exception is thrown in a verifyApproxEquals() method, an error is logged and the test continues.
Example
Char:
char valc1 = 'a';
char valc2 = 'e';
verifyApproxEquals("verify approx char passed", valc1,valc2, 10);
Byte:
byte valb1 = 5;
byte valb2 = 10;
verifyApproxEquals("verify approx byte passed", valb1,valb2, 10);
Short:
short val1 = 1;
short val2 = 5;
verifyAproxEquals("verify approx short passed", val1,val2, 10);
Int:
int vali1 = 1;
int vali2 = 20;
verifyApproxEquals("verify approx int passed", vali1,vali2, 20);
Long:
long vall1 = 1;
long vall2 = 20;
verifyApproxEquals("verify approx long passed", vall1,vall2, 20);
Float:
float valf1 = 1;
float valf2 = 20;
verifyApproxEquals("verify approx float passed", valf1,valf2, 20);
Double:
double vald1 = 1;
double vald2 = 20;
verifyApproxEquals("verify approx double passed", vald1,vald2, 20);
Related Topics