Example #1
0
    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = KeltnerChannel(10, 2.5, MovingAverageType.EXPONENTIAL, MovingAverageType.SIMPLE)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        assert indicator.has_inputs
        assert indicator.middle == 1.0000266666666666
 def setUp(self):
     # Arrange
     self.kc = KeltnerChannel(10, 2.5, MovingAverageType.EXPONENTIAL,
                              MovingAverageType.SIMPLE)
class KeltnerChannelTests(unittest.TestCase):

    # Fixture Setup
    def setUp(self):
        # Arrange
        self.kc = KeltnerChannel(10, 2.5, MovingAverageType.EXPONENTIAL,
                                 MovingAverageType.SIMPLE)

    def test_name_returns_expected_name(self):
        # Act
        # Assert
        self.assertEqual('KeltnerChannel', self.kc.name)

    def test_str_returns_expected_string(self):
        # Act
        # Assert
        self.assertEqual(
            'KeltnerChannel(10, 2.5, EXPONENTIAL, SIMPLE, True, 0.0)',
            str(self.kc))

    def test_repr_returns_expected_string(self):
        # Act
        # Assert
        self.assertTrue(
            repr(self.kc).startswith(
                '<KeltnerChannel(10, 2.5, EXPONENTIAL, SIMPLE, True, 0.0) object at'
            ))
        self.assertTrue(repr(self.kc).endswith('>'))

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

    def test_k_multiple_returns_expected_value(self):
        # Act
        # Assert
        self.assertEqual(2.5, self.kc.k_multiplier)

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        self.kc.update(1.00020, 1.00000, 1.00010)
        self.kc.update(1.00020, 1.00000, 1.00010)
        self.kc.update(1.00020, 1.00000, 1.00010)
        self.kc.update(1.00020, 1.00000, 1.00010)
        self.kc.update(1.00020, 1.00000, 1.00010)
        self.kc.update(1.00020, 1.00000, 1.00010)
        self.kc.update(1.00020, 1.00000, 1.00010)
        self.kc.update(1.00020, 1.00000, 1.00010)
        self.kc.update(1.00020, 1.00000, 1.00010)
        self.kc.update(1.00020, 1.00000, 1.00010)

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

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.kc.update(1.00020, 1.00000, 1.00010)

        # Act
        # Assert
        self.assertEqual(1.0006, self.kc.value_upper_band)
        self.assertEqual(1.0001, self.kc.value_middle_band)
        self.assertEqual(0.9996, self.kc.value_lower_band)

    def test_value_with_three_inputs_returns_expected_value(self):
        # Arrange
        self.kc.update(1.00020, 1.00000, 1.00010)
        self.kc.update(1.00030, 1.00010, 1.00020)
        self.kc.update(1.00040, 1.00020, 1.00030)

        # Act
        # Assert
        self.assertEqual(1.0006512396694212, self.kc.value_upper_band)
        self.assertEqual(1.0001512396694212, self.kc.value_middle_band)
        self.assertEqual(0.9996512396694213, self.kc.value_lower_band)

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        self.kc.update(1.00020, 1.00000, 1.00010)
        self.kc.update(1.00030, 1.00010, 1.00020)
        self.kc.update(1.00040, 1.00020, 1.00030)

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

    def test_with_battery_signal(self):
        # Arrange
        battery_signal = BatterySeries.create()
        output1 = []
        output2 = []
        output3 = []

        # Act
        for point in BatterySeries.create():
            self.kc.update(point, sys.float_info.epsilon,
                           sys.float_info.epsilon)
            output1.append(self.kc.value_upper_band)
            output2.append(self.kc.value_middle_band)
            output3.append(self.kc.value_lower_band)

        # Assert
        self.assertEqual(len(battery_signal), len(output1))
        self.assertEqual(len(battery_signal), len(output2))
        self.assertEqual(len(battery_signal), len(output3))
Example #4
0
 def setup(self):
     # Fixture Setup
     self.kc = KeltnerChannel(10, 2.5, MovingAverageType.EXPONENTIAL, MovingAverageType.SIMPLE)
Example #5
0
class TestKeltnerChannel:
    def setup(self):
        # Fixture Setup
        self.kc = KeltnerChannel(10, 2.5, MovingAverageType.EXPONENTIAL, MovingAverageType.SIMPLE)

    def test_name_returns_expected_string(self):
        # Arrange, Act, Assert
        assert self.kc.name == "KeltnerChannel"

    def test_str_repr_returns_expected_string(self):
        # Arrange, Act, Assert
        assert str(self.kc) == "KeltnerChannel(10, 2.5, EXPONENTIAL, SIMPLE, True, 0.0)"
        assert repr(self.kc) == "KeltnerChannel(10, 2.5, EXPONENTIAL, SIMPLE, True, 0.0)"

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

    def test_k_multiple_returns_expected_value(self):
        # Arrange, Act, Assert
        assert self.kc.k_multiplier == 2.5

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)

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

    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = KeltnerChannel(10, 2.5, MovingAverageType.EXPONENTIAL, MovingAverageType.SIMPLE)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

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

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

        # Act, Assert
        assert self.kc.upper == 1.0006
        assert self.kc.middle == 1.0001
        assert self.kc.lower == 0.9996

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

        # Act, Assert
        assert self.kc.upper == 1.0006512396694212
        assert self.kc.middle == 1.0001512396694212
        assert self.kc.lower == 0.9996512396694213

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

        # Act
        self.kc.reset()

        # Assert
        assert not self.kc.initialized
class KeltnerChannelTests(unittest.TestCase):
    def setUp(self):
        # Fixture Setup
        self.kc = KeltnerChannel(
            10, 2.5, MovingAverageType.EXPONENTIAL, MovingAverageType.SIMPLE
        )

    def test_name_returns_expected_string(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual("KeltnerChannel", self.kc.name)

    def test_str_repr_returns_expected_string(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual(
            "KeltnerChannel(10, 2.5, EXPONENTIAL, SIMPLE, True, 0.0)", str(self.kc)
        )
        self.assertEqual(
            "KeltnerChannel(10, 2.5, EXPONENTIAL, SIMPLE, True, 0.0)", repr(self.kc)
        )

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

    def test_k_multiple_returns_expected_value(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual(2.5, self.kc.k_multiplier)

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)
        self.kc.update_raw(1.00020, 1.00000, 1.00010)

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

    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = KeltnerChannel(
            10, 2.5, MovingAverageType.EXPONENTIAL, MovingAverageType.SIMPLE
        )

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

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

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

        # Act
        # Assert
        self.assertEqual(1.0006, self.kc.upper)
        self.assertEqual(1.0001, self.kc.middle)
        self.assertEqual(0.9996, self.kc.lower)

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

        # Act
        # Assert
        self.assertEqual(1.0006512396694212, self.kc.upper)
        self.assertEqual(1.0001512396694212, self.kc.middle)
        self.assertEqual(0.9996512396694213, self.kc.lower)

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

        # Act
        self.kc.reset()

        # Assert
        self.assertFalse(self.kc.initialized)