コード例 #1
0
class TestDonchianChannel:
    def setup(self):
        # Fixture Setup
        self.dc = DonchianChannel(10)

    def test_name_returns_expected_name(self):
        # Arrange, Act, Assert
        assert self.dc.name == "DonchianChannel"

    def test_str_repr_returns_expected_string(self):
        # Arrange, Act, Assert
        assert str(self.dc) == "DonchianChannel(10)"
        assert repr(self.dc) == "DonchianChannel(10)"

    def test_period_returns_expected_value(self):
        # Arrange, Act, Assert
        assert self.dc.period == 10

    def test_initialized_without_inputs_returns_false(self):
        # Arrange, Act, Assert
        assert self.dc.initialized is False

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)

        # Act, Assert
        assert self.dc.initialized is True

    def test_handle_quote_tick_updates_indicator(self):
        # Arrange
        indicator = DonchianChannel(10)

        tick = TestStubs.quote_tick_5decimal(AUDUSD_SIM.id)

        # Act
        indicator.handle_quote_tick(tick)

        # Assert
        assert indicator.has_inputs
        assert indicator.middle == 1.0000200000000001

    def test_handle_trade_tick_updates_indicator(self):
        # Arrange
        indicator = DonchianChannel(10)

        tick = TestStubs.trade_tick_5decimal(AUDUSD_SIM.id)

        # Act
        indicator.handle_trade_tick(tick)

        # Assert
        assert indicator.has_inputs
        assert indicator.middle == 1.00001

    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = DonchianChannel(10)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        assert indicator.has_inputs
        assert indicator.middle == 1.000025

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.dc.update_raw(1.00020, 1.00000)

        # Act, Assert
        assert self.dc.upper == 1.00020
        assert self.dc.middle == 1.00010
        assert self.dc.lower == 1.00000

    def test_value_with_three_inputs_returns_expected_value(self):
        # Arrange
        self.dc.update_raw(1.00020, 1.00000)
        self.dc.update_raw(1.00030, 1.00010)
        self.dc.update_raw(1.00040, 1.00020)

        # Act, Assert
        assert self.dc.upper == 1.00040
        assert self.dc.middle == 1.00020
        assert self.dc.lower == 1.00000

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        self.dc.update_raw(1.00020, 1.00000)
        self.dc.update_raw(1.00030, 1.00010)
        self.dc.update_raw(1.00040, 1.00020)

        # Act
        self.dc.reset()

        # Assert
        assert not self.dc.initialized
        assert self.dc.upper == 0
        assert self.dc.middle == 0
        assert self.dc.lower == 0
コード例 #2
0
class DonchianChannelTests(unittest.TestCase):

    def setUp(self):
        # Fixture Setup
        self.dc = DonchianChannel(10)

    def test_name_returns_expected_name(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual("DonchianChannel", self.dc.name)

    def test_str_repr_returns_expected_string(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual("DonchianChannel(10)", str(self.dc))
        self.assertEqual("DonchianChannel(10)", repr(self.dc))

    def test_period_returns_expected_value(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual(10, self.dc.period)

    def test_initialized_without_inputs_returns_false(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual(False, self.dc.initialized)

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)
        self.dc.update_raw(1.00000, 1.00000)

        # Act
        # Assert
        self.assertEqual(True, self.dc.initialized)

    def test_handle_quote_tick_updates_indicator(self):
        # Arrange
        indicator = DonchianChannel(10)

        tick = TestStubs.quote_tick_5decimal(AUDUSD_SIM.symbol)

        # Act
        indicator.handle_quote_tick(tick)

        # Assert
        self.assertTrue(indicator.has_inputs)
        self.assertEqual(1.0000200000000001, indicator.middle)

    def test_handle_trade_tick_updates_indicator(self):
        # Arrange
        indicator = DonchianChannel(10)

        tick = TestStubs.trade_tick_5decimal(AUDUSD_SIM.symbol)

        # Act
        indicator.handle_trade_tick(tick)

        # Assert
        self.assertTrue(indicator.has_inputs)
        self.assertEqual(1.00001, indicator.middle)

    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = DonchianChannel(10)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        self.assertTrue(indicator.has_inputs)
        self.assertEqual(1.000025, indicator.middle)

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.dc.update_raw(1.00020, 1.00000)

        # Act
        # Assert
        self.assertEqual(1.00020, self.dc.upper)
        self.assertEqual(1.00010, self.dc.middle)
        self.assertEqual(1.00000, self.dc.lower)

    def test_value_with_three_inputs_returns_expected_value(self):
        # Arrange
        self.dc.update_raw(1.00020, 1.00000)
        self.dc.update_raw(1.00030, 1.00010)
        self.dc.update_raw(1.00040, 1.00020)

        # Act
        # Assert
        self.assertEqual(1.00040, self.dc.upper)
        self.assertEqual(1.00020, self.dc.middle)
        self.assertEqual(1.00000, self.dc.lower)

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        self.dc.update_raw(1.00020, 1.00000)
        self.dc.update_raw(1.00030, 1.00010)
        self.dc.update_raw(1.00040, 1.00020)

        # Act
        self.dc.reset()

        # Assert
        self.assertFalse(self.dc.initialized)
        self.assertEqual(0, self.dc.upper)
        self.assertEqual(0, self.dc.middle)
        self.assertEqual(0, self.dc.lower)