34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
package playlists
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
func TestTieBreakHash_Deterministic(t *testing.T) {
|
|
id := pgtype.UUID{Bytes: [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, Valid: true}
|
|
a := tieBreakHash(id, "2026-05-04")
|
|
b := tieBreakHash(id, "2026-05-04")
|
|
if a != b {
|
|
t.Fatalf("same inputs gave different hashes: %d vs %d", a, b)
|
|
}
|
|
}
|
|
|
|
func TestTieBreakHash_DifferentDateChangesHash(t *testing.T) {
|
|
id := pgtype.UUID{Bytes: [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, Valid: true}
|
|
may4 := tieBreakHash(id, "2026-05-04")
|
|
may5 := tieBreakHash(id, "2026-05-05")
|
|
if may4 == may5 {
|
|
t.Errorf("different dates should change hash; got %d for both", may4)
|
|
}
|
|
}
|
|
|
|
func TestTieBreakHash_DifferentTrackChangesHash(t *testing.T) {
|
|
a := pgtype.UUID{Bytes: [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, Valid: true}
|
|
b := pgtype.UUID{Bytes: [16]byte{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, Valid: true}
|
|
if tieBreakHash(a, "2026-05-04") == tieBreakHash(b, "2026-05-04") {
|
|
t.Errorf("different track ids should change hash for the same date")
|
|
}
|
|
}
|