-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathFilterMatchingTest.cs
More file actions
699 lines (628 loc) · 26.7 KB
/
FilterMatchingTest.cs
File metadata and controls
699 lines (628 loc) · 26.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Filter;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Filter;
namespace osu.Game.Tests.NonVisual.Filtering
{
[TestFixture]
public class FilterMatchingTest
{
private BeatmapInfo getExampleBeatmap() => new BeatmapInfo
{
Ruleset = new RulesetInfo
{
ShortName = "osu",
OnlineID = 0
},
StarRating = 4.0d,
Difficulty = new BeatmapDifficulty
{
ApproachRate = 5.0f,
DrainRate = 3.0f,
CircleSize = 2.0f,
},
Metadata = new BeatmapMetadata
{
Artist = "The Artist",
ArtistUnicode = "check unicode too",
Title = "Title goes here",
TitleUnicode = "TitleUnicode goes here",
Author = { Username = "The Author" },
Source = "unit tests",
Tags = "look for tags too",
UserTags =
{
"song representation/simple",
"style/clean",
}
},
DifficultyName = "version as well",
Length = 2500,
BPM = 160,
BeatDivisor = 12,
Status = BeatmapOnlineStatus.Loved
};
[Test]
public void TestCriteriaMatchingNoRuleset()
{
var exampleBeatmapInfo = getExampleBeatmap();
var criteria = new FilterCriteria();
var carouselItem = new CarouselBeatmap(exampleBeatmapInfo);
carouselItem.Filter(criteria);
ClassicAssert.False(carouselItem.Filtered.Value);
}
[Test]
public void TestCriteriaMatchingSpecificRuleset()
{
var exampleBeatmapInfo = getExampleBeatmap();
var criteria = new FilterCriteria
{
Ruleset = new RulesetInfo { ShortName = "catch" }
};
var carouselItem = new CarouselBeatmap(exampleBeatmapInfo);
carouselItem.Filter(criteria);
ClassicAssert.True(carouselItem.Filtered.Value);
}
[Test]
public void TestCriteriaMatchingConvertedBeatmaps()
{
var exampleBeatmapInfo = getExampleBeatmap();
var criteria = new FilterCriteria
{
Ruleset = new RulesetInfo { OnlineID = 6 },
AllowConvertedBeatmaps = true
};
var carouselItem = new CarouselBeatmap(exampleBeatmapInfo);
carouselItem.Filter(criteria);
ClassicAssert.False(carouselItem.Filtered.Value);
}
[Test]
public void TestCriteriaMatchingConvertedBeatmapsForCustomRulesets()
{
var exampleBeatmapInfo = getExampleBeatmap();
var criteria = new FilterCriteria
{
Ruleset = new RulesetInfo { OnlineID = -1 },
AllowConvertedBeatmaps = true
};
var carouselItem = new CarouselBeatmap(exampleBeatmapInfo);
carouselItem.Filter(criteria);
ClassicAssert.False(carouselItem.Filtered.Value);
}
[Test]
[TestCase(true)]
[TestCase(false)]
public void TestCriteriaMatchingRangeMin(bool inclusive)
{
var exampleBeatmapInfo = getExampleBeatmap();
var criteria = new FilterCriteria
{
Ruleset = new RulesetInfo { OnlineID = 6 },
AllowConvertedBeatmaps = true,
ApproachRate = new FilterCriteria.OptionalRange<float>
{
IsLowerInclusive = inclusive,
Min = 5.0f
}
};
var carouselItem = new CarouselBeatmap(exampleBeatmapInfo);
carouselItem.Filter(criteria);
ClassicAssert.AreEqual(!inclusive, carouselItem.Filtered.Value);
}
[Test]
[TestCase(true)]
[TestCase(false)]
public void TestCriteriaMatchingRangeMax(bool inclusive)
{
var exampleBeatmapInfo = getExampleBeatmap();
var criteria = new FilterCriteria
{
Ruleset = new RulesetInfo { OnlineID = 6 },
AllowConvertedBeatmaps = true,
BPM = new FilterCriteria.OptionalRange<double>
{
IsUpperInclusive = inclusive,
Max = 160d
}
};
var carouselItem = new CarouselBeatmap(exampleBeatmapInfo);
carouselItem.Filter(criteria);
ClassicAssert.AreEqual(!inclusive, carouselItem.Filtered.Value);
}
[Test]
[TestCase("artist", false)]
[TestCase("artist title author", false)]
[TestCase("an artist", true)]
[TestCase("tags too", false)]
[TestCase("version", false)]
[TestCase("an auteur", true)]
[TestCase("unit", false)]
public void TestCriteriaMatchingTerms(string terms, bool filtered)
{
var exampleBeatmapInfo = getExampleBeatmap();
var criteria = new FilterCriteria
{
Ruleset = new RulesetInfo { OnlineID = 6 },
AllowConvertedBeatmaps = true,
SearchText = terms
};
var carouselItem = new CarouselBeatmap(exampleBeatmapInfo);
carouselItem.Filter(criteria);
ClassicAssert.AreEqual(filtered, carouselItem.Filtered.Value);
}
[Test]
[TestCase("\"artist\"", false)]
[TestCase("\"arti\"", true)]
[TestCase("\"artist title author\"", true)]
[TestCase("\"artist\" \"title\" \"author\"", false)]
[TestCase("\"an artist\"", true)]
[TestCase("\"tags too\"", false)]
[TestCase("\"tags to\"", true)]
[TestCase("\"version\"", false)]
[TestCase("\"an auteur\"", true)]
[TestCase("\"Artist\"!", true)]
[TestCase("\"The Artist\"!", false)]
[TestCase("\"the artist\"!", false)]
[TestCase("\"unit tests\"!", false)]
[TestCase("\"\\\"", true)] // nasty case, covers properly escaping user input in underlying regex.
public void TestCriteriaMatchingExactTerms(string terms, bool filtered)
{
var exampleBeatmapInfo = getExampleBeatmap();
var criteria = new FilterCriteria
{
Ruleset = new RulesetInfo { OnlineID = 6 },
AllowConvertedBeatmaps = true,
SearchText = terms
};
var carouselItem = new CarouselBeatmap(exampleBeatmapInfo);
carouselItem.Filter(criteria);
ClassicAssert.AreEqual(filtered, carouselItem.Filtered.Value);
}
[Test]
[TestCase("", false)]
[TestCase("The", false)]
[TestCase("THE", false)]
[TestCase("author", false)]
[TestCase("the author", false)]
[TestCase("the author AND then something else", true)]
[TestCase("unknown", true)]
public void TestCriteriaMatchingCreator(string creatorName, bool filtered)
{
var exampleBeatmapInfo = getExampleBeatmap();
var criteria = new FilterCriteria
{
Creator = new FilterCriteria.OptionalTextFilter { SearchTerm = creatorName }
};
var carouselItem = new CarouselBeatmap(exampleBeatmapInfo);
carouselItem.Filter(criteria);
ClassicAssert.AreEqual(filtered, carouselItem.Filtered.Value);
}
[Test]
[TestCase("\"quoted words\"", false)]
[TestCase("\"the artist\"", false)]
[TestCase("the artist \"quoted words\"", false)]
[TestCase("\"unknown\"", true)]
public void TestCriteriaMatchingTermsAdjacentToPunctuation(string terms, bool filtered)
{
var exampleBeatmapInfo = getExampleBeatmap();
exampleBeatmapInfo.Metadata.Title = "the artist \"quoted words\"";
var criteria = new FilterCriteria
{
Ruleset = new RulesetInfo { OnlineID = 6 },
AllowConvertedBeatmaps = true,
SearchText = terms
};
var carouselItem = new CarouselBeatmap(exampleBeatmapInfo);
carouselItem.Filter(criteria);
ClassicAssert.AreEqual(filtered, carouselItem.Filtered.Value);
}
[Test]
[TestCase("~quoted words~", false)]
[TestCase("the artist", false)]
[TestCase("the artist ~quoted words~", false)]
[TestCase("~unknown~", true)]
public void TestCriteriaMatchingTermsAdjacentToMathSymbols(string terms, bool filtered)
{
var exampleBeatmapInfo = getExampleBeatmap();
exampleBeatmapInfo.Metadata.Title = "the artist ~quoted words~";
var criteria = new FilterCriteria
{
Ruleset = new RulesetInfo { OnlineID = 6 },
AllowConvertedBeatmaps = true,
SearchText = terms
};
var carouselItem = new CarouselBeatmap(exampleBeatmapInfo);
carouselItem.Filter(criteria);
ClassicAssert.AreEqual(filtered, carouselItem.Filtered.Value);
}
[Test]
[TestCase("", false)]
[TestCase("Goes", false)]
[TestCase("GOES", false)]
[TestCase("goes", false)]
[TestCase("title goes", false)]
[TestCase("title goes AND then something else", true)]
[TestCase("titleunicode", false)]
[TestCase("unknown", true)]
public void TestCriteriaMatchingTitle(string titleName, bool filtered)
{
var exampleBeatmapInfo = getExampleBeatmap();
var criteria = new FilterCriteria
{
Title = new FilterCriteria.OptionalTextFilter { SearchTerm = titleName }
};
var carouselItem = new CarouselBeatmap(exampleBeatmapInfo);
carouselItem.Filter(criteria);
ClassicAssert.AreEqual(filtered, carouselItem.Filtered.Value);
}
[Test]
[TestCase("", false)]
[TestCase("The", false)]
[TestCase("THE", false)]
[TestCase("artist", false)]
[TestCase("the artist", false)]
[TestCase("the artist AND then something else", true)]
[TestCase("unicode too", false)]
[TestCase("unknown", true)]
[TestCase("\"Artist\"!", true)]
[TestCase("\"The Artist\"!", false)]
[TestCase("\"the artist\"!", false)]
public void TestCriteriaMatchingArtist(string artistName, bool filtered)
{
var exampleBeatmapInfo = getExampleBeatmap();
var criteria = new FilterCriteria
{
Artist = new FilterCriteria.OptionalTextFilter { SearchTerm = artistName }
};
var carouselItem = new CarouselBeatmap(exampleBeatmapInfo);
carouselItem.Filter(criteria);
ClassicAssert.AreEqual(filtered, carouselItem.Filtered.Value);
}
[Test]
[TestCase("", false)]
[TestCase("artist", false)]
[TestCase("unknown", true)]
public void TestCriteriaMatchingArtistWithNullUnicodeName(string artistName, bool filtered)
{
var exampleBeatmapInfo = getExampleBeatmap();
exampleBeatmapInfo.Metadata.ArtistUnicode = string.Empty;
var criteria = new FilterCriteria
{
Artist = new FilterCriteria.OptionalTextFilter { SearchTerm = artistName }
};
var carouselItem = new CarouselBeatmap(exampleBeatmapInfo);
carouselItem.Filter(criteria);
ClassicAssert.AreEqual(filtered, carouselItem.Filtered.Value);
}
[TestCase("202010", true)]
[TestCase("20201010", false)]
[TestCase("153", true)]
[TestCase("1535", false)]
public void TestCriteriaMatchingBeatmapIDs(string query, bool filtered)
{
var beatmap = getExampleBeatmap();
beatmap.OnlineID = 20201010;
beatmap.BeatmapSet = new BeatmapSetInfo { OnlineID = 1535 };
var criteria = new FilterCriteria { SearchText = query };
var carouselItem = new CarouselBeatmap(beatmap);
carouselItem.Filter(criteria);
ClassicAssert.AreEqual(filtered, carouselItem.Filtered.Value);
}
[Test]
[TestCase("artist")]
[TestCase("unicode")]
public void TestCriteriaNotMatchingArtist(string excludedTerm)
{
var beatmap = getExampleBeatmap();
var criteria = new FilterCriteria
{
Artist = new FilterCriteria.OptionalTextFilter { SearchTerm = excludedTerm, ExcludeTerm = true }
};
var carouselItem = new CarouselBeatmap(beatmap);
carouselItem.Filter(criteria);
ClassicAssert.True(carouselItem.Filtered.Value);
}
[TestCase("simple", false)]
[TestCase("\"style/clean\"", false)]
[TestCase("\"style/clean\"!", false)]
[TestCase("iNiS-style", true)]
[TestCase("\"reading/visually dense\"!", true)]
public void TestCriteriaMatchingUserTags(string query, bool filtered)
{
var beatmap = getExampleBeatmap();
var criteria = new FilterCriteria { UserTags = [new FilterCriteria.OptionalTextFilter { SearchTerm = query }] };
var carouselItem = new CarouselBeatmap(beatmap);
carouselItem.Filter(criteria);
ClassicAssert.AreEqual(filtered, carouselItem.Filtered.Value);
}
[Test]
public void TestCriteriaMatchingMultipleTagsAtOnce()
{
var beatmap = getExampleBeatmap();
var criteria = new FilterCriteria
{
UserTags =
[
new FilterCriteria.OptionalTextFilter { SearchTerm = "\"song representation/simple\"!" },
new FilterCriteria.OptionalTextFilter { SearchTerm = "\"style/clean\"!" }
]
};
var carouselItem = new CarouselBeatmap(beatmap);
carouselItem.Filter(criteria);
ClassicAssert.AreEqual(false, carouselItem.Filtered.Value);
}
[Test]
public void TestCriteriaAllTagFiltersMustMatch()
{
var beatmap = getExampleBeatmap();
var criteria = new FilterCriteria
{
UserTags =
[
new FilterCriteria.OptionalTextFilter { SearchTerm = "\"song representation/simple\"!" },
new FilterCriteria.OptionalTextFilter { SearchTerm = "\"style/dirty\"!" }
]
};
var carouselItem = new CarouselBeatmap(beatmap);
carouselItem.Filter(criteria);
ClassicAssert.AreEqual(true, carouselItem.Filtered.Value);
}
[Test]
public void TestCriteriaMatchingTagExcluded()
{
var beatmap = getExampleBeatmap();
var criteria = new FilterCriteria
{
UserTags =
[
new FilterCriteria.OptionalTextFilter { SearchTerm = "\"song representation/simple\"!", ExcludeTerm = true },
]
};
var carouselItem = new CarouselBeatmap(beatmap);
carouselItem.Filter(criteria);
ClassicAssert.AreEqual(true, carouselItem.Filtered.Value);
}
[Test]
public void TestCriteriaOneTagIncludedAndOneTagExcluded()
{
var beatmap = getExampleBeatmap();
var criteria = new FilterCriteria
{
UserTags =
[
new FilterCriteria.OptionalTextFilter { SearchTerm = "\"song representation/simple\"!" },
new FilterCriteria.OptionalTextFilter { SearchTerm = "\"style/clean\"!", ExcludeTerm = true }
]
};
var carouselItem = new CarouselBeatmap(beatmap);
carouselItem.Filter(criteria);
ClassicAssert.AreEqual(true, carouselItem.Filtered.Value);
}
[Test]
public void TestBeatmapMustHaveAtLeastOneTagIfUserTagFilterActive()
{
var beatmap = getExampleBeatmap();
var criteria = new FilterCriteria { UserTags = [new FilterCriteria.OptionalTextFilter { SearchTerm = "simple" }] };
var carouselItem = new CarouselBeatmap(beatmap);
carouselItem.BeatmapInfo.Metadata.UserTags.Clear();
carouselItem.Filter(criteria);
ClassicAssert.True(carouselItem.Filtered.Value);
}
[Test]
[TestCase("toprank=None", new int[] { 1 })]
[TestCase("toprank=X", new int[] { 0 })]
[TestCase("toprank=A", new int[] { })]
public void TestTopRank(string query, int[] expectedBeatmapIndexes)
{
var carouselBeatmaps = new CarouselBeatmap[]
{
new CarouselBeatmap(new BeatmapInfo()
{
ID = Guid.Empty
}),
new CarouselBeatmap(new BeatmapInfo()
{
ID = Guid.NewGuid()
}),
}.ToList();
Dictionary<Guid, ScoreRank> localUserTopRanks = new Dictionary<Guid, ScoreRank>() {
{ Guid.Empty, ScoreRank.X }
};
//localUserTopRanks.Add();
var criteria = new FilterCriteria();
FilterQueryParser.ApplyQueries(criteria, query);
carouselBeatmaps.ForEach(b => b.Filter(criteria, localUserTopRanks));
int[] visibleBeatmaps = carouselBeatmaps
.Where(b => !b.Filtered.Value)
.Select(b => carouselBeatmaps.IndexOf(b)).ToArray();
Assert.That(visibleBeatmaps, Is.EqualTo(expectedBeatmapIndexes));
}
[Test]
public void TestCustomRulesetCriteria([Values(null, true, false)] bool? matchCustomCriteria)
{
var beatmap = getExampleBeatmap();
var customCriteria = matchCustomCriteria is bool match ? new CustomCriteria(match) : null;
var criteria = new FilterCriteria { RulesetCriteria = customCriteria };
var carouselItem = new CarouselBeatmap(beatmap);
carouselItem.Filter(criteria);
ClassicAssert.AreEqual(matchCustomCriteria == false, carouselItem.Filtered.Value);
}
[TestCase("title!=Title", new[] { 2, 4, 6 })]
[TestCase("title!=\"Title1\"", new[] { 2, 3, 4, 5, 6 })]
[TestCase("title!=\"Title1\"!", new[] { 2, 3, 4, 5, 6 })]
public void TestNotEqualSearchForTextFilters(string query, int[] expectedBeatmapIndexes)
{
string[] titles =
[
"Title1",
"Title1",
"My[Favourite]Song",
"Title",
"Another One",
"Diff in title",
"a",
];
var carouselBeatmaps = titles.Select(title => new CarouselBeatmap(new BeatmapInfo
{
Metadata = new BeatmapMetadata
{
Title = title,
},
})).ToList();
var criteria = new FilterCriteria();
FilterQueryParser.ApplyQueries(criteria, query);
carouselBeatmaps.ForEach(b => b.Filter(criteria));
int[] visibleBeatmaps = carouselBeatmaps
.Where(b => !b.Filtered.Value)
.Select(b => carouselBeatmaps.IndexOf(b)).ToArray();
Assert.That(visibleBeatmaps, Is.EqualTo(expectedBeatmapIndexes));
}
[Test]
public void TestNotEqualSearchForNumberFilters()
{
double[] starRatings =
[
2.78,
1.78,
1.55,
3.78,
1.78,
1.55,
2.78
];
var carouselBeatmaps = starRatings.Select(starRating => new CarouselBeatmap(new BeatmapInfo
{
StarRating = starRating,
})).ToList();
var criteria = new FilterCriteria();
FilterQueryParser.ApplyQueries(criteria, "star!=1.78");
carouselBeatmaps.ForEach(b => b.Filter(criteria));
int[] visibleBeatmaps = carouselBeatmaps
.Where(b => !b.Filtered.Value)
.Select(b => carouselBeatmaps.IndexOf(b)).ToArray();
Assert.That(visibleBeatmaps, Is.EqualTo(new[] { 0, 2, 3, 5, 6 }));
}
[TestCase("status!=ranked", new[] { 1, 2, 4, 5 })]
[TestCase("status!=r", new[] { 1, 2, 4, 5 })]
[TestCase("status!=loved", new[] { 0, 1, 2, 3, 4, 6 })]
[TestCase("status!=l", new[] { 0, 1, 2, 3, 4, 6 })]
[TestCase("status!=r,l", new[] { 1, 2, 4 })]
public void TestNotEqualSearchForEnumFilter(string query, int[] expectedBeatmapIndexes)
{
var carouselBeatmaps = new[]
{
BeatmapOnlineStatus.Ranked,
BeatmapOnlineStatus.Qualified,
BeatmapOnlineStatus.Approved,
BeatmapOnlineStatus.Ranked,
BeatmapOnlineStatus.Approved,
BeatmapOnlineStatus.Loved,
BeatmapOnlineStatus.Ranked
}.Select(info => new CarouselBeatmap(new BeatmapInfo
{
Status = info
})).ToList();
var criteria = new FilterCriteria();
FilterQueryParser.ApplyQueries(criteria, query);
carouselBeatmaps.ForEach(b => b.Filter(criteria));
int[] visibleBeatmaps = carouselBeatmaps
.Where(b => !b.Filtered.Value)
.Select(b => carouselBeatmaps.IndexOf(b)).ToArray();
Assert.That(visibleBeatmaps, Is.EqualTo(expectedBeatmapIndexes));
}
[TestCase("played!=1", new[] { 1, 4, 5 })]
[TestCase("played!=0", new[] { 0, 2, 3, 6, 7 })]
public void TestNotEqualSearchForBooleanFilter(string query, int[] expectedBeatmapIndexes)
{
var carouselBeatmaps = (new DateTimeOffset?[]
{
new DateTimeOffset(2012, 10, 21, 12, 13, 24, TimeSpan.Zero),
null,
new DateTimeOffset(2012, 11, 12, 23, 10, 13, TimeSpan.Zero),
new DateTimeOffset(2013, 2, 13, 11, 43, 23, TimeSpan.Zero),
null,
null,
new DateTimeOffset(2014, 1, 15, 20, 13, 24, TimeSpan.Zero),
new DateTimeOffset(2014, 11, 16, 0, 13, 23, TimeSpan.Zero),
}).Select(lastPlayed => new CarouselBeatmap(new BeatmapInfo
{
LastPlayed = lastPlayed
})).ToList();
var criteria = new FilterCriteria();
FilterQueryParser.ApplyQueries(criteria, query);
carouselBeatmaps.ForEach(b => b.Filter(criteria));
int[] visibleBeatmaps = carouselBeatmaps
.Where(b => !b.Filtered.Value)
.Select(b => carouselBeatmaps.IndexOf(b)).ToArray();
Assert.That(visibleBeatmaps, Is.EqualTo(expectedBeatmapIndexes));
}
[TestCase("ranked!=2012", new[] { 3, 4, 5, 6, 7 })]
[TestCase("ranked!=2012.11", new[] { 0, 1, 3, 4, 5, 6, 7 })]
[TestCase("ranked!=2012.10.21", new[] { 1, 2, 3, 4, 5, 6, 7 })]
public void TestNotEqualSearchForDateFilter(string query, int[] expectedBeatmapIndexes)
{
var carouselBeatmaps = new[]
{
new DateTimeOffset(2012, 10, 21, 13, 42, 13, TimeSpan.Zero),
new DateTimeOffset(2012, 10, 11, 2, 33, 43, TimeSpan.Zero),
new DateTimeOffset(2012, 11, 12, 10, 22, 32, TimeSpan.Zero),
new DateTimeOffset(2013, 2, 13, 5, 19, 0, TimeSpan.Zero),
new DateTimeOffset(2013, 2, 13, 11, 23, 35, TimeSpan.Zero),
new DateTimeOffset(2013, 3, 14, 9, 9, 1, TimeSpan.Zero),
new DateTimeOffset(2014, 1, 15, 10, 5, 0, TimeSpan.Zero),
new DateTimeOffset(2014, 11, 16, 23, 27, 0, TimeSpan.Zero),
}.Select(dateRanked => new CarouselBeatmap(new BeatmapInfo
{
BeatmapSet = new BeatmapSetInfo
{
DateRanked = dateRanked,
}
})).ToList();
var criteria = new FilterCriteria();
FilterQueryParser.ApplyQueries(criteria, query);
carouselBeatmaps.ForEach(b => b.Filter(criteria));
int[] visibleBeatmaps = carouselBeatmaps
.Where(b => !b.Filtered.Value)
.Select(b => carouselBeatmaps.IndexOf(b)).ToArray();
Assert.That(visibleBeatmaps, Is.EqualTo(expectedBeatmapIndexes));
}
// This is a temporary class that emulates what these tests originally used from song select v1.
// If anyone ever ends up tidying up these test, here's a starting point:
// https://gist.github.com/peppy/67fda38f6483fd1dd01ef845ed5bf932
public class CarouselBeatmap
{
public readonly BeatmapInfo BeatmapInfo;
public BindableBool Filtered = new BindableBool();
public CarouselBeatmap(BeatmapInfo beatmapInfo)
{
BeatmapInfo = beatmapInfo;
}
public void Filter(FilterCriteria criteria, IReadOnlyDictionary<Guid, ScoreRank>? localUserTopRanks = null)
{
Filtered.Value = !BeatmapCarouselFilterMatching.CheckCriteriaMatch(BeatmapInfo, criteria, localUserTopRanks ?? new Dictionary<Guid, ScoreRank>());
}
}
private class CustomCriteria : IRulesetFilterCriteria
{
private readonly bool match;
public CustomCriteria(bool shouldMatch)
{
match = shouldMatch;
}
public bool Matches(BeatmapInfo beatmapInfo, FilterCriteria criteria) => match;
public bool TryParseCustomKeywordCriteria(string key, Operator op, string value) => false;
public bool FilterMayChangeFromMods(FilterCriteria criteria, ValueChangedEvent<IReadOnlyList<Mod>> mods) => false;
}
}
}