How to validate number is within range of a number

Ask general questions here.
User avatar
Gunner1980
Posts: 89
Joined: Mon Apr 05, 2010 8:44 pm
Location: Austin, Texas

How to validate number is within range of a number

Post by Gunner1980 » Sat May 29, 2010 8:42 pm

So I already have code working to validate an int but the problem is that the number is going to be slightly different than what is entered everytime. When I validate I need to validate the value within a range not the exact value. For example when I enter a value of 15750 I may receive it as 15759 on the validation side. This is due to various rounding methods that happen in our system and is correct so I don't want this to show up as a failure in my tests. I would like to validate that the altitude equals 15750 plus or minus 25. So basically if 15750 was entered everything from 15725 to 15775 would pass the test.

Can anyone help me out please?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to validate number is within range of a number

Post by Support Team » Mon May 31, 2010 11:40 am

Hi,
Gunner1980 wrote:I would like to validate that the altitude equals 15750 plus or minus 25. So basically if 15750 was entered everything from 15725 to 15775 would pass the test.
Use the Validate.IsTrue() method to check if the value is inside your range.
Validate.IsTrue( (value > x - 25) && (value < x + 25) );
Regards,
Peter
Ranorex Support Team

User avatar
Gunner1980
Posts: 89
Joined: Mon Apr 05, 2010 8:44 pm
Location: Austin, Texas

Re: How to validate number is within range of a number

Post by Gunner1980 » Tue Jun 01, 2010 7:27 pm

Thanks that worked like a champ!