def test_overlap_but_on_different_day():
    df = pd.DataFrame({
        'date': ['2020-08-10', '2020-08-10', '2020-08-11', '2020-08-11'],
        'song': ['S1', 'S2', 'S1', 'S3'],
        'artist': ['A1', 'A1', 'A1', 'A2'],
        'radio': ['rfm', 'rfm', 'comercial', 'comercial'],
        'time': ['00:01', '00:04', '00:02', '00:05']
    })
    df = _add_datetime_to_df(df)

    result = rra.overlaps(df)
    assert len(result) == 0
def test_overlap_consecutive_days():
    df = pd.DataFrame({
        'date': ['2020-08-10', '2020-08-11', '2020-08-11', '2020-08-11'],
        'song': ['S1', 'S2', 'S1', 'S3'],
        'artist': ['A1', 'A1', 'A1', 'A2'],
        'radio': ['rfm', 'rfm', 'comercial', 'comercial'],
        'time': ['23:58', '00:03', '00:02', '00:07']
    })
    df = _add_datetime_to_df(df)

    result = rra.overlaps(df)
    assert len(result) == 1
    result = result.iloc[0]
    assert result['song'] == 'S1' and result['artist'] == 'A1'
    assert len(result['radios'].split(' | ')) == 2
    assert 'rfm' in result['radios'] and 'comercial' in result['radios']
def test_three_overlaps():
    df = pd.DataFrame({
        'date': [
            '2020-08-10', '2020-08-10', '2020-08-10', '2020-08-10',
            '2020-08-10', '2020-08-10'
        ],
        'song': ['S1', 'S2', 'S1', 'S3', 'S1', 'S5'],
        'artist': ['A1', 'A1', 'A1', 'A2', 'A1', 'A5'],
        'radio': ['rfm', 'rfm', 'comercial', 'comercial', 'megafm', 'megafm'],
        'time': ['15:38', '15:42', '15:39', '15:43', '15:41', '15:45']
    })
    df = _add_datetime_to_df(df)

    result = rra.overlaps(df)
    assert len(result) == 1
    result = result.iloc[0]
    assert result['song'] == 'S1' and result['artist'] == 'A1'
    assert len(result['radios'].split(' | ')) == 3
    assert sorted(
        result['radios'].split(' | ')) == ['comercial', 'megafm', 'rfm']
def test_multiple_overlaps():
    """
    Tests multiple overlaps, with unordered times, and a complex three-overlap.
    The three-overlap takes the form:
    [   ]
      [   ]
         [   ]
    That is, the first and last plays do not overlap directly, only through the middle play.
    """
    df = pd.DataFrame({
        'date': [
            '2020-08-10', '2020-08-10', '2020-08-10', '2020-08-10',
            '2020-08-10', '2020-08-10', '2020-08-10', '2020-08-10',
            '2020-08-10'
        ],
        'song': ['S1', 'S2', 'S3', 'S4', 'S2', 'S5', 'S3', 'S2', 'S5'],
        'artist': ['A1', 'A2', 'A3', 'A4', 'A2', 'A5', 'A3', 'A2', 'A5'],
        'radio': [
            'rfm', 'rfm', 'rfm', 'comercial', 'comercial', 'comercial',
            'megafm', 'megafm', 'megafm'
        ],
        'time': [
            '15:38', '15:42', '15:46', '15:37', '15:41', '15:45', '15:41',
            '15:37', '15:35'
        ]
    })
    df = _add_datetime_to_df(df)

    result = rra.overlaps(df)
    assert len(result) == 2

    first = result.iloc[0]
    assert first['song'] == 'S2' and first['artist'] == 'A2'
    assert len(first['radios'].split(' | ')) == 3
    assert sorted(
        first['radios'].split(' | ')) == ['comercial', 'megafm', 'rfm']

    second = result.iloc[1]
    assert second['song'] == 'S3' and second['artist'] == 'A3'
    assert len(second['radios'].split(' | ')) == 2
    assert sorted(second['radios'].split(' | ')) == ['megafm', 'rfm']