aboutsummaryrefslogtreecommitdiff
path: root/playlist_test.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-07-22 15:15:47 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2023-07-22 15:15:47 +0200
commit26f0033ebb5f8e7c204a042709e3dfa885eac868 (patch)
tree6e3c0bbb0525bd295db93a363b28d33f557a0a17 /playlist_test.go
parentd00967aa6e6ce880b5f900e8493fd93092fd36ca (diff)
downloadWRMS-26f0033ebb5f8e7c204a042709e3dfa885eac868.tar.gz
WRMS-26f0033ebb5f8e7c204a042709e3dfa885eac868.zip
fix applyTimeBonus by always using Song pointers
Storing song objects in the Songs slice and using pointers to the underlying array slots breaks if the underlying array must be grown. When the array is grown the objects are copied to the new array and the pointers used in queue point to the old objects. This causes that Playlist.applyTimeBonus may not correctly apply to the most recent list of songs. This is fixed by always using Song pointers.
Diffstat (limited to 'playlist_test.go')
-rw-r--r--playlist_test.go38
1 files changed, 19 insertions, 19 deletions
diff --git a/playlist_test.go b/playlist_test.go
index 2ccad7c..8730737 100644
--- a/playlist_test.go
+++ b/playlist_test.go
@@ -5,7 +5,7 @@ import "testing"
func TestPlAdd(t *testing.T) {
var pl Playlist
s := NewDummySong("Foo", "Bar")
- pl.Add(&s)
+ pl.Add(s)
if len(pl) != 1 {
t.Log("len should be 1")
t.Fail()
@@ -15,7 +15,7 @@ func TestPlAdd(t *testing.T) {
func TestPlAddPop(t *testing.T) {
var pl Playlist
s := NewDummySong("Foo", "Bar")
- pl.Add(&s)
+ pl.Add(s)
if len(pl) != 1 {
t.Log("len should be 1")
t.Fail()
@@ -27,7 +27,7 @@ func TestPlAddPop(t *testing.T) {
t.Fail()
}
- if ps != &s {
+ if ps != s {
t.Log("the popped ptr should match the one added")
t.Fail()
}
@@ -37,8 +37,8 @@ func TestPlAddPopTwice(t *testing.T) {
var pl Playlist
s1 := NewDummySong("Foo", "Bar")
s2 := NewDummySong("Nasen", "Baer")
- pl.Add(&s1)
- pl.Add(&s2)
+ pl.Add(s1)
+ pl.Add(s2)
if len(pl) != 2 {
t.Log("len should be 2")
t.Fail()
@@ -51,12 +51,12 @@ func TestPlAddPopTwice(t *testing.T) {
t.Fail()
}
- if ps1 != &s1 {
+ if ps1 != s1 {
t.Log("the popped ptr should match the one added")
t.Fail()
}
- if ps2 != &s2 {
+ if ps2 != s2 {
t.Log("the popped ptr should match the one added")
t.Fail()
}
@@ -66,15 +66,15 @@ func TestPlAdd2AdjustPop(t *testing.T) {
var pl Playlist
s1 := NewDummySong("Foo", "Bar")
s2 := NewDummySong("Nasen", "Baer")
- pl.Add(&s1)
- pl.Add(&s2)
+ pl.Add(s1)
+ pl.Add(s2)
if len(pl) != 2 {
t.Log("len should be 2")
t.Fail()
}
s2.Weight += 1
- pl.Adjust(&s2)
+ pl.Adjust(s2)
ps := pl.PopSong()
if len(pl) != 1 {
@@ -82,7 +82,7 @@ func TestPlAdd2AdjustPop(t *testing.T) {
t.Fail()
}
- if ps != &s2 {
+ if ps != s2 {
t.Log("the popped ptr should match the one adjusted")
t.Fail()
}
@@ -93,9 +93,9 @@ func TestPlAdd3AdjustAdjustPop(t *testing.T) {
s1 := NewDummySong("Foo", "Bar")
s2 := NewDummySong("Nasen", "Baer")
s3 := NewDummySong("Hut", "Traeger")
- pl.Add(&s1)
- pl.Add(&s2)
- pl.Add(&s3)
+ pl.Add(s1)
+ pl.Add(s2)
+ pl.Add(s3)
if len(pl) != 3 {
t.Log("len should be 3")
@@ -103,13 +103,13 @@ func TestPlAdd3AdjustAdjustPop(t *testing.T) {
}
s1.Weight += 1
- pl.Adjust(&s1)
+ pl.Adjust(s1)
s2.Weight -= 1
- pl.Adjust(&s2)
+ pl.Adjust(s2)
s3.Weight += 1
- pl.Adjust(&s3)
+ pl.Adjust(s3)
ps := pl.PopSong()
if len(pl) != 2 {
@@ -117,7 +117,7 @@ func TestPlAdd3AdjustAdjustPop(t *testing.T) {
t.Fail()
}
- if ps == &s2 {
+ if ps == s2 {
t.Log("the popped ptr is the downvoted one")
t.Fail()
}
@@ -128,7 +128,7 @@ func TestPlAdd3AdjustAdjustPop(t *testing.T) {
t.Fail()
}
- if ps == &s2 {
+ if ps == s2 {
t.Log("the popped ptr is the downvoted one")
t.Fail()
}