Exemplo n.º 1
0
    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = RelativeStrengthIndex(10)

        bar = TestDataStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        assert indicator.has_inputs
        assert indicator.value == 1.0
Exemplo n.º 2
0
    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = RelativeStrengthIndex(10)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        self.assertTrue(indicator.has_inputs)
        self.assertEqual(1.0, indicator.value)
Exemplo n.º 3
0
 def setUp(self):
     # Arrange
     self.rsi = RelativeStrengthIndex(10)
Exemplo n.º 4
0
class RelativeStrengthIndexTests(unittest.TestCase):

    # Fixture Setup
    def setUp(self):
        # Arrange
        self.rsi = RelativeStrengthIndex(10)

    def test_name_returns_expected_name(self):
        # Act
        # Assert
        self.assertEqual("RelativeStrengthIndex", self.rsi.name)

    def test_str_returns_expected_string(self):
        # Act
        # Assert
        self.assertEqual("RelativeStrengthIndex(10, EXPONENTIAL)", str(self.rsi))

    def test_repr_returns_expected_string(self):
        # Act
        # Assert
        self.assertTrue(repr(self.rsi).startswith(
            "<RelativeStrengthIndex(10, EXPONENTIAL) object at"))
        self.assertTrue(repr(self.rsi).endswith(">"))

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

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

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

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

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

        # Act
        # Assert
        self.assertEqual(1, self.rsi.value)

    def test_value_with_all_higher_inputs_returns_expected_value(self):
        # Arrange
        self.rsi.update_raw(1.00000)
        self.rsi.update_raw(2.00000)
        self.rsi.update_raw(3.00000)
        self.rsi.update_raw(4.00000)

        # Act
        # Assert
        self.assertEqual(1, self.rsi.value)

    def test_value_with_all_lower_inputs_returns_expected_value(self):
        # Arrange
        self.rsi.update_raw(3.00000)
        self.rsi.update_raw(2.00000)
        self.rsi.update_raw(1.00000)
        self.rsi.update_raw(0.50000)

        # Act
        # Assert
        self.assertEqual(0, self.rsi.value)

    def test_value_with_various_inputs_returns_expected_value(self):
        # Arrange
        self.rsi.update_raw(3.00000)
        self.rsi.update_raw(2.00000)
        self.rsi.update_raw(5.00000)
        self.rsi.update_raw(6.00000)
        self.rsi.update_raw(7.00000)
        self.rsi.update_raw(6.00000)

        # Act
        # Assert
        self.assertEqual(0.6837363325825265, self.rsi.value)

    def test_value_at_returns_expected_value(self):
        # Arrange
        self.rsi.update_raw(3.00000)
        self.rsi.update_raw(2.00000)
        self.rsi.update_raw(5.00000)
        self.rsi.update_raw(6.00000)
        self.rsi.update_raw(7.00000)
        self.rsi.update_raw(6.00000)
        self.rsi.update_raw(6.00000)
        self.rsi.update_raw(7.00000)

        # Act
        # Assert
        self.assertEqual(0.7615344667662725, self.rsi.value)

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

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

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

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

        # Assert
        self.assertEqual(len(battery_signal), len(output))
Exemplo n.º 5
0
 def setup(self):
     # Fixture Setup
     self.rsi = RelativeStrengthIndex(10)
