checkmate icon indicating copy to clipboard operation
checkmate copied to clipboard

Add an argument for open intervals in assert_numeric

Open JakubBujnowicz opened this issue 4 years ago • 3 comments

Currently lower acts as greater than or equal (>=) to lower. Would it be possible to add an another argument that would act as >? Or maybe something like boolean lower.eq that would decide whether equality is allowed.

Obviously the same goes for upper.

One can use a trick with the machine epsilon, i.e. assert_numeric(0, lower = .Machine$double.eps), but neither the code nor the error message (Error: Assertion on '0' failed: Element 1 is not >= 2.22045e-016.) is elegant. The same trick used for something other than zero may result in an even more confusing error message, i.e. assert_numeric(1, lower = 1 + .Machine$double.eps) leading to Error: Assertion on '1' failed: Element 1 is not >= 1..

JakubBujnowicz avatar Nov 03 '21 09:11 JakubBujnowicz

Yes, that is possible. However, I am currently busy with other projects, so it will take a while.

mllg avatar Nov 23 '21 11:11 mllg

That's great, thanks!

JakubBujnowicz avatar Nov 23 '21 11:11 JakubBujnowicz

I needed this earlier today, and I wrote a wrapper (that I didn't think was all that great, but it worked for my immediate need).

As I was thinking about how to implement this, I think that adding lower.condition = ">=" and upper.condition = ">=" would be the most straight-forward ways to do this. The alternative for lower.condition would be ">" and the alternative for upper.condition would be "<".

Using this interface would allow:

  1. backward compatibility,
  2. a clear interface for changing the condition, and
  3. different decisions for the lower and upper bounds.

billdenney avatar Sep 29 '23 01:09 billdenney