示例#1
0
class HullMovingAverageTests(unittest.TestCase):

    # Fixture Setup
    def setUp(self):
        # Arrange
        self.hma = HullMovingAverage(10)

    def test_name_returns_expected_name(self):
        # Act
        # Assert
        self.assertEqual("HullMovingAverage", self.hma.name)

    def test_str_returns_expected_string(self):
        # Act
        # Assert
        self.assertEqual("HullMovingAverage(10)", str(self.hma))

    def test_repr_returns_expected_string(self):
        # Act
        # Assert
        self.assertTrue(
            repr(self.hma).startswith("<HullMovingAverage(10) object at"))
        self.assertTrue(repr(self.hma).endswith(">"))

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        self.hma.update_raw(1.00000)
        self.hma.update_raw(2.00000)
        self.hma.update_raw(3.00000)
        self.hma.update_raw(4.00000)
        self.hma.update_raw(5.00000)
        self.hma.update_raw(6.00000)
        self.hma.update_raw(7.00000)
        self.hma.update_raw(8.00000)
        self.hma.update_raw(9.00000)
        self.hma.update_raw(10.00000)

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

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.hma.update_raw(1.00000)

        # Act
        # Assert
        self.assertEqual(1.0, self.hma.value)

    def test_value_with_three_inputs_returns_expected_value(self):
        # Arrange
        self.hma.update_raw(1.00000)
        self.hma.update_raw(2.00000)
        self.hma.update_raw(3.00000)

        # Act
        # Assert
        self.assertEqual(1.8245614035087718, self.hma.value)

    def test_value_with_ten_inputs_returns_expected_value(self):
        # Arrange
        self.hma.update_raw(1.00000)
        self.hma.update_raw(1.00010)
        self.hma.update_raw(1.00020)
        self.hma.update_raw(1.00030)
        self.hma.update_raw(1.00040)
        self.hma.update_raw(1.00050)
        self.hma.update_raw(1.00040)
        self.hma.update_raw(1.00030)
        self.hma.update_raw(1.00020)
        self.hma.update_raw(1.00010)
        self.hma.update_raw(1.00000)

        # Act
        # Assert
        self.assertEqual(1.0001403928170594, self.hma.value)

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        self.hma.update_raw(1.00020)
        self.hma.update_raw(1.00030)
        self.hma.update_raw(1.00050)

        # Act
        self.hma.reset()  # No assertion errors.

    def test_with_battery_signal(self):
        # Arrange
        battery_signal = BatterySeries.create()
        output = []

        # Act
        for point in battery_signal:
            self.hma.update_raw(point)
            output.append(self.hma.value)

        # Assert
        self.assertEqual(len(battery_signal), len(output))
示例#2
0
class HullMovingAverageTests(unittest.TestCase):
    def setUp(self):
        # Fixture Setup
        self.hma = HullMovingAverage(10)

    def test_name_returns_expected_string(self):
        # Act
        # Assert
        self.assertEqual("HullMovingAverage", self.hma.name)

    def test_str_repr_returns_expected_string(self):
        # Act
        # Assert
        self.assertEqual("HullMovingAverage(10)", str(self.hma))
        self.assertEqual("HullMovingAverage(10)", repr(self.hma))

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        self.hma.update_raw(1.00000)
        self.hma.update_raw(2.00000)
        self.hma.update_raw(3.00000)
        self.hma.update_raw(4.00000)
        self.hma.update_raw(5.00000)
        self.hma.update_raw(6.00000)
        self.hma.update_raw(7.00000)
        self.hma.update_raw(8.00000)
        self.hma.update_raw(9.00000)
        self.hma.update_raw(10.00000)

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

    def test_handle_quote_tick_updates_indicator(self):
        # Arrange
        indicator = HullMovingAverage(10, PriceType.MID)

        tick = TestStubs.quote_tick_5decimal(AUDUSD_SIM.symbol)

        # Act
        indicator.handle_quote_tick(tick)

        # Assert
        self.assertTrue(indicator.has_inputs)
        self.assertEqual(1.00002, indicator.value)

    def test_handle_trade_tick_updates_indicator(self):
        # Arrange
        indicator = HullMovingAverage(10, PriceType.MID)

        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.value)

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

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        self.assertTrue(indicator.has_inputs)
        self.assertEqual(1.00003, indicator.value)

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.hma.update_raw(1.00000)

        # Act
        # Assert
        self.assertEqual(1.0, self.hma.value)

    def test_value_with_three_inputs_returns_expected_value(self):
        # Arrange
        self.hma.update_raw(1.00000)
        self.hma.update_raw(2.00000)
        self.hma.update_raw(3.00000)

        # Act
        # Assert
        self.assertEqual(1.8245614035087718, self.hma.value)

    def test_value_with_ten_inputs_returns_expected_value(self):
        # Arrange
        self.hma.update_raw(1.00000)
        self.hma.update_raw(1.00010)
        self.hma.update_raw(1.00020)
        self.hma.update_raw(1.00030)
        self.hma.update_raw(1.00040)
        self.hma.update_raw(1.00050)
        self.hma.update_raw(1.00040)
        self.hma.update_raw(1.00030)
        self.hma.update_raw(1.00020)
        self.hma.update_raw(1.00010)
        self.hma.update_raw(1.00000)

        # Act
        # Assert
        self.assertEqual(1.0001403928170594, self.hma.value)

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        self.hma.update_raw(1.00020)
        self.hma.update_raw(1.00030)
        self.hma.update_raw(1.00050)

        # Act
        self.hma.reset()

        # Assert
        self.assertFalse(self.hma.initialized)
