leonk
15 years agoNew Contributor
Testing inequality
I have the following code to test if a reading is within +/-25% of the expected value.
function testWithinLimits()
{
var expectedVal = 200;
var ErrorInPercent = 25;
var UpperLimit = expectedVal/1000 * ((100 + ErrorInPercent)/100);
var LowerLimit = expectedVal/1000 * ((100 - ErrorInPercent)/100);
var readVal = "0.15";
var reading = StrToFloat(readVal);
bResult1 = (reading <= UpperLimit);
bResult2 = (reading >= LowerLimit);
strMsg = FloatToStr(reading) + " <= " + FloatToStr(UpperLimit) + " is : " + bResult1;
strMsg += "\r\n";
strMsg += FloatToStr(reading) + " >= " + FloatToStr(LowerLimit) + " is : " + bResult2;
ShowMessage(strMsg);
}
The expected value is 0.2 so a range from 0.15 to 0.25 (inclusive) is allowed. My reading is 0.15 but the function shows a false result.
Have I missed a type conversion or made a serious error?
I'm using TestComplete v6.52.419.7.
Thanks, Leon.