# Path: thrifty/carrier_detect.py
# def fft_range_index(start, stop, length):
# def detect(fft_mag, thresh_coeffs, window=None, peak_filter=None):
# def _estimate_noise(fft_mag, peak_mag):
# def _calculate_threshold(fft_mag, thresh_coeffs, noise_rms):
# def _get_window(array, window):
# def _filter(fft_mag, weights):
# def _window_peak(fft_mag, window, peak_filter):


import pytest
import numpy as np
from thrifty import carrier_detect
    (79.0e3, 81.0e3, -80.0e3, False),
    (79.0e3, 81.0e3, 0.0e3, False),

    (-10.0e3, 5.0e3, 0.0e3, True),
    (-10.0e3, 5.0e3, -9.9e3, True),
    (-10.0e3, 5.0e3, 4.9e3, True),
    (-10.0e3, 5.0e3, 6.0e3, False),
    (-10.0e3, 5.0e3, -11.0e3, False),
]


@pytest.mark.parametrize("freq_min,freq_max,carrier_freq,expected_detected",
                         DETECT_WINDOW_TESTDATA)
def test_detect_window(freq_min, freq_max, carrier_freq, expected_detected):
    """Test detect() with different windows, but without a filter."""
    # pylint: disable=too-many-locals

    block_len = 8192
    carrier_len = 2085
    sample_rate = 2.2e6
    threshold = (500.0**2, 0.0, 0.0)

    bin_freq = sample_rate / block_len
    bin_min, bin_max = int(freq_min / bin_freq), int(freq_max / bin_freq)

    carrier_rads = 2j * np.pi * carrier_freq
    carrier = np.exp(carrier_rads * np.arange(carrier_len) / sample_rate)
    block = np.concatenate([carrier, np.zeros(block_len - carrier_len)])
    fft_mag = np.abs(np.fft.fft(block))


# Path: thrifty/carrier_detect.py
# def fft_range_index(start, stop, length):
# def detect(fft_mag, thresh_coeffs, window=None, peak_filter=None):
# def _estimate_noise(fft_mag, peak_mag):
# def _calculate_threshold(fft_mag, thresh_coeffs, noise_rms):
# def _get_window(array, window):
# def _filter(fft_mag, weights):
# def _window_peak(fft_mag, window, peak_filter):


# Path: tests/test_carrier_detect.py
import pytest
import numpy as np
from thrifty import carrier_detect

    (79.0e3, 81.0e3, -80.0e3, False),
    (79.0e3, 81.0e3, 0.0e3, False),

    (-10.0e3, 5.0e3, 0.0e3, True),
    (-10.0e3, 5.0e3, -9.9e3, True),
    (-10.0e3, 5.0e3, 4.9e3, True),
    (-10.0e3, 5.0e3, 6.0e3, False),
    (-10.0e3, 5.0e3, -11.0e3, False),
]


@pytest.mark.parametrize("freq_min,freq_max,carrier_freq,expected_detected",
                         DETECT_WINDOW_TESTDATA)
def test_detect_window(freq_min, freq_max, carrier_freq, expected_detected):
    """Test detect() with different windows, but without a filter."""
    # pylint: disable=too-many-locals

    block_len = 8192
    carrier_len = 2085
    sample_rate = 2.2e6
    threshold = (500.0**2, 0.0, 0.0)

    bin_freq = sample_rate / block_len
    bin_min, bin_max = int(freq_min / bin_freq), int(freq_max / bin_freq)

    carrier_rads = 2j * np.pi * carrier_freq
    carrier = np.exp(carrier_rads * np.arange(carrier_len) / sample_rate)
    block = np.concatenate([carrier, np.zeros(block_len - carrier_len)])
    fft_mag = np.abs(np.fft.fft(block))


    detected, _, _, _ = carrier_detect.detect(