Initial commit: LastRecc discovery feed and weekly engine
This commit is contained in:
40 files changed
+6972
No files matched your search
@@ -0,0 +1,93 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"lastrecc-go/internal/lastfm"
|
||||
"lastrecc-go/internal/navidrome"
|
||||
"lastrecc-go/internal/text"
|
||||
)
|
||||
|
||||
func TestSelectFavoriteSongs(t *testing.T) {
|
||||
songs := []navidrome.Song{
|
||||
{ID: "a", Artist: "A", Title: "First"},
|
||||
{ID: "b", Artist: "A", Title: "Second"},
|
||||
{ID: "c", Artist: "A", Title: "Third"},
|
||||
}
|
||||
top := []lastfm.Track{
|
||||
{Name: "Third"},
|
||||
{Name: "First"},
|
||||
}
|
||||
heard := map[string]bool{text.TrackKey("A", "Second"): true}
|
||||
selected := selectFavoriteSongs(songs, top, heard, 2)
|
||||
if len(selected) != 2 {
|
||||
t.Fatalf("expected 2 songs, got %d", len(selected))
|
||||
}
|
||||
if selected[0].ID != "c" || selected[1].ID != "a" {
|
||||
t.Fatalf("unexpected order: %+v", selected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectFavoriteSongsFallsBackToAlbumOrder(t *testing.T) {
|
||||
songs := []navidrome.Song{
|
||||
{ID: "a", Artist: "A", Title: "First"},
|
||||
{ID: "b", Artist: "A", Title: "Second"},
|
||||
}
|
||||
selected := selectFavoriteSongs(songs, nil, map[string]bool{}, 1)
|
||||
if len(selected) != 1 || selected[0].ID != "a" {
|
||||
t.Fatalf("unexpected selection: %+v", selected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildPlaylistTracksDedupesAndCaps(t *testing.T) {
|
||||
plan := &Plan{
|
||||
SeedAlbums: []AlbumPlan{
|
||||
{
|
||||
Score: 0.5,
|
||||
SelectedSongs: []navidrome.Song{
|
||||
{ID: "1", Artist: "A", Title: "One", Album: "X"},
|
||||
{ID: "2", Artist: "A", Title: "Two", Album: "X"},
|
||||
},
|
||||
},
|
||||
},
|
||||
Artists: []ArtistPlan{
|
||||
{
|
||||
Score: 0.9,
|
||||
Album: &AlbumPlan{
|
||||
Action: "downloaded",
|
||||
SelectedSongs: []navidrome.Song{
|
||||
{ID: "1", Artist: "A", Title: "One", Album: "X"},
|
||||
{ID: "3", Artist: "B", Title: "Three", Album: "Y"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
tracks := BuildPlaylistTracks(plan, Options{PlaylistMaxTracks: 2}, nil)
|
||||
if len(tracks) != 2 {
|
||||
t.Fatalf("expected cap of 2, got %d", len(tracks))
|
||||
}
|
||||
if tracks[0].SongID != "3" || tracks[1].SongID != "1" {
|
||||
t.Fatalf("unexpected order/dedupe: %+v", tracks)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildPlaylistTracksRepeatWindow(t *testing.T) {
|
||||
plan := &Plan{
|
||||
SeedAlbums: []AlbumPlan{
|
||||
{
|
||||
Score: 1,
|
||||
SelectedSongs: []navidrome.Song{
|
||||
{ID: "1", Artist: "A", Title: "One"},
|
||||
{ID: "2", Artist: "A", Title: "Two"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
current := text.WeekIndex(nowUTC())
|
||||
history := map[string]int{text.TrackKey("A", "One"): current}
|
||||
tracks := BuildPlaylistTracks(plan, Options{RepeatWeeks: 4}, history)
|
||||
if len(tracks) != 1 || tracks[0].SongID != "2" {
|
||||
t.Fatalf("expected only unheard track, got %+v", tracks)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user