Commit 4ab14221 authored by Julien Muchembled's avatar Julien Muchembled

FloatEquivalenceTester: simplify commit 41890

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41899 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e37accfa
...@@ -80,22 +80,20 @@ class FloatEquivalenceTester(Predicate, EquivalenceTesterMixin): ...@@ -80,22 +80,20 @@ class FloatEquivalenceTester(Predicate, EquivalenceTesterMixin):
if self.isDecimalAlignmentEnabled(): if self.isDecimalAlignmentEnabled():
decision_value = self._round(decision_value) decision_value = self._round(decision_value)
prevision_value = self._round(prevision_value) prevision_value = self._round(prevision_value)
epsilon = 0
delta = decision_value - prevision_value else:
if type(delta) is float:
# XXX: What if prevision or decision is 0 ? # XXX: What if prevision or decision is 0 ?
# How to know if the other value is negligible or not ? # How to know if the other value is negligible or not ?
epsilon = abs(prevision_value * DEFAULT_PRECISION) epsilon = abs(prevision_value * DEFAULT_PRECISION)
__lt__ = lambda a, b: a < b - epsilon
else: delta = decision_value - prevision_value
from operator import __lt__
# XXX we should use appropriate property sheets and getter methods # XXX we should use appropriate property sheets and getter methods
# for these properties. # for these properties.
# Maybe, but beware of default values of quantity when doing so # Maybe, but beware of default values of quantity when doing so
absolute_tolerance_min = self.getProperty('quantity_range_min') absolute_tolerance_min = self.getProperty('quantity_range_min')
if absolute_tolerance_min is not None and \ if absolute_tolerance_min is not None and \
__lt__(delta, absolute_tolerance_min): delta < (absolute_tolerance_min or - epsilon):
return ( return (
prevision_value, decision_value, prevision_value, decision_value,
'The difference of ${property_name} between decision and prevision is less than ${value}.', 'The difference of ${property_name} between decision and prevision is less than ${value}.',
...@@ -103,7 +101,7 @@ class FloatEquivalenceTester(Predicate, EquivalenceTesterMixin): ...@@ -103,7 +101,7 @@ class FloatEquivalenceTester(Predicate, EquivalenceTesterMixin):
value=absolute_tolerance_min)) value=absolute_tolerance_min))
absolute_tolerance_max = self.getProperty('quantity_range_max') absolute_tolerance_max = self.getProperty('quantity_range_max')
if absolute_tolerance_max is not None and \ if absolute_tolerance_max is not None and \
__lt__(absolute_tolerance_max, delta): delta > (absolute_tolerance_max or epsilon):
return ( return (
prevision_value, decision_value, prevision_value, decision_value,
'The difference of ${property_name} between decision and prevision is larger than ${value}.', 'The difference of ${property_name} between decision and prevision is larger than ${value}.',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment