reports: Balance.le/ge_zero returns False when exactly at tolerance.
This commit is contained in:
parent
95ba1638d2
commit
39fa977f71
2 changed files with 8 additions and 2 deletions
|
@ -167,11 +167,13 @@ class Balance(Mapping[str, data.Amount]):
|
||||||
|
|
||||||
def ge_zero(self) -> bool:
|
def ge_zero(self) -> bool:
|
||||||
"""Returns true if all amounts in the balance >= 0, within tolerance."""
|
"""Returns true if all amounts in the balance >= 0, within tolerance."""
|
||||||
return self._all_amounts(operator.ge, -self.tolerance)
|
op_func = operator.gt if self.tolerance else operator.ge
|
||||||
|
return self._all_amounts(op_func, -self.tolerance)
|
||||||
|
|
||||||
def le_zero(self) -> bool:
|
def le_zero(self) -> bool:
|
||||||
"""Returns true if all amounts in the balance <= 0, within tolerance."""
|
"""Returns true if all amounts in the balance <= 0, within tolerance."""
|
||||||
return self._all_amounts(operator.le, self.tolerance)
|
op_func = operator.lt if self.tolerance else operator.le
|
||||||
|
return self._all_amounts(op_func, self.tolerance)
|
||||||
|
|
||||||
def format(self,
|
def format(self,
|
||||||
fmt: Optional[str]='#,#00.00 ¤¤',
|
fmt: Optional[str]='#,#00.00 ¤¤',
|
||||||
|
|
|
@ -112,6 +112,8 @@ def test_eq_zero(mapping, expected):
|
||||||
({'JPY': 10, 'BRL': 20}, True),
|
({'JPY': 10, 'BRL': 20}, True),
|
||||||
({'USD': '0.00015'}, True),
|
({'USD': '0.00015'}, True),
|
||||||
({'EUR': '-0.00052'}, True),
|
({'EUR': '-0.00052'}, True),
|
||||||
|
({'RUB': core.Balance.TOLERANCE}, True),
|
||||||
|
({'RUB': -core.Balance.TOLERANCE}, False),
|
||||||
])
|
])
|
||||||
def test_ge_zero(mapping, expected):
|
def test_ge_zero(mapping, expected):
|
||||||
balance = core.Balance(amounts_from_map(mapping))
|
balance = core.Balance(amounts_from_map(mapping))
|
||||||
|
@ -129,6 +131,8 @@ def test_ge_zero(mapping, expected):
|
||||||
({'JPY': 10, 'BRL': 20}, False),
|
({'JPY': 10, 'BRL': 20}, False),
|
||||||
({'USD': '0.00015'}, True),
|
({'USD': '0.00015'}, True),
|
||||||
({'EUR': '-0.00052'}, True),
|
({'EUR': '-0.00052'}, True),
|
||||||
|
({'RUB': core.Balance.TOLERANCE}, False),
|
||||||
|
({'RUB': -core.Balance.TOLERANCE}, True),
|
||||||
])
|
])
|
||||||
def test_le_zero(mapping, expected):
|
def test_le_zero(mapping, expected):
|
||||||
balance = core.Balance(amounts_from_map(mapping))
|
balance = core.Balance(amounts_from_map(mapping))
|
||||||
|
|
Loading…
Reference in a new issue