def test_detect_apd90_returns_false_different_y_voltage(self):
        pacing_info = trace.IrregularPacingInfo()
        pacing_info.apd_90_end_voltage = 5

        detected_apd90 = pacing_info.detect_apd_90(y_voltage=10)

        self.assertFalse(detected_apd90)
    def test_detect_apd90_returns_true(self):
        pacing_info = trace.IrregularPacingInfo()
        pacing_info.apd_90_end_voltage = 5

        detected_apd90 = pacing_info.detect_apd_90(y_voltage=5.0001)

        self.assertTrue(detected_apd90)
    def test_should_stimulate_returns_true(self):
        pacing_info = trace.IrregularPacingInfo()
        pacing_info.stimulations = [1.1, 1.3005, 1.7]

        test_times = [1.10001, 1.3006, 1.7003]
        for i in test_times:
            with self.subTest():
                self.assertTrue(pacing_info.should_stimulate(t=i))
    def test_should_stimulate_returns_false(self):
        pacing_info = trace.IrregularPacingInfo()
        pacing_info.stimulations = [1.1, 1.3005, 1.7]

        test_times = [1.2, 1.0999, 1.8]
        for i in test_times:
            with self.subTest():
                self.assertFalse(pacing_info.should_stimulate(t=i))
    def test_detect_peak_returns_true(self):
        pacing_info = trace.IrregularPacingInfo()
        pacing_info.peaks.append(0.1)

        detected_peak = pacing_info.detect_peak(t=[.1, .2, 3],
                                                y_voltage=0.03,
                                                d_y_voltage=[1.5, -1.5])

        self.assertTrue(detected_peak)
    def test_detect_peak_returns_false_under_voltage_threshold(self):
        pacing_info = trace.IrregularPacingInfo()
        pacing_info.peaks.append(0.1)

        detected_peak = pacing_info.detect_peak(t=[.1, .2, 3],
                                                y_voltage=-0.01,
                                                d_y_voltage=[1.5, -1.5])

        self.assertFalse(detected_peak)
    def test_detect_peak_returns_false_no_switch_in_d_y(self):
        pacing_info = trace.IrregularPacingInfo()
        pacing_info.peaks.append(0.1)

        detected_peak = pacing_info.detect_peak(t=[.1, .2, 3],
                                                y_voltage=0.03,
                                                d_y_voltage=[-1.5, -1.5])

        self.assertFalse(detected_peak)
    def test_detect_peak_returns_false_too_close_to_past_peak(self):
        pacing_info = trace.IrregularPacingInfo()
        pacing_info.peaks.append(0.3)

        detected_peak = pacing_info.detect_peak(t=[.1, .2, .3],
                                                y_voltage=0.03,
                                                d_y_voltage=[1.5, -1.5])

        self.assertFalse(detected_peak)
 def generate_irregular_pacing_response(self, protocol):
     """
     Args:
         protocol: An irregular pacing protocol 
     Returns:
         A irregular pacing trace
     """
     pacing_info = trace.IrregularPacingInfo()
     try:
         solution = integrate.solve_ivp(
             self.generate_irregular_pacing_function(protocol, pacing_info),
             [0, protocol.duration],
             self.y_initial,
             method='BDF',
             max_step=1e-3 * self.time_conversion)
         self._set_data_without_error(solution)
     except ValueError:
         return None
     return trace.Trace(self.t, self.y_voltage, pacing_info=pacing_info)
    def test_detect_apd90_returns_false_apd_end_not_set(self):
        pacing_info = trace.IrregularPacingInfo()

        detected_apd90 = pacing_info.detect_apd_90(y_voltage=10)

        self.assertFalse(detected_apd90)
    def test_add_apd90(self):
        pacing_info = trace.IrregularPacingInfo()
        pacing_info.apd_90_end_voltage = 10
        pacing_info.add_apd_90(apd_90=1.5)

        self.assertEqual(pacing_info.apd_90_end_voltage, -1)