aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--playlist.go6
-rw-r--r--wrms_test.go32
2 files changed, 36 insertions, 2 deletions
diff --git a/playlist.go b/playlist.go
index 049354e..c11843e 100644
--- a/playlist.go
+++ b/playlist.go
@@ -72,6 +72,12 @@ func (pl *Playlist) OrderedList() []*Song {
songs = append(songs, heap.Pop(&cpy).(*Song))
}
+ // TODO: Use more efficiently traversable data structure
+ llog.DDebug("fix song indices in pl")
+ for i, s := range *pl {
+ s.index = i
+ }
+
llog.DDebug("ordering queue %v returned %v", pl, songs)
return songs
}
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()
+ }
+}