import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Comparator;
import java.util.List;

import org.junit.jupiter.api.Test;

// Las cuatro formas de escribir "por duración" ordenan exactamente igual.
class ThreeWaysTest {

    private static List<Song> sortedWith(Comparator<Song> order) {
        List<Song> songs = Songs.sample();
        songs.sort(order);
        return songs;
    }

    @Test
    void lambdaAndComparingIntAgreeWithByDuration() {
        List<Song> expected = sortedWith(new ByDuration());
        assertEquals(expected, sortedWith((a, b) -> Integer.compare(a.seconds(), b.seconds())));
        assertEquals(expected, sortedWith(Comparator.comparingInt(Song::seconds)));
    }

    @Test
    void reversedTurnsTheOrderAround() {
        List<Song> songs = sortedWith(Comparator.comparingInt(Song::seconds).reversed());
        assertEquals("Puente de piedra", songs.get(0).title());
        assertEquals("Arena", songs.get(songs.size() - 1).title());
    }
}
