@@ -86,7 +86,7 @@ func Test_filterEpisodes(t *testing.T) {
86
86
87
87
func Test_buildTaggedNyaaList (t * testing.T ) {
88
88
t .Run ("empty" , func (t * testing.T ) {
89
- got := parseAndSort ([]nyaa.Entry {})
89
+ got := parseAndSort (animelist. Entry {}, []nyaa.Entry {})
90
90
require .Empty (t , got )
91
91
})
92
92
t .Run ("sort by tag" , func (t * testing.T ) {
@@ -96,7 +96,7 @@ func Test_buildTaggedNyaaList(t *testing.T) {
96
96
{Title : "Show3: S03E01" },
97
97
{Title : "Show3: S03" },
98
98
}
99
- got := parseAndSort (input )
99
+ got := parseAndSort (animelist. Entry {}, input )
100
100
require .Len (t , got , len (input ))
101
101
for i := 1 ; i < len (got ); i ++ {
102
102
require .True (t , tagCompare (got [i - 1 ].SeasonEpisodeTag , got [i ].SeasonEpisodeTag ) <= 0 )
@@ -106,7 +106,7 @@ func Test_buildTaggedNyaaList(t *testing.T) {
106
106
107
107
func Test_filterNyaaFeed (t * testing.T ) {
108
108
t .Run ("empty" , func (t * testing.T ) {
109
- got := getDownloadableEntries ([]nyaa.Entry {}, "" , animelist .AiringStatusAiring )
109
+ got := getDownloadableEntries (animelist. Entry {}, []nyaa.Entry {}, "" , animelist .AiringStatusAiring )
110
110
require .Empty (t , got )
111
111
})
112
112
t .Run ("airing: no latestTag" , func (t * testing.T ) {
@@ -115,7 +115,7 @@ func Test_filterNyaaFeed(t *testing.T) {
115
115
{Title : "Show3: S03E02" },
116
116
{Title : "Show3: S03E01" },
117
117
}
118
- got := getDownloadableEntries (input , "" , animelist .AiringStatusAiring )
118
+ got := getDownloadableEntries (animelist. Entry {}, input , "" , animelist .AiringStatusAiring )
119
119
require .Len (t , got , len (input ))
120
120
for i := 1 ; i < len (got ); i ++ {
121
121
require .True (t , tagCompare (got [i - 1 ].SeasonEpisodeTag , got [i ].SeasonEpisodeTag ) <= 0 )
@@ -127,19 +127,19 @@ func Test_filterNyaaFeed(t *testing.T) {
127
127
{Title : "Show3: S03E02" },
128
128
{Title : "Show3: S03E01" },
129
129
}
130
- got := getDownloadableEntries (input , "Show3 S03E02" , animelist .AiringStatusAiring )
130
+ got := getDownloadableEntries (animelist. Entry {}, input , "Show3 S03E02" , animelist .AiringStatusAiring )
131
131
require .Len (t , got , 1 )
132
- require .Equal (t , parseAndSort (input [:1 ]), got )
132
+ require .Equal (t , parseAndSort (animelist. Entry {}, input [:1 ]), got )
133
133
})
134
134
t .Run ("airing: with repeated tag" , func (t * testing.T ) {
135
135
input := []nyaa.Entry {
136
136
{Title : "Show3: S03E02" },
137
137
{Title : "Show3: S03E02" },
138
138
{Title : "Show3: S03E01" },
139
139
}
140
- got := getDownloadableEntries (input , "Show3 S03E01" , animelist .AiringStatusAiring )
140
+ got := getDownloadableEntries (animelist. Entry {}, input , "Show3 S03E01" , animelist .AiringStatusAiring )
141
141
require .Len (t , got , 1 )
142
- require .Equal (t , parseAndSort (input [0 :1 ]), got )
142
+ require .Equal (t , parseAndSort (animelist. Entry {}, input [0 :1 ]), got )
143
143
})
144
144
145
145
t .Run ("airing: with latestTag and quality" , func (t * testing.T ) {
@@ -149,57 +149,71 @@ func Test_filterNyaaFeed(t *testing.T) {
149
149
{Title : "Show3: S03E02" },
150
150
{Title : "Show3: S03E01" },
151
151
}
152
- got := getDownloadableEntries (input , "Show3 S03E02" , animelist .AiringStatusAiring )
152
+ got := getDownloadableEntries (animelist. Entry {}, input , "Show3 S03E02" , animelist .AiringStatusAiring )
153
153
require .Len (t , got , 1 )
154
- require .Equal (t , parseAndSort (input [1 :2 ]), got )
154
+ require .Equal (t , parseAndSort (animelist. Entry {}, input [1 :2 ]), got )
155
155
})
156
156
t .Run ("aired: with latestTag" , func (t * testing.T ) {
157
157
input := []nyaa.Entry {
158
158
{Title : "Show3: S03E03" },
159
159
{Title : "Show3: S03E02" },
160
160
{Title : "Show3: S03E01" },
161
161
}
162
- got := getDownloadableEntries (input , "Show3 S03E02" , animelist .AiringStatusAired )
162
+ got := getDownloadableEntries (animelist. Entry {}, input , "Show3 S03E02" , animelist .AiringStatusAired )
163
163
require .Len (t , got , 1 )
164
- require .Equal (t , parseAndSort (input [:1 ]), got )
164
+ require .Equal (t , parseAndSort (animelist. Entry {}, input [:1 ]), got )
165
165
})
166
166
t .Run ("aired: with batch, no latestTag" , func (t * testing.T ) {
167
167
input := []nyaa.Entry {
168
168
{Title : "Show3: S03E03" },
169
169
{Title : "Show3: S03E02" },
170
170
{Title : "Show3: S03" },
171
171
}
172
- got := getDownloadableEntries (input , "" , animelist .AiringStatusAired )
172
+ got := getDownloadableEntries (animelist. Entry {}, input , "" , animelist .AiringStatusAired )
173
173
require .Len (t , got , 1 )
174
- require .Equal (t , parseAndSort (input [2 :]), got )
174
+ require .Equal (t , parseAndSort (animelist. Entry {}, input [2 :]), got )
175
175
})
176
176
t .Run ("aired: with batch, different qualities" , func (t * testing.T ) {
177
177
input := []nyaa.Entry {
178
178
{Title : "Show3: S03 1220x760" },
179
179
{Title : "Show3: S03 1080p" },
180
180
}
181
- got := getDownloadableEntries (input , "" , animelist .AiringStatusAired )
181
+ got := getDownloadableEntries (animelist. Entry {}, input , "" , animelist .AiringStatusAired )
182
182
require .Len (t , got , 1 )
183
- require .Equal (t , parseAndSort (input [1 :]), got )
183
+ require .Equal (t , parseAndSort (animelist. Entry {}, input [1 :]), got )
184
184
})
185
185
t .Run ("aired: with batch, with latestTag" , func (t * testing.T ) {
186
186
input := []nyaa.Entry {
187
187
{Title : "Show3: S03E03" },
188
188
{Title : "Show3: S03E02" },
189
189
{Title : "Show3: S03" },
190
190
}
191
- got := getDownloadableEntries (input , "Show3 S03E02" , animelist .AiringStatusAired )
191
+ got := getDownloadableEntries (animelist. Entry {}, input , "Show3 S03E02" , animelist .AiringStatusAired )
192
192
require .Len (t , got , 1 )
193
- require .Equal (t , parseAndSort (input [:1 ]), got )
193
+ require .Equal (t , parseAndSort (animelist. Entry {}, input [:1 ]), got )
194
194
})
195
195
t .Run ("same tag and quality, different seeders" , func (t * testing.T ) {
196
196
input := []nyaa.Entry {
197
197
{Title : "Show3: S03E03" , Seeders : 1 },
198
198
{Title : "Show3: S03E03" , Seeders : 10 },
199
199
{Title : "Show3: S03" },
200
200
}
201
- got := getDownloadableEntries (input , "Show3 S03E02" , animelist .AiringStatusAired )
201
+ got := getDownloadableEntries (animelist. Entry {}, input , "Show3 S03E02" , animelist .AiringStatusAired )
202
202
require .Len (t , got , 1 )
203
- require .Equal (t , parseAndSort (input [1 :2 ]), got )
203
+ require .Equal (t , parseAndSort (animelist.Entry {}, input [1 :2 ]), got )
204
+ })
205
+ }
206
+
207
+ func Test_calculateTitleSimilarityScore (t * testing.T ) {
208
+ t .Run ("exact match in lower case" , func (t * testing.T ) {
209
+ score := calculateTitleSimilarityScore ("My pony academy: the story continues" , "My Pony Academy the story continues" )
210
+ require .EqualValues (t , score , 1 )
211
+ })
212
+
213
+ t .Run ("closer match should have higher score" , func (t * testing.T ) {
214
+ originalTitle := "My pony academy: the battle continues"
215
+ scoreA := calculateTitleSimilarityScore (originalTitle , "My Pony Academy" )
216
+ scoreB := calculateTitleSimilarityScore (originalTitle , "My Pony Academy 2: second battle" )
217
+ require .Greater (t , scoreA , scoreB )
204
218
})
205
219
}
0 commit comments