vunit icon indicating copy to clipboard operation
vunit copied to clipboard

CHECK_EQUAL_VARIANCE with variance of 0 should default to CHECK_EQUAL

Open jonatasp1016 opened this issue 4 years ago • 3 comments

The CHECK_EQUAL_VARIANCE macro in the vunit_defines.svh file does the following assertion.

define CHECK_EQUAL_VARIANCE(got,expected,variance,msg=__none__) assert (((got) < ((expected) + (variance))) && ((got) > ((expected) - (variance)))) else ....

I tried using the macro by passing the variance as a percentage of a variable: CHECK_EQUAL_VARIANCE(got.bucket_a, result.bucket_a, result.bucket_a*0.002) , but for cases in which result.bucket_a was zero, the check failed, basically because the variance passed was also zero. I believe it would be more correct for the macro to check with less than or equal to / greater than or equal to instead of plain less than / greater than.

I.e.: (((got) <= ((expected) + (variance))) && ((got) >= ((expected) - (variance))))

instead of: (((got) < ((expected) + (variance))) && ((got) > ((expected) - (variance))))

In that case, CHECK_EQUAL_VARIANCE would implicitly default to CHECK_EQUAL in case of variance=0

jonatasp1016 avatar Aug 16 '21 08:08 jonatasp1016

@dbalthazor What is you view on this? I know that at least Python unittest accept values right on the boundaries of the range.

LarsAsplund avatar Aug 18 '21 19:08 LarsAsplund

I don't have particularly strong feelings one way or another, I'll let you make the call whether that comparison should be inclusive or exclusive. Either way, a test case for variance 0 should be added that checks for this edge case.

dbalthazor avatar Aug 18 '21 23:08 dbalthazor

@jonatasp1016 @dbalthazor Then I suggest we change. A PR @jonatasp1016?

LarsAsplund avatar Aug 22 '21 08:08 LarsAsplund