Skip to content

Decimal precision lost in assertion messages #20

Description

@mikepotjer

I have part of a test that checks if the value coming from a Currency field in a cursor is being rounded to 2 decimal places. Because of the default setting of SET DECIMALS TO, and the way TRANSFORM() formats a currency value, the failure message from FoxUnit looks like this:

-------------------------------
------Assertion Failure
-------------------------------
Pay Rate 00004 calculated wages are incorrect
Values Not Equal
Expected Value: $250.00
Actual Value: $250.00
-------------------------------
------Assertion Failure
-------------------------------
Pay Rate 00005 calculated wages are incorrect
Values Not Equal
Expected Value: $250.00
Actual Value: $250.00

I don't want to take the time to figure out where to plug in this code right now, but I did come up with a replacement function for TRANSFORM() which preserves decimal precision on all numbers, though you do lose the currency formatting. Here's the code that does that:

LPARAMETERS tuValue

LOCAL lcSetFixed, ;
  lcString, ;
  lnSetDecimals

DO CASE
  CASE VARTYPE( m.tuValue ) = "C"
    lcString = m.tuValue

  CASE INLIST( VARTYPE( m.tuValue ), "N", "Y" )
    * Force all relevant decimal places to be displayed.
    lcSetFixed = SET("Fixed")
    SET FIXED OFF
    lnSetDecimals = SET("Decimals")
    SET DECIMALS TO 18

    lcString = TRANSFORM( IIF( VARTYPE( m.tuValue ) = "Y", MTON( m.tuValue ), m.tuValue ) )

    SET FIXED &lcSetFixed.
    SET DECIMALS TO m.lnSetDecimals

  CASE ISNULL( m.tuValue )
    * In case SET NULLDISPLAY is something other than the default.
    lcString = ".NULL."

  OTHERWISE
    lcString = TRANSFORM( m.tuValue )
ENDCASE

RETURN m.lcString

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions