idris2-hedgehog icon indicating copy to clipboard operation
idris2-hedgehog copied to clipboard

How to add test cases that will always be used?

Open joelberkeley opened this issue 3 years ago • 2 comments

I'm testing with Doubles, and I'd like to be sure that -1/0, 1/0 and 0/0 are always used. Is there a function for this? I know I can just create separate tests with constant 0/0 etc. but that quickly becomes messy with all combinations when testing binary functions. Can I combine e.g.

double (exponentialDoubleFrom (-999) 0 999)

with these constants such that it always checks those examples?

I guess an alternative is to combine such Ranges but I also don't know how to do that

joelberkeley avatar Apr 04 '22 16:04 joelberkeley

How about:


doubleWithCornerCases : Gen Double
doubleWithCornerCases =
  frequency [ (4, double $ linearFracFrom 0 (-999) 999)
            , (1, element [-1 / 0, 1 / 0, 0 / 0])
            ]

If the frequency of the corner cases is set to a large enough value, these will be included. This might not be exactly what you are looking for, but I guess it gets you close enough. I'll have a look and see if I can come up with an even stricter solution.

stefan-hoeck avatar Apr 04 '22 18:04 stefan-hoeck

That works for now, yes thanks. A strict option would be great

joelberkeley avatar Apr 08 '22 16:04 joelberkeley