def test_collect_peak_pairs(shift, expected_pairs, expected_matches):
    """Test finding expected peak matches for tolerance=0.2 and given shift."""
    spec1 = numpy.array([[100, 200, 300, 500],
                         [0.1, 0.1, 1.0, 1.0]], dtype="float").T

    spec2 = numpy.array([[105, 205.1, 300, 500.1],
                         [0.1, 0.1, 1.0, 1.0]], dtype="float").T

    matching_pairs = numpy.array(collect_peak_pairs.py_func(spec1, spec2, tolerance=0.2, shift=shift))
    assert matching_pairs.shape == expected_matches, "Expected different number of matching peaks"
    assert numpy.allclose(matching_pairs, numpy.array(expected_pairs), atol=1e-8), "Expected different values."
def test_collect_peak_pairs_no_matches(numba_compiled):
    """Test function for no matching peaks."""
    shift = -20.0
    spec1 = numpy.array([[100, 200, 300, 500],
                         [0.1, 0.1, 1.0, 1.0]], dtype="float").T

    spec2 = numpy.array([[105, 205.1, 300, 500.1],
                         [0.1, 0.1, 1.0, 1.0]], dtype="float").T
    if numba_compiled:
        matching_pairs = collect_peak_pairs(spec1, spec2, tolerance=0.2, shift=shift)
    else:
        matching_pairs = collect_peak_pairs.py_func(spec1, spec2, tolerance=0.2, shift=shift)
    assert matching_pairs is None, "Expected pairs to be None."
def test_collect_peak_pairs(shift, expected_pairs):
    """Test finding expected peak matches for tolerance=0.2 and given shift."""
    spec1 = numpy.array([[100, 200, 300, 500], [0.1, 0.1, 1.0, 1.0]],
                        dtype="float").T

    spec2 = numpy.array([[105, 205.1, 300, 500.1], [0.1, 0.1, 1.0, 1.0]],
                        dtype="float").T

    matching_pairs = collect_peak_pairs.py_func(spec1,
                                                spec2,
                                                tolerance=0.2,
                                                shift=shift)
    assert len(
        matching_pairs) == 2, "Expected different number of matching peaks"
    assert matching_pairs == [pytest.approx(x, 1e-9) for x in expected_pairs
                              ], "Expected different pairs."