예제 #1
0
    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = RateOfChange(3)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        self.assertTrue(indicator.has_inputs)
        self.assertEqual(0, indicator.value)
예제 #2
0
    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = RateOfChange(3)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        assert indicator.has_inputs
        assert indicator.value == 0
예제 #3
0
    def test_log_returns_value_with_noisy_inputs(self):
        # Arrange
        roc = RateOfChange(3, use_log=True)

        roc.update_raw(1.00000)
        roc.update_raw(1.00010)
        roc.update_raw(1.00008)
        roc.update_raw(1.00007)
        roc.update_raw(1.00012)
        roc.update_raw(1.00005)
        roc.update_raw(1.00015)

        # Act, Assert
        assert roc.value == 2.999595054919663e-05
예제 #4
0
    def test_log_returns_value_with_noisy_inputs(self):
        # Arrange
        roc = RateOfChange(3, use_log=True)

        roc.update(1.00000)
        roc.update(1.00010)
        roc.update(1.00008)
        roc.update(1.00007)
        roc.update(1.00012)
        roc.update(1.00005)
        roc.update(1.00015)

        # Act
        # Assert
        self.assertEqual(2.999595054919663e-05, roc.value)
예제 #5
0
 def setUp(self):
     # Arrange
     self.roc = RateOfChange(3)
예제 #6
0
class RateOfChangeTests(unittest.TestCase):

    # Fixture Setup
    def setUp(self):
        # Arrange
        self.roc = RateOfChange(3)

    def test_name(self):
        # Act
        # Assert
        self.assertEqual("RateOfChange", self.roc.name)

    def test_str(self):
        # Act
        # Assert
        self.assertEqual("RateOfChange(3)", str(self.roc))

    def test_repr(self):
        # Act
        # Assert
        self.assertTrue(
            repr(self.roc).startswith("<RateOfChange(3) object at"))
        self.assertTrue(repr(self.roc).endswith(">"))

    def test_period(self):
        # Act
        # Assert
        self.assertEqual(3, self.roc.period)

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        # Act
        for _i in range(3):
            self.roc.update_raw(1.00000)

        # Assert
        self.assertEqual(True, self.roc.initialized)

    def test_value_with_one_input(self):
        # Arrange
        self.roc.update_raw(1.00000)

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

    def test_value_with_efficient_higher_inputs(self):
        # Arrange
        price = 1.00000

        # Act
        for _i in range(10):
            price += 0.10000
            self.roc.update_raw(price)

        # Assert
        self.assertEqual(0.11111111111111116, self.roc.value)

    def test_value_with_oscillating_inputs_returns_zero(self):
        # Arrange
        self.roc.update_raw(1.00000)
        self.roc.update_raw(1.00010)
        self.roc.update_raw(1.00000)
        self.roc.update_raw(0.99990)
        self.roc.update_raw(1.00000)

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

    def test_value_with_half_oscillating_inputs_returns_zero(self):
        # Arrange
        self.roc.update_raw(1.00000)
        self.roc.update_raw(1.00020)
        self.roc.update_raw(1.00010)
        self.roc.update_raw(1.00030)
        self.roc.update_raw(1.00020)

        # Act
        # Assert
        self.assertEqual(9.9990000999889e-05, self.roc.value)

    def test_value_with_noisy_inputs(self):
        # Arrange
        self.roc.update_raw(1.00000)
        self.roc.update_raw(1.00010)
        self.roc.update_raw(1.00008)
        self.roc.update_raw(1.00007)
        self.roc.update_raw(1.00012)
        self.roc.update_raw(1.00005)
        self.roc.update_raw(1.00015)

        # Act
        # Assert
        self.assertEqual(2.9996400432144683e-05, self.roc.value)

    def test_log_returns_value_with_noisy_inputs(self):
        # Arrange
        roc = RateOfChange(3, use_log=True)

        roc.update_raw(1.00000)
        roc.update_raw(1.00010)
        roc.update_raw(1.00008)
        roc.update_raw(1.00007)
        roc.update_raw(1.00012)
        roc.update_raw(1.00005)
        roc.update_raw(1.00015)

        # Act
        # Assert
        self.assertEqual(2.999595054919663e-05, roc.value)

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        for _i in range(10):
            self.roc.update_raw(1.00000)

        # Act
        self.roc.reset()

        # Assert
        self.assertEqual(0, self.roc.value)  # No assertion errors.

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

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

        # Assert
        self.assertEqual(len(battery_signal), len(output))
        print(self.roc.value)
예제 #7
0
 def setup(self):
     # Fixture Setup
     self.roc = RateOfChange(3)
