Files
minstrel/internal/scrobble/threshold_test.go
T
bvandeusenandClaude Opus 5.5 cfdbfa30e3
release / web (push) Successful in 1m41s
release / go (push) Successful in 2m4s
release / govulncheck (push) Successful in 23s
release / integration (push) Successful in 3m5s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Publish the release image to GHCR (dispatch only) (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / android (push) Canceled after 4m35s
release / Build signed APK (push) Canceled after 3m53s
test(backup, scrobble, playevents, recsettings, apierror, auth, providers): merge repeated cases (#8299)
- backup: schema coverage's three tests and the three AWS signing
  examples, one table each.
- scrobble: Qualifies' six boundary tests; the ListenBrainz client's
  refusal mapping, twelve tests of the same rule across three calls, one
  table over call x status; the two similarity lookups' success and URL
  tests, one table.
- playevents: the skip rule's three plays share one fixture. Dropped
  TestRecordPlayEnded_SubThreshold_NoEnqueue: the writer only calls
  scrobble.MaybeEnqueue, whose own test and Qualifies' table hold that
  case; the qualifying-play test still proves the writer calls it.
- recsettings: the three tag-scale tests share one database reset.
- apierror: Error() and From, one test each; auth: RequireAdmin's three.
- providers: GetJSON's not-found and transient answers, one table. Its
  two 401 tests expected the same answer with and without
  TreatAuthAsTransient, which changes only the error's text; the table
  says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 15:16:20 -05:00

26 lines
621 B
Go

package scrobble
import "testing"
// A play is scrobbled once it ran four minutes or half the track, whichever
// comes first, the rule ListenBrainz and Last.fm both use.
func TestQualifies(t *testing.T) {
for _, tc := range []struct {
playedMs int
ratio float64
want bool
}{
{0, 0, false},
{240_000, 0, true},
{0, 0.5, true},
{120_000, 0.49, false},
{239_999, 0.4999, false},
{240_000, 0.4999, true},
{239_999, 0.5, true},
} {
if got := Qualifies(tc.playedMs, tc.ratio); got != tc.want {
t.Errorf("Qualifies(%d ms, %.4f) = %v, want %v", tc.playedMs, tc.ratio, got, tc.want)
}
}
}