crmPack icon indicating copy to clipboard operation
crmPack copied to clipboard

open interval constraint in assertions at checkmate

Open wwojciech opened this issue 4 years ago • 1 comments

Why the first test gives TRUE, instead of FALSE, while the second one is ok? How to check that x > 1, not x >= 1?

> test_number(x = 1, lower = 1 + .Machine$double.xmin)
[1] TRUE
> test_number(x = 0, lower = .Machine$double.xmin)
[1] FALSE

More evidences:

> assert_number(1, lower = 1 + .Machine$double.xmin)
> assert_number(0.9, lower = 1 + .Machine$double.xmin)
Error: Assertion on '0.9' failed: Element 1 is not >= 1.
> assert_number(0, lower = .Machine$double.xmin)
Error: Assertion on '0' failed: Element 1 is not >= 2.22507e-308.

wwojciech avatar Mar 16 '22 11:03 wwojciech

This results from finite arithmetic precision. Possibly, we could create a new wrapper-helper, e.g. test_number_bounds that checks whether numbers are in a given interval using <, >.

wwojciech avatar Apr 14 '22 07:04 wwojciech