예제 #8
0
class TestRateOfChange:
    def setup(self):
        # Fixture Setup
        self.roc = RateOfChange(3)

    def test_name_returns_expected_string(self):
        # Act, Assert
        assert self.roc.name == "RateOfChange"

    def test_str_repr_returns_expected_string(self):
        # Act, Assert
        assert str(self.roc) == "RateOfChange(3)"
        assert repr(self.roc) == "RateOfChange(3)"

    def test_period(self):
        # Act, Assert
        assert self.roc.period == 3

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange, Act
        for _i in range(3):
            self.roc.update_raw(1.00000)

        # Assert
        assert self.roc.initialized is True

    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = RateOfChange(3)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

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

    def test_value_with_one_input(self):
        # Arrange
        self.roc.update_raw(1.00000)

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

    def test_value_with_efficient_higher_inputs(self):
        # Arrange
        price = 1.00000

        # Act
        for _i in range(10):
            price += 0.10000
            self.roc.update_raw(price)

        # Assert
        assert self.roc.value == 0.11111111111111116

    def test_value_with_oscillating_inputs_returns_zero(self):
        # Arrange
        self.roc.update_raw(1.00000)
        self.roc.update_raw(1.00010)
        self.roc.update_raw(1.00000)
        self.roc.update_raw(0.99990)
        self.roc.update_raw(1.00000)

        # Act, Assert
        assert self.roc.value == 0.0

    def test_value_with_half_oscillating_inputs_returns_zero(self):
        # Arrange
        self.roc.update_raw(1.00000)
        self.roc.update_raw(1.00020)
        self.roc.update_raw(1.00010)
        self.roc.update_raw(1.00030)
        self.roc.update_raw(1.00020)

        # Act, Assert
        assert self.roc.value == 9.9990000999889e-05

    def test_value_with_noisy_inputs(self):
        # Arrange
        self.roc.update_raw(1.00000)
        self.roc.update_raw(1.00010)
        self.roc.update_raw(1.00008)
        self.roc.update_raw(1.00007)
        self.roc.update_raw(1.00012)
        self.roc.update_raw(1.00005)
        self.roc.update_raw(1.00015)

        # Act, Assert
        assert self.roc.value == 2.9996400432144683e-05

    def test_log_returns_value_with_noisy_inputs(self):
        # Arrange
        roc = RateOfChange(3, use_log=True)

        roc.update_raw(1.00000)
        roc.update_raw(1.00010)
        roc.update_raw(1.00008)
        roc.update_raw(1.00007)
        roc.update_raw(1.00012)
        roc.update_raw(1.00005)
        roc.update_raw(1.00015)

        # Act, Assert
        assert roc.value == 2.999595054919663e-05

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        for _i in range(10):
            self.roc.update_raw(1.00000)

        # Act
        self.roc.reset()

        # Assert
        assert not self.roc.initialized
        assert self.roc.value == 0
예제 #9
0
class RateOfChangeTests(unittest.TestCase):

    def setUp(self):
        # Fixture Setup
        self.roc = RateOfChange(3)

    def test_name_returns_expected_string(self):
        # Act
        # Assert
        self.assertEqual("RateOfChange", self.roc.name)

    def test_str_repr_returns_expected_string(self):
        # Act
        # Assert
        self.assertEqual("RateOfChange(3)", str(self.roc))
        self.assertEqual("RateOfChange(3)", repr(self.roc))

    def test_period(self):
        # Act
        # Assert
        self.assertEqual(3, self.roc.period)

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        # Act
        for _i in range(3):
            self.roc.update_raw(1.00000)

        # Assert
        self.assertEqual(True, self.roc.initialized)

    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = RateOfChange(3)

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

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

    def test_value_with_one_input(self):
        # Arrange
        self.roc.update_raw(1.00000)

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

    def test_value_with_efficient_higher_inputs(self):
        # Arrange
        price = 1.00000

        # Act
        for _i in range(10):
            price += 0.10000
            self.roc.update_raw(price)

        # Assert
        self.assertEqual(0.11111111111111116, self.roc.value)

    def test_value_with_oscillating_inputs_returns_zero(self):
        # Arrange
        self.roc.update_raw(1.00000)
        self.roc.update_raw(1.00010)
        self.roc.update_raw(1.00000)
        self.roc.update_raw(0.99990)
        self.roc.update_raw(1.00000)

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

    def test_value_with_half_oscillating_inputs_returns_zero(self):
        # Arrange
        self.roc.update_raw(1.00000)
        self.roc.update_raw(1.00020)
        self.roc.update_raw(1.00010)
        self.roc.update_raw(1.00030)
        self.roc.update_raw(1.00020)

        # Act
        # Assert
        self.assertEqual(9.9990000999889e-05, self.roc.value)

    def test_value_with_noisy_inputs(self):
        # Arrange
        self.roc.update_raw(1.00000)
        self.roc.update_raw(1.00010)
        self.roc.update_raw(1.00008)
        self.roc.update_raw(1.00007)
        self.roc.update_raw(1.00012)
        self.roc.update_raw(1.00005)
        self.roc.update_raw(1.00015)

        # Act
        # Assert
        self.assertEqual(2.9996400432144683e-05, self.roc.value)

    def test_log_returns_value_with_noisy_inputs(self):
        # Arrange
        roc = RateOfChange(3, use_log=True)

        roc.update_raw(1.00000)
        roc.update_raw(1.00010)
        roc.update_raw(1.00008)
        roc.update_raw(1.00007)
        roc.update_raw(1.00012)
        roc.update_raw(1.00005)
        roc.update_raw(1.00015)

        # Act
        # Assert
        self.assertEqual(2.999595054919663e-05, roc.value)

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        for _i in range(10):
            self.roc.update_raw(1.00000)

        # Act
        self.roc.reset()

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