Created
January 18, 2018 16:37
-
-
Save CD3/b3cf45c02623d3eb4fa9012a2e23ada2 to your computer and use it in GitHub Desktop.
An Approx class for unit testing float values similar to Catch2 (https://github.com/catchorg/Catch2/blob/master/docs/assertions.md#floating-point-comparisons)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Approx(object): | |
def __init__(self,val): | |
self._val = val | |
self._epsilon = 0.01 | |
def epsilon(self,epsilon): | |
self._epsilon = epsilon | |
return self | |
def __eq__(self,other): | |
return abs(other - self._val) <= self._epsilon*abs(other + self._val)/2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment