Skip to content

Assert function for testing floating point equality #5243

Open
@Irubataru

Description

@Irubataru

Justification
I have a couple of unit tests where I have to check for floating point equality, and that can sometimes cause some problems. At the moment I have to make a separate function that returns a boolean and then use "IsTrue" instead.

Description
Would be great if we could have a separate AreEqualNumeric or something like that which checks for value equality taking things like floating point quirks into account. Possibly also allowing optional arguments for setting absolute/relative precision so that one can get information in the test explorer on values if the assert fails.

Optional suggestion
Another possibility would be to let the user themselves define assert'ers and have a special ExpectThat where you can pass an instance of an assert object defined in VBA with some expected methods such as Assert, Report etc which is what is used to fill out the test explorer with information. Then if I had implemented my own double precision assert class I could write

Assert.ExpectThat DoublesAreEqual, Number1, Number2, "Numbers from calculation are equal"

Where the DoublesAreEqual is some class in my VBA project with the necessary methods.

I have probably been informed before, but I am not entirely sure to what extent the Rubberduck can interact with the VBA code, so obviously I have no idea if this can be done. If it is possible then I can always spin this into a separate suggestion. If it could then that would also provide an additional workaround for the PermissiveAssert you have in your pipeline. This would also e.g. let users write special checkers for class equality etc so that you can reduce the number of asserts in a test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty-03-duckInvolves more challenging problems and/or developing within and revising the internals APIenhancementFeature requests, or enhancements to existing features. Ideas. Anything within the project's scope.feature-unit-testing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions