pFUnit
pFUnit copied to clipboard
feat: add relative equals that defaults to direct equals for small values
For relative equals there is check in case the values are small.
This commit provides a relative equals that defaults to direct when the values are small.
e.g. max(relative_tolerance*abs(expected), tolerance)
If there is a better way to do this please advise.
Originally I tried to keep with the naming convention, but ran into trouble with the length of function names and therefore used RelMinEqual which I really don't like.
Another thing that need some more attention is I didn't modify the added test yet to evaluate the threshold. It would be good to get feedback that this is the right approach before doing more.
I decided to rename the function to approx to simplify the name length, and mirror the name use by pytest as there doesn't appear to be an equivalent in JUnit. I removed the relative difference calculation as providing the difference and calculated tolerance is sufficient to describe the criteria that is failing.
Looks like it would not be too difficult to introduce aliases, but I'd not ask you to implement it.
The intro would define a small dictionary whose keys are the annotations and the values are the Fortran procedure names. It would then intercept the usual expansion:
parser.outputFile.write(fragment.format(match.group(1), match.group(2)))
I made a simple example on this branch.
https://github.com/kurtsansom/pFUnit/tree/assert_alias
map:
assert_alias_map = {'approx' : 'ApproxEqual'}
in class AtAssert(Action):
if (match.group(1).lower() in self.alias_map.keys()):
function_name = self.alias_map[match.group(1).lower()]
else:
function_name = match.group(1)
Same request as the other. Please change to PR onto develop branch.
I will shoot for getting to this by the end of the week.
@kurtsansom - do you still intend to resubmit this as a PR onto develop?
@tclune Apologies this has fallen off my radar. It looks like I just missed fixing this by about a week.