Beispiel #1
0
    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = OnBalanceVolume(100)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        self.assertTrue(indicator.has_inputs)
        self.assertEqual(100000, indicator.value)
Beispiel #2
0
    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = OnBalanceVolume(100)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        assert indicator.has_inputs
        assert indicator.value == 1000000
Beispiel #3
0
 def setUp(self):
     # Arrange
     self.obv = OnBalanceVolume(100)
Beispiel #4
0
class OnBalanceVolumeTests(unittest.TestCase):

    # Fixture Setup
    def setUp(self):
        # Arrange
        self.obv = OnBalanceVolume(100)

    def test_name_returns_expected_name(self):
        # Act
        # Assert
        self.assertEqual('OnBalanceVolume', self.obv.name)

    def test_str_returns_expected_string(self):
        # Act
        # Assert
        self.assertEqual('OnBalanceVolume(100)', str(self.obv))

    def test_repr_returns_expected_string(self):
        # Act
        # Assert
        self.assertTrue(
            repr(self.obv).startswith('<OnBalanceVolume(100) object at'))
        self.assertTrue(repr(self.obv).endswith('>'))

    def test_period_returns_expected_value(self):
        # Act
        # Assert
        self.assertEqual(100, self.obv.period)

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        for i in range(100):
            self.obv.update(1.00000, 1.00010, 10000)

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

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.obv.update(1.00000, 1.00010, 10000)

        # Act
        # Assert
        self.assertEqual(10000, self.obv.value)

    def test_values_with_higher_inputs_returns_expected_value(self):
        # Arrange
        self.obv.update(1.00000, 1.00010, 10000)
        self.obv.update(1.00000, 1.00010, 10000)
        self.obv.update(1.00000, 1.00010, 10000)
        self.obv.update(1.00000, 1.00010, 10000)
        self.obv.update(1.00000, 1.00000, 10000)
        self.obv.update(1.00000, 1.00010, 10000)
        self.obv.update(1.00000, 1.00010, 10000)
        self.obv.update(1.00000, 1.00010, 10000)
        self.obv.update(1.00000, 1.00010, 10000)
        self.obv.update(1.00000, 1.00010, 10000)

        # Act
        # Assert
        self.assertEqual(90000.0, self.obv.value)

    def test_values_with_lower_inputs_returns_expected_value(self):
        # Arrange
        self.obv.update(1.00010, 1.00000, 10000)
        self.obv.update(1.00010, 1.00000, 10000)
        self.obv.update(1.00010, 1.00000, 10000)
        self.obv.update(1.00010, 1.00000, 10000)
        self.obv.update(1.00010, 1.00000, 10000)
        self.obv.update(1.00010, 1.00000, 10000)
        self.obv.update(1.00010, 1.00010, 10000)
        self.obv.update(1.00010, 1.00000, 10000)
        self.obv.update(1.00010, 1.00000, 10000)
        self.obv.update(1.00010, 1.00000, 10000)

        # Act
        # Assert
        self.assertEqual(-90000.0, self.obv.value)

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        for i in range(100):
            self.obv.update(1.00000, 1.00010, 10000)

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

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

        # Act
        for point in BatterySeries.create():
            self.obv.update(sys.float_info.epsilon, point, 10000)
            output.append(self.obv.value)

        # Assert
        self.assertEqual(len(battery_signal), len(output))
Beispiel #5
0
 def setUp(self):
     # Fixture Setup
     self.obv = OnBalanceVolume(100)