示例#3
0
class TestHullMovingAverage:
    def setup(self):
        # Fixture Setup
        self.hma = HullMovingAverage(10)

    def test_name_returns_expected_string(self):
        # Act, Assert
        assert self.hma.name == "HullMovingAverage"

    def test_str_repr_returns_expected_string(self):
        # Act, Assert
        assert str(self.hma) == "HullMovingAverage(10)"
        assert repr(self.hma) == "HullMovingAverage(10)"

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        self.hma.update_raw(1.00000)
        self.hma.update_raw(2.00000)
        self.hma.update_raw(3.00000)
        self.hma.update_raw(4.00000)
        self.hma.update_raw(5.00000)
        self.hma.update_raw(6.00000)
        self.hma.update_raw(7.00000)
        self.hma.update_raw(8.00000)
        self.hma.update_raw(9.00000)
        self.hma.update_raw(10.00000)

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

    def test_handle_quote_tick_updates_indicator(self):
        # Arrange
        indicator = HullMovingAverage(10, PriceType.MID)

        tick = TestDataStubs.quote_tick_5decimal(AUDUSD_SIM.id)

        # Act
        indicator.handle_quote_tick(tick)

        # Assert
        assert indicator.has_inputs
        assert indicator.value == 1.00002

    def test_handle_trade_tick_updates_indicator(self):
        # Arrange
        indicator = HullMovingAverage(10, PriceType.MID)

        tick = TestDataStubs.trade_tick_5decimal(AUDUSD_SIM.id)

        # Act
        indicator.handle_trade_tick(tick)

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

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

        bar = TestDataStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        assert indicator.has_inputs
        assert indicator.value == 1.00003

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.hma.update_raw(1.00000)

        # Act, Assert
        assert self.hma.value == 1.0

    def test_value_with_three_inputs_returns_expected_value(self):
        # Arrange
        self.hma.update_raw(1.00000)
        self.hma.update_raw(2.00000)
        self.hma.update_raw(3.00000)

        # Act, Assert
        assert self.hma.value == 1.8245614035087718

    def test_value_with_ten_inputs_returns_expected_value(self):
        # Arrange
        self.hma.update_raw(1.00000)
        self.hma.update_raw(1.00010)
        self.hma.update_raw(1.00020)
        self.hma.update_raw(1.00030)
        self.hma.update_raw(1.00040)
        self.hma.update_raw(1.00050)
        self.hma.update_raw(1.00040)
        self.hma.update_raw(1.00030)
        self.hma.update_raw(1.00020)
        self.hma.update_raw(1.00010)
        self.hma.update_raw(1.00000)

        # Act, Assert
        assert self.hma.value == 1.0001403928170594

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        self.hma.update_raw(1.00020)
        self.hma.update_raw(1.00030)
        self.hma.update_raw(1.00050)

        # Act
        self.hma.reset()

        # Assert
        assert not self.hma.initialized