Forum Discussion

pashooo's avatar
pashooo
Contributor
14 years ago

TC compare equal values and says they are not equal

Did anybody compare values having a lot of figures?

I get this message only once, comparing this value:



Object: Sys.Process("OptionsWorkshop").WPFObject("HwndSource: NewPositionForm", "New position").WPFObject("NewPositionForm", "New position", 1).WPFObject("DialogControl", "", 1).WPFObject("Grid", "", 1).WPFObject("PriceSpinner")

Property: Value

Expected value: 9211.00074695698

Actual value: 9211.00074695698



The values are equal!!! Whats wrong?? lot of figures?

4 Replies

  • Hi Pasha,



    The behavior you're facing is caused by a common problem with comparing floating-point numbers. In computers, floating-point numbers are represented as approximates rather than exact numbers (for example, the number 9211.00074695698 may really be 9211.00074695697999999999999), which may lead to comparison and presicion issues.



    Currently, checkpoints cannot correctly compare some floating-point numbers due to these specifics. We have an existing feature request to improve the checkpoint mechanism for comparing floating-point values, and I've increased its rating based on your post.



    Meanwhile, I'd suggest that you do not compare floating-point numbers directly, but instead subtract them and compare their difference against a very small value (used as the comparison precision). For example:

    var obj = Sys.Process("OptionsWorkshop").WPFObject("HwndSource: NewPositionForm", "New position").WPFObject("NewPositionForm", "New position", 1).WPFObject("DialogControl", "", 1).WPFObject("Grid", "", 1).WPFObject("PriceSpinner");



    var diff = Math.abs(obj.Value - 9211.00074695698);


    if (diff < 0.0000000001)


      // values are equal


    else


      // values are not equal
     
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    It may be that there is a non-printing character in the actual value.  This comparison in the object is a string comparison of characters and so there may be a difference like that.  Double check by inspecting the component directly and see if there are what appear to be spaces after the last digit.
  • andy_cheetham's avatar
    andy_cheetham
    Occasional Contributor
    I am also facing the very same issue and I would have thought that this would have been addressed in earlier version of the application.



    My situation is futher complicated by the fact that when I convert my Keyword Test to a Script I am getting an error message when the code attempt to get a value from one of the items from the .Net Property Grid. This is a seperate issue but it does mean I can't impliment the the suggested diffing method.



    Any further suggetions welcome.



    Cheers

    Andy