From 67b25dea819ea27a9229afebee65e4110c4c6678 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 8 Aug 2023 18:41:56 +0200 Subject: fix broken indices in songs after Playlist.OrderedList() 04205039f24ea6e71d2ce94c7cb7e1395f95179e was not enough to fix the ordered list issue introduced by 26f0033ebb5f8e7c204a042709e3dfa885eac868. heap.Pop uses Swap internally which modifies as songs index. We fix the broken indices by overriding them after the ordered list was created. --- wrms_test.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'wrms_test.go') diff --git a/wrms_test.go b/wrms_test.go index 7d7942c..75318fb 100644 --- a/wrms_test.go +++ b/wrms_test.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "github.com/google/uuid" "io" "testing" @@ -48,10 +49,13 @@ func TestWrmsAdd3Next3(t *testing.T) { t.Fail() } - for _, s := range wrms.queue.OrderedList() { + oq := wrms.queue.OrderedList() + t.Logf("pl: %v", wrms.queue) + t.Logf("oq: %v", oq) + for _, s := range oq { wrms.Next() if wrms.CurrentSong.Load().Uri != s.Uri { - t.Log("Not returning the next song") + t.Logf("Not returning the next song is: %v expected: %v", wrms.CurrentSong.Load(), s) t.Fail() } } @@ -160,3 +164,27 @@ func TestTimeBonus(t *testing.T) { t.Fail() } } + +func TestMultipleAddsOrderedListUpNext(t *testing.T) { + wrms := Wrms{Player: &mockPlayer{}} + nsongs := 21 + songs := make([]*Song, 0, nsongs) + for i := 0; i < nsongs; i++ { + songs = append(songs, NewDummySong(fmt.Sprintf("song%d", i), "snfmt")) + } + + for _, s := range songs { + wrms._addSong(s) + } + + _ = wrms.queue.OrderedList() + + s := songs[16] + wrms.AdjustSongWeight(alice, s.Uri, "up") + t.Logf("queue %v", wrms.queue) + wrms.Next() + if wrms.CurrentSong.Load().Uri != s.Uri { + t.Logf("Not playing the upvoted song %v", s) + t.Fail() + } +} -- cgit v1.2.3