Skip to content
Snippets Groups Projects

Asset range option

Merged Michał Kudela requested to merge kudmich/add_asset_range_option into master
All threads resolved!
Files
3
@@ -4,13 +4,15 @@ from copy import deepcopy
from decimal import Decimal
from functools import total_ordering
import operator
from typing import Any, Final, NoReturn, Optional, Union
from typing import Any, Final, NoReturn, Optional, TypeVar, Union
import abstractcp as acp
from test_tools.__private.exceptions import ParseError
from test_tools.__private.utilities.decimal_converter import DecimalConverter
AssetLimitT = TypeVar("AssetLimitT", bound="AssetBase")
@total_ordering
class AssetBase(acp.Abstract):
@@ -198,20 +200,21 @@ class Asset:
Usage:
tt.Asset.Range(lower_limit=tt.Asset.Hive(100), upper_limit=tt.Asset.Hive(110))
:param lower_limit is required
:param lower_limit is required. When tolerance is given it acts as the value to which we refer when specifying
the percentage range.
:param tolerance: is defined as a positive number, which is a percentage of the upper and lower deviations e.g:
asset = tt.Asset.Hive(100)
tt.Asset.Range(asset, tolerance=10) -> the range of this asset is from tt.Asset.Hive(90) to (100)
tt.Asset.Range(asset, tolerance=10) -> the range of this asset is from tt.Asset.Hive(90) to inclusive (100)
Upper limit and tolerance should be used interchangeably.
"""
def __init__(
self,
lower_limit: AssetBase,
upper_limit: Optional[AssetBase] = None,
lower_limit: AssetLimitT,
upper_limit: Optional[AssetLimitT] = None,
*,
tolerance: Optional[int] = None,
tolerance: Union[int, float, None] = None,
):
if not upper_limit and not tolerance:
raise TypeError("Range has to be specified with either `upper_limit` or `tolerance`")
@@ -219,9 +222,8 @@ class Asset:
if upper_limit and tolerance:
raise TypeError("Please choose only one option from `upper_limit` or `tolerance`")
if isinstance(tolerance, (int, float)):
if tolerance < 0:
raise TypeError("`tolerance` should be given as an positive number")
if tolerance and tolerance < 0:
raise TypeError("`tolerance` should be given as an positive number")
self.__lower_limit = lower_limit if upper_limit else lower_limit - (lower_limit * tolerance / 100)
self.__upper_limit = upper_limit if upper_limit else lower_limit + (lower_limit * tolerance / 100)
Loading