Пример #1
0
def test_find_twitch_indices__raises_error_if_no_valleys_given():
    with pytest.raises(
            TooFewPeaksDetectedError,
            match=
            rf"A minimum of {MIN_NUMBER_VALLEYS} valleys is required to extract twitch metrics, however only 0 valley\(s\) were detected",
    ):
        find_twitch_indices((np.array([1, 3, 5]), np.array([])))
Пример #2
0
def test_find_twitch_indices__raises_error_if_less_than_3_peaks_given():
    with pytest.raises(
            TooFewPeaksDetectedError,
            match=
            rf"A minimum of {MIN_NUMBER_PEAKS} peaks is required to extract twitch metrics, however only 2 peak\(s\) were detected",
    ):
        find_twitch_indices((np.array([1, 2]), None))
Пример #3
0
def test_find_twitch_indices__returns_correct_values_with_data_that_ends_in_valley(
):
    peak_indices = np.array([1, 3, 5], dtype=np.int32)
    valley_indices = np.array([2, 4, 6], dtype=np.int32)
    actual = find_twitch_indices((peak_indices, valley_indices))

    assert actual[3][PRIOR_PEAK_INDEX_UUID] == 1
    assert actual[3][PRIOR_VALLEY_INDEX_UUID] == 2
    assert actual[3][SUBSEQUENT_PEAK_INDEX_UUID] == 5
    assert actual[3][SUBSEQUENT_VALLEY_INDEX_UUID] == 4
Пример #4
0
def test_find_twitch_indices__excludes_only_last_peak_when_no_outer_peak_at_beginning_and_no_outer_valley_at_end(
):
    test_peak_indices = np.arange(3, 12, 2)
    test_valley_indices = np.arange(1, 11, 2)
    actual_twitch_indices = find_twitch_indices(
        (test_peak_indices, test_valley_indices))

    actual_twitch_peak_indices = list(actual_twitch_indices.keys())
    assert actual_twitch_peak_indices == list(test_peak_indices[:-1])

    assert actual_twitch_indices[test_peak_indices[0]] == {
        PRIOR_PEAK_INDEX_UUID: None,
        PRIOR_VALLEY_INDEX_UUID: test_valley_indices[0],
        SUBSEQUENT_PEAK_INDEX_UUID: test_peak_indices[1],
        SUBSEQUENT_VALLEY_INDEX_UUID: test_valley_indices[1],
    }
Пример #5
0
def test_find_twitch_indices__excludes_first_and_last_peak_when_starts_and_ends_with_peaks(
):
    test_peak_indices = np.arange(0, 12, 2)
    test_valley_indices = np.arange(1, 11, 2)
    actual_twitch_indices = find_twitch_indices(
        (test_peak_indices, test_valley_indices))

    actual_twitch_peak_indices = list(actual_twitch_indices.keys())
    assert actual_twitch_peak_indices == list(test_peak_indices[1:-1])

    assert actual_twitch_indices[test_peak_indices[1]] == {
        PRIOR_PEAK_INDEX_UUID: test_peak_indices[0],
        PRIOR_VALLEY_INDEX_UUID: test_valley_indices[0],
        SUBSEQUENT_PEAK_INDEX_UUID: test_peak_indices[2],
        SUBSEQUENT_VALLEY_INDEX_UUID: test_valley_indices[1],
    }
Пример #6
0
def test_find_twitch_indices__raises_error_if_two_valleys_in_a_row__and_does_not_start_with_valley(
        test_valleys, expected_match, test_description):
    test_peaks = [-2, 2, 6, 10]
    with pytest.raises(TwoValleysInARowError, match=expected_match):
        find_twitch_indices((test_peaks, test_valleys))