import numpy as np
import librosa
import pytest

from src.relative_mode import relative_mode

def test_relative_mode():
    # Generate a synthetic sine wave for testing
    filename = 'data/Bach_1_Gould_0_Major_bachGould1971.wav'
    y, sr = librosa.load(filename)

    # Run the relative_mode function
    df, df_segments = relative_mode(
        y=y,
        sr=sr,
        winlen=1,
        hoplen=0.5,
        distance='cosine',
        profile='krumhansl',
        chromatype='CQT'
    )

    # Assertions to validate the output
    assert not df.empty, "The summary dataframe should not be empty."
    assert not df_segments.empty, "The segments dataframe should not be empty."
#    assert 'time' in df_segments.columns, "The segments dataframe should include time codes."
    assert df_segments['time'].iloc[0] == 0, "The first time code should be 0."
    assert df_segments['time'].iloc[-1] > 0, "The last time code should be greater than 0."

if __name__ == "__main__":
    pytest.main()