Exemple #1
0
    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = HilbertSignalNoiseRatio()

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        self.assertEqual(0, indicator.value)
Exemple #2
0
 def setUp(self):
     # Arrange
     self.snr = HilbertSignalNoiseRatio()
Exemple #3
0
class HilbertSignalNoiseRatioTests(unittest.TestCase):

    # Fixture Setup
    def setUp(self):
        # Arrange
        self.snr = HilbertSignalNoiseRatio()

    def test_name_returns_expected_name(self):
        # Act
        # Assert
        self.assertEqual('HilbertSignalNoiseRatio', self.snr.name)

    def test_str_returns_expected_string(self):
        # Act
        # Assert
        self.assertEqual('HilbertSignalNoiseRatio(7)', str(self.snr))

    def test_repr_returns_expected_string(self):
        # Act
        # Assert
        self.assertTrue(
            repr(self.snr).startswith('<HilbertSignalNoiseRatio(7) object at'))
        self.assertTrue(repr(self.snr).endswith('>'))

    def test_period_returns_expected_value(self):
        # Act
        # Assert
        self.assertEqual(7, self.snr.period)

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Act
        for i in range(10):
            self.snr.update(1.00010, 1.00000)

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

    def test_value_with_no_inputs_returns_none(self):
        # Act
        # Assert
        self.assertEqual(0.0, self.snr.value)

    def test_value_with_epsilon_inputs_returns_expected_value(self):
        # Arrange
        for i in range(100):
            self.snr.update(sys.float_info.epsilon, sys.float_info.epsilon)

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

    def test_value_with_ones_inputs_returns_expected_value(self):
        # Arrange
        for i in range(100):
            self.snr.update(1.00000, 1.00000)

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

    def test_value_with_seven_inputs_returns_expected_value(self):
        # Arrange
        high = 1.00010
        low = 1.00000

        # Act
        for i in range(9):
            high += 0.00010
            low += 0.00010
            self.snr.update(high, low)

        # Assert
        self.assertEqual(0, self.snr.value)

    def test_value_with_close_on_high_returns_expected_value(self):
        # Arrange
        high = 1.00010
        low = 1.00000

        # Act
        for i in range(1000):
            high += 0.00010
            low += 0.00010
            self.snr.update(high, low)

        # Assert
        self.assertEqual(51.90000000000095, self.snr.value)

    def test_value_with_close_on_low_returns_expected_value(self):
        # Arrange
        high = 1.00010
        low = 1.00000

        # Act
        for i in range(1000):
            high -= 0.00010
            low -= 0.00010
            self.snr.update(high, low)

        # Assert
        self.assertEqual(51.90000000000095, self.snr.value)

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        for i in range(1000):
            self.snr.update(1.00000, 1.00000)

        # Act
        self.snr.reset()

        # Assert
        self.assertEqual(0.0, self.snr.value)  # No assertion errors.

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

        # Act
        for point in BatterySeries.create():
            self.snr.update(point + 0.00010, point)
            output.append(self.snr.value)

        # Assert
        self.assertEqual(len(battery_signal), len(output))
Exemple #4
0
 def setUp(self):
     # Fixture Setup
     self.snr = HilbertSignalNoiseRatio()
