Skip to content

Support for tests on floating point numbers. #15

@smblott-github

Description

@smblott-github

With floating point calculations, the actual result is hardware dependent. Two algebraically equivalent calculations may yield slightly different values.

Suggestion: add explicit support for testing such values.

Support might look something like:

assert.withinEpsillon 0.001, oldWordRelevancy(...), newWordRelevancy(...) * 2
assert.withinFactor 0.001, oldWordRelevancy(...), newWordRelevancy(...) * 2

In the first case, we're looking for an absolute difference less than the given constant. In the second case, we're looking for the ratio of the difference to the absolute value (of the second argument, say) to be less than the given constant.

This came up for me while working on word relevancy in vimium. Amazingly, my floating point tests using isEqual work. But I'd be more comfortable working with test which are more likely to succeed on a variety of hardware platforms.

You might argue that such tests don't make sense for floating point calculations: they're always hardware dependent. And you'd have a point.

Or you might argue that such tests can always be constructed using the existing isTrue. And you'd be right there, too. However, all tests can be constructed in terms of isTrue. But explicit support from shoulda makes such tests easier to write and easier to read.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions