Tsqlt tests are failing even though Expected and Actual tables have same values

233 Views Asked by At

I am getting error failed: (Failure) Unexpected/missing resultset rows! for tsqlt tests even though Expected and Actual table has same result

volume 90Dayvolume Relative90Dvol
4493 16413368.1429 95.119153740058

In above example "Relative90Dvol" is being calculated with in stored procedure.If Relative90Dvol is a integer value say 95 the tests are being passed but if value is in float with decimal precision like 95.119153740058 tests are failing. How to handle such decimal precision values with tsqlt tests.

failed: (Failure) Unexpected/missing resultset rows!
|_m_|symbol |exchange|session|Time                |Open   | Volume             |Volume.90D          |Relative90D.Pct             |insert_Date         |
+---+-------+--------+-------+--------------------+-------------------+------------------------+------+--------------------+--------------------+-------------------+------------+-----------------+-----------------------+----------------------+---------+----------------------------+--------------------+
|<  |TEST1.O|NSQ     |0      |4.479070000000000E+4|!NULL! |1.292000000000000E+3|6.923157219780000E+6|8.635296985604490E+1        |4.479070000000000E+4|
|<  |TEST2.O|NSQ     |0      |4.479070000000000E+4|!NULL! |2.229000000000000E+3|9.369240538460000E+6|1.100841107726760E+2        |4.479070000000000E+4|
|>  |TEST2.O|NSQ     |0      |4.479070000000000E+4|!NULL! |2.229000000000000E+3|9.369240538460000E+6|1.100841107726760E+2        |4.479070000000000E+4|
|>  |TEST1.O|NSQ     |0      |4.479070000000000E+4|!NULL! |1.292000000000000E+3|6.923157219780000E+6|8.635296985604490E+1        |4.479070000000000E+4|
1

There are 1 best solutions below

0
FFFffff On

I usually end up implementing some tolerance. You can do that easily in the following manner:

declare @actual decimal(30,2);
declare @expected decimal(30,2) = 789.5;
declare @tolerance decimal(18,2) = 0.1;

IF @actual between @expected - @tolerance and @expected + @tolerance 
    set @actual = @expected;

EXEC tsqlt.AssertEquals @expected, @actual, @Message = '...';