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