Beispiel #6
0
class OnBalanceVolumeTests(unittest.TestCase):
    def setUp(self):
        # Fixture Setup
        self.obv = OnBalanceVolume(100)

    def test_name_returns_expected_string(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual("OnBalanceVolume", self.obv.name)

    def test_str_repr_returns_expected_string(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual("OnBalanceVolume(100)", str(self.obv))
        self.assertEqual("OnBalanceVolume(100)", repr(self.obv))

    def test_period_returns_expected_value(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual(100, self.obv.period)

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        for _i in range(100):
            self.obv.update_raw(1.00000, 1.00010, 10000)

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

    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = OnBalanceVolume(100)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

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

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.obv.update_raw(1.00000, 1.00010, 10000)

        # Act
        # Assert
        self.assertEqual(10000, self.obv.value)

    def test_values_with_higher_inputs_returns_expected_value(self):
        # Arrange
        self.obv.update_raw(1.00000, 1.00010, 10000)
        self.obv.update_raw(1.00000, 1.00010, 10000)
        self.obv.update_raw(1.00000, 1.00010, 10000)
        self.obv.update_raw(1.00000, 1.00010, 10000)
        self.obv.update_raw(1.00000, 1.00000, 10000)
        self.obv.update_raw(1.00000, 1.00010, 10000)
        self.obv.update_raw(1.00000, 1.00010, 10000)
        self.obv.update_raw(1.00000, 1.00010, 10000)
        self.obv.update_raw(1.00000, 1.00010, 10000)
        self.obv.update_raw(1.00000, 1.00010, 10000)

        # Act
        # Assert
        self.assertEqual(90000.0, self.obv.value)

    def test_values_with_lower_inputs_returns_expected_value(self):
        # Arrange
        self.obv.update_raw(1.00010, 1.00000, 10000)
        self.obv.update_raw(1.00010, 1.00000, 10000)
        self.obv.update_raw(1.00010, 1.00000, 10000)
        self.obv.update_raw(1.00010, 1.00000, 10000)
        self.obv.update_raw(1.00010, 1.00000, 10000)
        self.obv.update_raw(1.00010, 1.00000, 10000)
        self.obv.update_raw(1.00010, 1.00010, 10000)
        self.obv.update_raw(1.00010, 1.00000, 10000)
        self.obv.update_raw(1.00010, 1.00000, 10000)
        self.obv.update_raw(1.00010, 1.00000, 10000)

        # Act
        # Assert
        self.assertEqual(-90000.0, self.obv.value)

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        for _i in range(100):
            self.obv.update_raw(1.00000, 1.00010, 10000)

        # Act
        self.obv.reset()

        # Assert
        self.assertFalse(self.obv.initialized)
Beispiel #7
0
class TestOnBalanceVolume:
    def setup(self):
        # Fixture Setup
        self.obv = OnBalanceVolume(100)

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

    def test_str_repr_returns_expected_string(self):
        # Arrange, Act, Assert
        assert str(self.obv) == "OnBalanceVolume(100)"
        assert repr(self.obv) == "OnBalanceVolume(100)"

    def test_period_returns_expected_value(self):
        # Arrange, Act, Assert
        assert self.obv.period == 100

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        for _i in range(100):
            self.obv.update_raw(1.00000, 1.00010, 10000)

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

    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = OnBalanceVolume(100)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

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

    def test_value_with_one_input_returns_expected_value(self):
        # Arrange
        self.obv.update_raw(1.00000, 1.00010, 10000)

        # Act, Assert
        assert self.obv.value == 10000

    def test_values_with_higher_inputs_returns_expected_value(self):
        # Arrange
        self.obv.update_raw(1.00000, 1.00010, 10000)
        self.obv.update_raw(1.00000, 1.00010, 10000)
        self.obv.update_raw(1.00000, 1.00010, 10000)
        self.obv.update_raw(1.00000, 1.00010, 10000)
        self.obv.update_raw(1.00000, 1.00000, 10000)
        self.obv.update_raw(1.00000, 1.00010, 10000)
        self.obv.update_raw(1.00000, 1.00010, 10000)
        self.obv.update_raw(1.00000, 1.00010, 10000)
        self.obv.update_raw(1.00000, 1.00010, 10000)
        self.obv.update_raw(1.00000, 1.00010, 10000)

        # Act, Assert
        assert self.obv.value == 90000.0

    def test_values_with_lower_inputs_returns_expected_value(self):
        # Arrange
        self.obv.update_raw(1.00010, 1.00000, 10000)
        self.obv.update_raw(1.00010, 1.00000, 10000)
        self.obv.update_raw(1.00010, 1.00000, 10000)
        self.obv.update_raw(1.00010, 1.00000, 10000)
        self.obv.update_raw(1.00010, 1.00000, 10000)
        self.obv.update_raw(1.00010, 1.00000, 10000)
        self.obv.update_raw(1.00010, 1.00010, 10000)
        self.obv.update_raw(1.00010, 1.00000, 10000)
        self.obv.update_raw(1.00010, 1.00000, 10000)
        self.obv.update_raw(1.00010, 1.00000, 10000)

        # Act, Assert
        assert self.obv.value == -90000.0

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        for _i in range(100):
            self.obv.update_raw(1.00000, 1.00010, 10000)

        # Act
        self.obv.reset()

        # Assert
        assert not self.obv.initialized