0.3.06
This commit is contained in:
@@ -30,17 +30,17 @@ const thrillerHistory = `{
|
||||
"People":[{"Name":"Denis Villeneuve","Type":"Director"},{"Name":"Emily Blunt","Type":"Actor"}]
|
||||
}`
|
||||
|
||||
func TestWhyNamesTheGenreTheViewerActuallyWatches(t *testing.T) {
|
||||
func TestWhyPrefersTheRelatedTitleOverItsGenres(t *testing.T) {
|
||||
profile := explainProfile(t, thrillerHistory)
|
||||
candidate := explainItem(t, `{
|
||||
"Id":"c1","Name":"Prisoners","Type":"Movie","Genres":["Thriller"],
|
||||
"Id":"c1","Name":"Prisoners","Type":"Movie","Genres":["Thriller","Crime"],
|
||||
"People":[{"Name":"Denis Villeneuve","Type":"Director"}]
|
||||
}`)
|
||||
|
||||
reasons := Why(profile, candidate, ReasonLimit)
|
||||
|
||||
if len(reasons) == 0 || reasons[0] != "Because you watch Thriller" {
|
||||
t.Fatalf("expected the genre reason first, got %v", reasons)
|
||||
if len(reasons) == 0 || reasons[0] != "Because you watched Sicario" {
|
||||
t.Fatalf("expected the related viewing reason first, got %v", reasons)
|
||||
}
|
||||
if !strings.Contains(strings.Join(reasons, "|"), "Denis Villeneuve") {
|
||||
t.Fatalf("expected the shared director to be named, got %v", reasons)
|
||||
@@ -73,7 +73,7 @@ func TestWhyAlwaysSaysSomething(t *testing.T) {
|
||||
|
||||
reasons := Why(Profile{}, candidate, ReasonLimit)
|
||||
|
||||
if len(reasons) != 1 || reasons[0] != "Drama from your library" {
|
||||
if len(reasons) != 1 || reasons[0] != "Recommended from your library" {
|
||||
t.Fatalf("an empty profile should still explain the title, got %v", reasons)
|
||||
}
|
||||
}
|
||||
@@ -98,9 +98,9 @@ func TestWhyIsCappedAndOrdered(t *testing.T) {
|
||||
t.Fatalf("expected exactly %d reasons, got %v", ReasonLimit, reasons)
|
||||
}
|
||||
want := []string{
|
||||
"Because you watch Thriller",
|
||||
"You've watched Emily Blunt before",
|
||||
"More from Lionsgate",
|
||||
"Because you watched Sicario",
|
||||
"Because you like crime thrillers",
|
||||
"Because you watch Emily Blunt",
|
||||
}
|
||||
for i, reason := range want {
|
||||
if reasons[i] != reason {
|
||||
@@ -109,6 +109,103 @@ func TestWhyIsCappedAndOrdered(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWhyDoesNotTreatDramaAloneAsATitleRelationship(t *testing.T) {
|
||||
profile := explainProfile(t, `{
|
||||
"Id":"h1","Name":"A Drama","Type":"Movie","Genres":["Drama"]
|
||||
}`)
|
||||
candidate := explainItem(t, `{
|
||||
"Id":"c1","Name":"Another Drama","Type":"Movie","Genres":["Drama"]
|
||||
}`)
|
||||
|
||||
reasons := Why(profile, candidate, ReasonLimit)
|
||||
|
||||
if reasons[0] != "Because you watch Drama" {
|
||||
t.Fatalf("broad genre should be the fallback, got %v", reasons)
|
||||
}
|
||||
if strings.Contains(strings.Join(reasons, "|"), "A Drama") {
|
||||
t.Fatalf("Drama alone invented a title relationship: %v", reasons)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWhyUsesSpecificSubgenreBeforeBroadGenre(t *testing.T) {
|
||||
profile := explainProfile(t, `{
|
||||
"Id":"h1","Name":"Crime One","Type":"Movie","Genres":["Crime","Drama"]
|
||||
}`)
|
||||
// Do not retain title evidence here: this test isolates the learned theme wording.
|
||||
profile.ReasonEvidence = nil
|
||||
candidate := explainItem(t, `{
|
||||
"Id":"c1","Name":"Crime Two","Type":"Series","Genres":["Drama","Crime"]
|
||||
}`)
|
||||
|
||||
if got := Why(profile, candidate, 1); len(got) != 1 || got[0] != "Because you like crime dramas" {
|
||||
t.Fatalf("specific theme reason = %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWhyUsesCreatorBeforeBroadGenre(t *testing.T) {
|
||||
profile := explainProfile(t, `{
|
||||
"Id":"h1","Name":"The First","Type":"Movie","Genres":["Drama"],
|
||||
"People":[{"Name":"Vince Gilligan","Type":"Writer"}]
|
||||
}`)
|
||||
candidate := explainItem(t, `{
|
||||
"Id":"c1","Name":"The Second","Type":"Series","Genres":["Drama"],
|
||||
"People":[{"Name":"Vince Gilligan","Type":"Writer"}]
|
||||
}`)
|
||||
|
||||
if got := Why(profile, candidate, 1); len(got) != 1 || got[0] != "More from Vince Gilligan" {
|
||||
t.Fatalf("creator reason = %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWhyDistinguishesFinishedTitlesFromEpisodes(t *testing.T) {
|
||||
finished := explainItem(t, `{
|
||||
"Id":"h1","Name":"Breaking Bad","Type":"Series","Genres":["Crime","Drama"],
|
||||
"UserData":{"Played":true}
|
||||
}`)
|
||||
candidate := explainItem(t, `{
|
||||
"Id":"c1","Name":"Better Call Saul","Type":"Series","Genres":["Crime","Drama"]
|
||||
}`)
|
||||
if got := Why(BuildProfile([]Item{finished}, nil), candidate, 1); got[0] != "Because you finished Breaking Bad" {
|
||||
t.Fatalf("completed title reason = %v", got)
|
||||
}
|
||||
|
||||
episodeHistory := explainItem(t, `{
|
||||
"Id":"ep1","Name":"Pilot","Type":"Episode","SeriesId":"show-1",
|
||||
"SeriesName":"Breaking Bad","Genres":["Crime","Drama"],"UserData":{"Played":true}
|
||||
}`)
|
||||
if got := Why(BuildProfile([]Item{episodeHistory}, nil), candidate, 1); got[0] != "Because you watched Breaking Bad" {
|
||||
t.Fatalf("completed episode overstated series completion: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWhyCanUseARepeatedViewingEra(t *testing.T) {
|
||||
profile := explainProfile(t,
|
||||
`{"Id":"h1","Name":"One","Type":"Movie","ProductionYear":2003,"Genres":["Drama"]}`,
|
||||
`{"Id":"h2","Name":"Two","Type":"Movie","ProductionYear":2007,"Genres":["Drama"]}`,
|
||||
)
|
||||
profile.ReasonEvidence = nil
|
||||
candidate := explainItem(t, `{
|
||||
"Id":"c1","Name":"Three","Type":"Movie","ProductionYear":2005,"Genres":["Drama"]
|
||||
}`)
|
||||
|
||||
if got := Why(profile, candidate, 1); got[0] != "Because you've been watching 2000s dramas" {
|
||||
t.Fatalf("viewing-era reason = %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWhyCanNameAFavouriteTitle(t *testing.T) {
|
||||
favourite := explainItem(t, `{
|
||||
"Id":"h1","Name":"The Wire","Type":"Series","Genres":["Crime","Drama"]
|
||||
}`)
|
||||
candidate := explainItem(t, `{
|
||||
"Id":"c1","Name":"We Own This City","Type":"Series","Genres":["Crime","Drama"]
|
||||
}`)
|
||||
|
||||
if got := Why(BuildProfile(nil, []Item{favourite}), candidate, 1); got[0] != "Because you like The Wire" {
|
||||
t.Fatalf("favourite-title reason = %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWhyIsStableAcrossCalls(t *testing.T) {
|
||||
profile := explainProfile(t, thrillerHistory)
|
||||
candidate := explainItem(t, `{
|
||||
|
||||
Reference in New Issue
Block a user