Exemple #5
0
class HilbertSignalNoiseRatioTests(unittest.TestCase):
    def setUp(self):
        # Fixture Setup
        self.snr = HilbertSignalNoiseRatio()

    def test_name_returns_expected_name(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual("HilbertSignalNoiseRatio", self.snr.name)

    def test_str_returns_expected_string(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual("HilbertSignalNoiseRatio(7)", str(self.snr))
        self.assertEqual("HilbertSignalNoiseRatio(7)", repr(self.snr))

    def test_period_returns_expected_value(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual(7, self.snr.period)

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange
        # Act
        for _i in range(10):
            self.snr.update_raw(1.00010, 1.00000)

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

    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = HilbertSignalNoiseRatio()

        bar = TestStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

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

    def test_value_with_no_inputs_returns_none(self):
        # Arrange
        # Act
        # Assert
        self.assertEqual(0.0, self.snr.value)

    def test_value_with_epsilon_inputs_returns_expected_value(self):
        # Arrange
        for _i in range(100):
            self.snr.update_raw(sys.float_info.epsilon, sys.float_info.epsilon)

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

    def test_value_with_ones_inputs_returns_expected_value(self):
        # Arrange
        for _i in range(100):
            self.snr.update_raw(1.00000, 1.00000)

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

    def test_value_with_seven_inputs_returns_expected_value(self):
        # Arrange
        high = 1.00010
        low = 1.00000

        # Act
        for _i in range(9):
            high += 0.00010
            low += 0.00010
            self.snr.update_raw(high, low)

        # Assert
        self.assertEqual(0, self.snr.value)

    def test_value_with_close_on_high_returns_expected_value(self):
        # Arrange
        high = 1.00010
        low = 1.00000

        # Act
        for _i in range(1000):
            high += 0.00010
            low += 0.00010
            self.snr.update_raw(high, low)

        # Assert
        self.assertEqual(51.90000000000095, self.snr.value)

    def test_value_with_close_on_low_returns_expected_value(self):
        # Arrange
        high = 1.00010
        low = 1.00000

        # Act
        for _i in range(1000):
            high -= 0.00010
            low -= 0.00010
            self.snr.update_raw(high, low)

        # Assert
        self.assertEqual(51.90000000000095, self.snr.value)

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        for _i in range(1000):
            self.snr.update_raw(1.00000, 1.00000)

        # Act
        self.snr.reset()

        # Assert
        self.assertEqual(0.0, self.snr.value)  # No assertion errors.
class TestHilbertSignalNoiseRatio:
    def setup(self):
        # Fixture Setup
        self.snr = HilbertSignalNoiseRatio()

    def test_name_returns_expected_name(self):
        # Arrange, Act, Assert
        assert self.snr.name == "HilbertSignalNoiseRatio"

    def test_str_returns_expected_string(self):
        # Arrange, Act, Assert
        assert str(self.snr) == "HilbertSignalNoiseRatio(7)"
        assert repr(self.snr) == "HilbertSignalNoiseRatio(7)"

    def test_period_returns_expected_value(self):
        # Arrange, Act, Assert
        assert self.snr.period == 7

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

    def test_initialized_with_required_inputs_returns_true(self):
        # Arrange, Act
        for _i in range(10):
            self.snr.update_raw(1.00010, 1.00000)

        # Assert
        assert self.snr.initialized is True

    def test_handle_bar_updates_indicator(self):
        # Arrange
        indicator = HilbertSignalNoiseRatio()

        bar = TestDataStubs.bar_5decimal()

        # Act
        indicator.handle_bar(bar)

        # Assert
        assert indicator.value == 0

    def test_value_with_no_inputs_returns_none(self):
        # Arrange, Act, Assert
        assert self.snr.value == 0.0

    def test_value_with_epsilon_inputs_returns_expected_value(self):
        # Arrange
        for _i in range(100):
            self.snr.update_raw(sys.float_info.epsilon, sys.float_info.epsilon)

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

    def test_value_with_ones_inputs_returns_expected_value(self):
        # Arrange
        for _i in range(100):
            self.snr.update_raw(1.00000, 1.00000)

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

    def test_value_with_seven_inputs_returns_expected_value(self):
        # Arrange
        high = 1.00010
        low = 1.00000

        # Act
        for _i in range(9):
            high += 0.00010
            low += 0.00010
            self.snr.update_raw(high, low)

        # Assert
        assert self.snr.value == 0

    def test_value_with_close_on_high_returns_expected_value(self):
        # Arrange
        high = 1.00010
        low = 1.00000

        # Act
        for _i in range(1000):
            high += 0.00010
            low += 0.00010
            self.snr.update_raw(high, low)

        # Assert
        assert self.snr.value == 51.90000000000095

    def test_value_with_close_on_low_returns_expected_value(self):
        # Arrange
        high = 1.00010
        low = 1.00000

        # Act
        for _i in range(1000):
            high -= 0.00010
            low -= 0.00010
            self.snr.update_raw(high, low)

        # Assert
        assert self.snr.value == 51.90000000000095

    def test_reset_successfully_returns_indicator_to_fresh_state(self):
        # Arrange
        for _i in range(1000):
            self.snr.update_raw(1.00000, 1.00000)

        # Act
        self.snr.reset()

        # Assert
        assert self.snr.value == 0.0  # No assertion errors.