1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 17:27:24 +08:00

Adjust sample test to pass with pooling

This commit is contained in:
Bartłomiej Dach 2020-12-20 18:25:49 +01:00
parent b24fc1922e
commit 6e21806873

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Audio; using osu.Game.Audio;
@ -18,11 +19,8 @@ namespace osu.Game.Rulesets.Taiko.Tests
public override void SetUpSteps() public override void SetUpSteps()
{ {
base.SetUpSteps(); base.SetUpSteps();
AddAssert("has correct samples", () =>
{
var names = Player.DrawableRuleset.Playfield.AllHitObjects.OfType<DrawableHit>().Select(h => string.Join(',', h.GetSamples().Select(s => s.Name)));
var expected = new[] var expectedSampleNames = new[]
{ {
string.Empty, string.Empty,
string.Empty, string.Empty,
@ -33,9 +31,21 @@ namespace osu.Game.Rulesets.Taiko.Tests
HitSampleInfo.HIT_WHISTLE, HitSampleInfo.HIT_WHISTLE,
HitSampleInfo.HIT_WHISTLE, HitSampleInfo.HIT_WHISTLE,
}; };
var actualSampleNames = new List<string>();
return names.SequenceEqual(expected); // due to pooling we can't access all samples right away due to object re-use,
// so we need to collect as we go.
AddStep("collect sample names", () => Player.DrawableRuleset.Playfield.NewResult += (dho, _) =>
{
if (!(dho is DrawableHit h))
return;
actualSampleNames.Add(string.Join(',', h.GetSamples().Select(s => s.Name)));
}); });
AddUntilStep("all samples collected", () => actualSampleNames.Count == expectedSampleNames.Length);
AddAssert("samples are correct", () => actualSampleNames.SequenceEqual(expectedSampleNames));
} }
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => new TaikoBeatmapConversionTest().GetBeatmap("sample-to-type-conversions"); protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => new TaikoBeatmapConversionTest().GetBeatmap("sample-to-type-conversions");