def test_handle_bar_updates_indicator(self): # Arrange indicator = HilbertPeriod() bar = TestStubs.bar_5decimal() # Act indicator.handle_bar(bar) # Assert self.assertTrue(indicator.has_inputs) self.assertEqual(0, indicator.value)
def test_handle_bar_updates_indicator(self): # Arrange indicator = HilbertPeriod() bar = TestDataStubs.bar_5decimal() # Act indicator.handle_bar(bar) # Assert assert indicator.has_inputs assert indicator.value == 0
def setup(self): # Fixture Setup self.h_period = HilbertPeriod()
class TestHilbertPeriod: def setup(self): # Fixture Setup self.h_period = HilbertPeriod() def test_name_returns_expected_name(self): # Arrange, Act, Assert assert self.h_period.name == "HilbertPeriod" def test_str_returns_expected_string(self): # Arrange, Act, Assert assert str(self.h_period) == "HilbertPeriod(7)" assert repr(self.h_period) == "HilbertPeriod(7)" def test_period_returns_expected_value(self): # Arrange, Act, Assert assert self.h_period.period == 7 def test_initialized_without_inputs_returns_false(self): # Arrange, Act, Assert assert self.h_period.initialized is False def test_initialized_with_required_inputs_returns_true(self): # Arrange, Act for _i in range(10): self.h_period.update_raw(1.00010, 1.00000) # Assert assert self.h_period.initialized is True def test_handle_bar_updates_indicator(self): # Arrange indicator = HilbertPeriod() bar = TestDataStubs.bar_5decimal() # Act indicator.handle_bar(bar) # Assert assert indicator.has_inputs assert indicator.value == 0 def test_value_with_no_inputs_returns_none(self): # Arrange, Act, Assert assert self.h_period.value == 0 def test_value_with_epsilon_inputs_returns_expected_value(self): # Arrange for _i in range(100): self.h_period.update_raw(sys.float_info.epsilon, sys.float_info.epsilon) # Act, Assert assert self.h_period.value == 7 def test_value_with_ones_inputs_returns_expected_value(self): # Arrange for _i in range(100): self.h_period.update_raw(1.00000, 1.00000) # Act, Assert assert self.h_period.value == 7 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.h_period.update_raw(high, low) # Assert assert self.h_period.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.h_period.update_raw(high, low) # Assert assert self.h_period.value == 7 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.h_period.update_raw(high, low) # Assert assert self.h_period.value == 7 def test_reset_successfully_returns_indicator_to_fresh_state(self): # Arrange for _i in range(1000): self.h_period.update_raw(1.00000, 1.00000) # Act self.h_period.reset() # Assert assert self.h_period.value == 0 # No exceptions raised
class HilbertPeriodTests(unittest.TestCase): def setUp(self): # Fixture Setup self.h_period = HilbertPeriod() def test_name_returns_expected_name(self): # Arrange # Act # Assert self.assertEqual("HilbertPeriod", self.h_period.name) def test_str_returns_expected_string(self): # Arrange # Act # Assert self.assertEqual("HilbertPeriod(7)", str(self.h_period)) self.assertEqual("HilbertPeriod(7)", repr(self.h_period)) def test_period_returns_expected_value(self): # Arrange # Act # Assert self.assertEqual(7, self.h_period.period) def test_initialized_without_inputs_returns_false(self): # Arrange # Act # Assert self.assertEqual(False, self.h_period.initialized) def test_initialized_with_required_inputs_returns_true(self): # Arrange # Act for _i in range(10): self.h_period.update_raw(1.00010, 1.00000) # Assert self.assertEqual(True, self.h_period.initialized) def test_handle_bar_updates_indicator(self): # Arrange indicator = HilbertPeriod() bar = TestStubs.bar_5decimal() # Act indicator.handle_bar(bar) # Assert self.assertTrue(indicator.has_inputs) self.assertEqual(0, indicator.value) def test_value_with_no_inputs_returns_none(self): # Arrange # Act # Assert self.assertEqual(0, self.h_period.value) def test_value_with_epsilon_inputs_returns_expected_value(self): # Arrange for _i in range(100): self.h_period.update_raw(sys.float_info.epsilon, sys.float_info.epsilon) # Act # Assert self.assertEqual(7, self.h_period.value) def test_value_with_ones_inputs_returns_expected_value(self): # Arrange for _i in range(100): self.h_period.update_raw(1.00000, 1.00000) # Act # Assert self.assertEqual(7, self.h_period.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.h_period.update_raw(high, low) # Assert self.assertEqual(0, self.h_period.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.h_period.update_raw(high, low) # Assert self.assertEqual(7, self.h_period.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.h_period.update_raw(high, low) # Assert self.assertEqual(7, self.h_period.value) def test_reset_successfully_returns_indicator_to_fresh_state(self): # Arrange for _i in range(1000): self.h_period.update_raw(1.00000, 1.00000) # Act self.h_period.reset() # Assert self.assertEqual(0, self.h_period.value) # No exceptions raised
def setUp(self): # Arrange self.h_period = HilbertPeriod()
class HilbertPeriodTests(unittest.TestCase): # Fixture Setup def setUp(self): # Arrange self.h_period = HilbertPeriod() def test_name_returns_expected_name(self): # Act # Assert self.assertEqual('HilbertPeriod', self.h_period.name) def test_str_returns_expected_string(self): # Act # Assert self.assertEqual('HilbertPeriod(7)', str(self.h_period)) def test_repr_returns_expected_string(self): # Act # Assert self.assertTrue( repr(self.h_period).startswith('<HilbertPeriod(7) object at')) self.assertTrue(repr(self.h_period).endswith('>')) def test_period_returns_expected_value(self): # Act # Assert self.assertEqual(7, self.h_period.period) def test_initialized_without_inputs_returns_false(self): # Act # Assert self.assertEqual(False, self.h_period.initialized) def test_initialized_with_required_inputs_returns_true(self): # Act for i in range(10): self.h_period.update(1.00010, 1.00000) # Assert self.assertEqual(True, self.h_period.initialized) def test_value_with_no_inputs_returns_none(self): # Act # Assert self.assertEqual(0.0, self.h_period.value) def test_value_with_epsilon_inputs_returns_expected_value(self): # Arrange for i in range(100): self.h_period.update(sys.float_info.epsilon, sys.float_info.epsilon) # Act # Assert self.assertEqual(7, self.h_period.value) def test_value_with_ones_inputs_returns_expected_value(self): # Arrange for i in range(100): self.h_period.update(1.00000, 1.00000) # Act # Assert self.assertEqual(7, self.h_period.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.h_period.update(high, low) # Assert self.assertEqual(0, self.h_period.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.h_period.update(high, low) # Assert self.assertEqual(7, self.h_period.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.h_period.update(high, low) # Assert self.assertEqual(7, self.h_period.value) def test_reset_successfully_returns_indicator_to_fresh_state(self): # Arrange for i in range(1000): self.h_period.update(1.00000, 1.00000) # Act self.h_period.reset() # Assert self.assertEqual(0.0, self.h_period.value) # No assertion errors. def test_with_battery_signal(self): # Arrange battery_signal = BatterySeries.create() output = [] # Act for point in BatterySeries.create(): self.h_period.update(point, sys.float_info.epsilon) output.append(self.h_period.value) # Assert self.assertEqual(len(battery_signal), len(output)) self.assertTrue(self.h_period.value > 0)