From 325fd8a7802fd533247edda120f928576f93c76f Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 24 Jan 2022 19:15:42 +0100 Subject: [PATCH] Add test with absolute values --- tests/strategy/test_strategy_helpers.py | 26 ++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tests/strategy/test_strategy_helpers.py b/tests/strategy/test_strategy_helpers.py index 244fa25bf..c52a02ab9 100644 --- a/tests/strategy/test_strategy_helpers.py +++ b/tests/strategy/test_strategy_helpers.py @@ -153,18 +153,22 @@ def test_stoploss_from_open(): def test_stoploss_from_absolute(): - assert stoploss_from_absolute(90, 100) == 1 - (90 / 100) - assert stoploss_from_absolute(100, 100) == 0 - assert stoploss_from_absolute(110, 100) == 0 - assert stoploss_from_absolute(100, 0) == 1 - assert stoploss_from_absolute(0, 100) == 1 + assert pytest.approx(stoploss_from_absolute(90, 100)) == 1 - (90 / 100) + assert pytest.approx(stoploss_from_absolute(90, 100)) == 0.1 + assert pytest.approx(stoploss_from_absolute(95, 100)) == 0.05 + assert pytest.approx(stoploss_from_absolute(100, 100)) == 0 + assert pytest.approx(stoploss_from_absolute(110, 100)) == 0 + assert pytest.approx(stoploss_from_absolute(100, 0)) == 1 + assert pytest.approx(stoploss_from_absolute(0, 100)) == 1 - assert stoploss_from_absolute(90, 100, True) == 0 - assert stoploss_from_absolute(100, 100, True) == 0 - assert stoploss_from_absolute(110, 100, True) == -(1 - (110/100)) - assert stoploss_from_absolute(100, 0, True) == 1 - assert stoploss_from_absolute(0, 100, True) == 0 - assert stoploss_from_absolute(100, 1, True) == 1 + assert pytest.approx(stoploss_from_absolute(90, 100, True)) == 0 + assert pytest.approx(stoploss_from_absolute(100, 100, True)) == 0 + assert pytest.approx(stoploss_from_absolute(110, 100, True)) == -(1 - (110/100)) + assert pytest.approx(stoploss_from_absolute(110, 100, True)) == 0.1 + assert pytest.approx(stoploss_from_absolute(105, 100, True)) == 0.05 + assert pytest.approx(stoploss_from_absolute(100, 0, True)) == 1 + assert pytest.approx(stoploss_from_absolute(0, 100, True)) == 0 + assert pytest.approx(stoploss_from_absolute(100, 1, True)) == 1 # TODO-lev: @pytest.mark.parametrize('candle_type', ['mark', ''])