Compare commits

...

3 Commits

Author SHA1 Message Date
Hazel Noack
60abe03885 artist tests 2025-10-07 14:26:08 +02:00
Hazel Noack
8fc6d69d45 test album unify 2025-10-07 14:21:03 +02:00
Hazel Noack
e19803323a tests 2025-10-07 14:14:06 +02:00

View File

@ -4,7 +4,7 @@ import (
"testing" "testing"
) )
func TestSong(t *testing.T) { func TestSongDeduplicate(t *testing.T) {
song := Song{ song := Song{
Name: "song_a", Name: "song_a",
Album: Album{ Album: Album{
@ -16,8 +16,8 @@ func TestSong(t *testing.T) {
}, },
}, },
Artists: []Artist{ Artists: []Artist{
{Name: "artist_a"}, {Name: "artist a"},
{Name: "artist_a"}, {Name: "artist a"},
{Name: "artist_b"}, {Name: "artist_b"},
}, },
} }
@ -32,3 +32,153 @@ func TestSong(t *testing.T) {
t.Errorf(`the two artists with the same names in the album have to be merged, %d`, len(compiled.Album.Artists)) t.Errorf(`the two artists with the same names in the album have to be merged, %d`, len(compiled.Album.Artists))
} }
} }
func TestSongUnify(t *testing.T) {
song := Song{
Name: " foo Bar BAZ",
Album: Album{
Name: " foo",
},
}
compiled := song.Compile().(Song)
if compiled.UnifiedName != "foo bar baz" {
t.Errorf(`the song name doesn't get compiled properly`)
}
if compiled.Album.UnifiedName != "foo" {
t.Errorf(`the album name in the song isn't unified`)
}
}
func TestAlbumDeduplicate(t *testing.T) {
album := Album{
Name: "album_a",
Songs: []Song{
{Name: "song a"},
{Name: "song a"},
{Name: "song_b"},
{Name: "song_c"},
{Name: "song_d"},
{Name: "song a"},
},
Artists: []Artist{
{Name: "artist_a"},
{
Name: "artist_a",
Albums: []Album{
{Name: "album_a"},
{Name: "album_b"},
{Name: "album_a"},
},
},
},
}
compiled := album.Compile().(Album)
if len(compiled.Songs) != 4 {
t.Errorf(`didn't properly merge songs`)
}
if len(compiled.Artists) != 1 {
t.Errorf(`didn't properly merge artists`)
}
if len(compiled.Artists[0].Albums) != 2 {
t.Errorf(`didn't properly merge or deduplicate albums`)
}
}
func TestAlbumUnify(t *testing.T) {
album := Album{
Name: " foo Bar BAZ",
}
compiled := album.Compile().(Album)
if compiled.UnifiedName != "foo bar baz" {
t.Errorf(`the song name doesn't get compiled properly`)
}
}
func TestArtistDeduplicate(t *testing.T) {
artist := Artist{
Name: "main_artist",
Albums: []Album{
{Name: "concept_album"},
{
Name: "concept_album",
Artists: []Artist{
{
Name: "main_artist",
Albums: []Album{
{Name: "concept_album", Songs: []Song{{Name: "song_x"}, {Name: "song_x"}}},
{Name: "other_album"},
},
},
{Name: "featured_artist"},
{Name: "featured_artist"},
},
Songs: []Song{
{
Name: "complex_song",
Artists: []Artist{
{Name: "main_artist"},
{Name: "featured_artist"},
{Name: "main_artist"},
},
},
},
},
},
}
compiled := artist.Compile().(Artist)
if len(compiled.Albums) != 1 {
t.Errorf("should deduplicate album artists, got %d", len(compiled.Albums[0].Artists))
}
if len(compiled.Albums[0].Artists) != 2 {
t.Errorf("should deduplicate album artists, got %d", len(compiled.Albums[0].Artists))
}
if len(compiled.Albums[0].Artists[0].Albums) != 2 {
t.Errorf("should deduplicate nested albums, got %d", len(compiled.Albums[0].Artists[0].Albums))
}
if len(compiled.Albums[0].Songs[0].Artists) != 2 {
t.Errorf("should deduplicate song artists, got %d", len(compiled.Albums[0].Songs[0].Artists))
}
}
func TestArtistUnify(t *testing.T) {
artist := Artist{
Name: " The BEATLES ",
Albums: []Album{
{
Name: " Abbey Road ",
Songs: []Song{
{Name: "Come Together "},
{Name: "Something"},
},
},
},
}
compiled := artist.Compile().(Artist)
if compiled.UnifiedName != "the beatles" {
t.Errorf("artist name not unified properly, got: %s", compiled.UnifiedName)
}
if compiled.Albums[0].UnifiedName != "abbey road" {
t.Errorf("album name in artist not unified properly, got: %s", compiled.Albums[0].UnifiedName)
}
if compiled.Albums[0].Songs[0].UnifiedName != "come together" {
t.Errorf("song name in artist album not unified properly, got: %s", compiled.Albums[0].Songs[0].UnifiedName)
}
}