Exemplo n.º 6
0
class TestRelativeStrengthIndex:
    def setup(self):
        # Fixture Setup
        self.rsi = RelativeStrengthIndex(10)

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

    def test_str_repr_returns_expected_string(self):
        # Arrange, Act, Assert
        assert str(self.rsi) == "RelativeStrengthIndex(10, EXPONENTIAL)"
        assert repr(self.rsi) == "RelativeStrengthIndex(10, EXPONENTIAL)"

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

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

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

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

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

        bar = TestDataStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

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

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

        # Act, Assert
        assert self.rsi.value == 1

    def test_value_with_all_higher_inputs_returns_expected_value(self):
        # Arrange
        self.rsi.update_raw(1.00000)
        self.rsi.update_raw(2.00000)
        self.rsi.update_raw(3.00000)
        self.rsi.update_raw(4.00000)

        # Act, Assert
        assert self.rsi.value == 1

    def test_value_with_all_lower_inputs_returns_expected_value(self):
        # Arrange
        self.rsi.update_raw(3.00000)
        self.rsi.update_raw(2.00000)
        self.rsi.update_raw(1.00000)
        self.rsi.update_raw(0.50000)

        # Act, Assert
        assert self.rsi.value == 0

    def test_value_with_various_inputs_returns_expected_value(self):
        # Arrange
        self.rsi.update_raw(3.00000)
        self.rsi.update_raw(2.00000)
        self.rsi.update_raw(5.00000)
        self.rsi.update_raw(6.00000)
        self.rsi.update_raw(7.00000)
        self.rsi.update_raw(6.00000)

        # Act, Assert
        assert self.rsi.value == 0.6837363325825265

    def test_value_at_returns_expected_value(self):
        # Arrange
        self.rsi.update_raw(3.00000)
        self.rsi.update_raw(2.00000)
        self.rsi.update_raw(5.00000)
        self.rsi.update_raw(6.00000)
        self.rsi.update_raw(7.00000)
        self.rsi.update_raw(6.00000)
        self.rsi.update_raw(6.00000)
        self.rsi.update_raw(7.00000)

        # Act, Assert
        assert self.rsi.value == 0.7615344667662725

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

        # Act
        self.rsi.reset()

        # Assert
        assert not self.rsi.initialized
        assert self.rsi.value == 0
Exemplo n.º 7
0
class RelativeStrengthIndexTests(unittest.TestCase):

    def setUp(self):
        # Fixture Setup
        self.rsi = RelativeStrengthIndex(10)

    def test_name_returns_expected_string(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual("RelativeStrengthIndex", self.rsi.name)

    def test_str_repr_returns_expected_string(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual("RelativeStrengthIndex(10, EXPONENTIAL)", str(self.rsi))
        self.assertEqual("RelativeStrengthIndex(10, EXPONENTIAL)", repr(self.rsi))

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

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

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

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

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

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

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

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

        # Act
        # Assert
        self.assertEqual(1, self.rsi.value)

    def test_value_with_all_higher_inputs_returns_expected_value(self):
        # Arrange
        self.rsi.update_raw(1.00000)
        self.rsi.update_raw(2.00000)
        self.rsi.update_raw(3.00000)
        self.rsi.update_raw(4.00000)

        # Act
        # Assert
        self.assertEqual(1, self.rsi.value)

    def test_value_with_all_lower_inputs_returns_expected_value(self):
        # Arrange
        self.rsi.update_raw(3.00000)
        self.rsi.update_raw(2.00000)
        self.rsi.update_raw(1.00000)
        self.rsi.update_raw(0.50000)

        # Act
        # Assert
        self.assertEqual(0, self.rsi.value)

    def test_value_with_various_inputs_returns_expected_value(self):
        # Arrange
        self.rsi.update_raw(3.00000)
        self.rsi.update_raw(2.00000)
        self.rsi.update_raw(5.00000)
        self.rsi.update_raw(6.00000)
        self.rsi.update_raw(7.00000)
        self.rsi.update_raw(6.00000)

        # Act
        # Assert
        self.assertEqual(0.6837363325825265, self.rsi.value)

    def test_value_at_returns_expected_value(self):
        # Arrange
        self.rsi.update_raw(3.00000)
        self.rsi.update_raw(2.00000)
        self.rsi.update_raw(5.00000)
        self.rsi.update_raw(6.00000)
        self.rsi.update_raw(7.00000)
        self.rsi.update_raw(6.00000)
        self.rsi.update_raw(6.00000)
        self.rsi.update_raw(7.00000)

        # Act
        # Assert
        self.assertEqual(0.7615344667662725, self.rsi.value)

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

        # Act
        self.rsi.reset()

        # Assert
        self.assertFalse(self.rsi.initialized)
        self.assertEqual(0, self.rsi.value)