pFUnit icon indicating copy to clipboard operation
pFUnit copied to clipboard

feat: add relative equals that defaults to direct equals for small values

Open kurtsansom opened this issue 3 years ago • 7 comments

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.

kurtsansom avatar May 12 '21 19:05 kurtsansom

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.

kurtsansom avatar May 17 '21 19:05 kurtsansom

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)))

tclune avatar May 17 '21 20:05 tclune

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)

kurtsansom avatar May 17 '21 20:05 kurtsansom

Same request as the other. Please change to PR onto develop branch.

tclune avatar Jul 05 '21 20:07 tclune

I will shoot for getting to this by the end of the week.

kurtsansom avatar Jul 06 '21 16:07 kurtsansom

@kurtsansom - do you still intend to resubmit this as a PR onto develop?

tclune avatar Nov 15 '21 00:11 tclune

@tclune Apologies this has fallen off my radar. It looks like I just missed fixing this by about a week.

kurtsansom avatar Nov 23 '21 16:11 kurtsansom