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

Improve test scenes/cases

This commit is contained in:
smoogipoo 2020-03-02 10:50:41 +09:00
parent 5c15704c81
commit 239cfddcbb
6 changed files with 95 additions and 128 deletions

View File

@ -1,28 +0,0 @@
// 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 osu.Game.Rulesets.Mods;
using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Catch.Tests
{
[TestFixture]
public class TestSceneCatchModSandbox : ModSandboxTestScene
{
public override IReadOnlyList<Type> RequiredTypes => base.RequiredTypes.Append(typeof(TestSceneCatchModSandbox)).ToList();
public TestSceneCatchModSandbox()
: this(null)
{
}
public TestSceneCatchModSandbox(Mod mod = null)
: base(new CatchRuleset(), mod)
{
}
}
}

View File

@ -1,28 +0,0 @@
// 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 osu.Game.Rulesets.Mods;
using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Mania.Tests
{
[TestFixture]
public class TestSceneManiaModSandbox : ModSandboxTestScene
{
public override IReadOnlyList<Type> RequiredTypes => base.RequiredTypes.Append(typeof(TestSceneManiaModSandbox)).ToList();
public TestSceneManiaModSandbox()
: this(null)
{
}
public TestSceneManiaModSandbox(Mod mod = null)
: base(new ManiaRuleset(), mod)
{
}
}
}

View File

@ -5,16 +5,50 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Osu.Tests.Mods namespace osu.Game.Rulesets.Osu.Tests.Mods
{ {
public class TestSceneOsuModDifficultyAdjust : TestSceneOsuModSandbox public class TestSceneOsuModDifficultyAdjust : ModSandboxTestScene
{ {
public override IReadOnlyList<Type> RequiredTypes => base.RequiredTypes.Append(typeof(OsuModDifficultyAdjust)).ToList(); public override IReadOnlyList<Type> RequiredTypes => base.RequiredTypes.Append(typeof(OsuModDifficultyAdjust)).ToList();
public TestSceneOsuModDifficultyAdjust() public TestSceneOsuModDifficultyAdjust()
: base(new OsuModDifficultyAdjust()) : base(new OsuRuleset())
{
}
protected override ModTestCaseData[] CreateTestCases() => new[]
{
new ModTestCaseData("no adjustment", new OsuModDifficultyAdjust())
{
Autoplay = true,
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
},
new ModTestCaseData("cs = 10", new OsuModDifficultyAdjust { CircleSize = { Value = 10 } })
{
Autoplay = true,
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
},
new ModTestCaseData("ar = 10", new OsuModDifficultyAdjust { ApproachRate = { Value = 10 } })
{
Autoplay = true,
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
},
};
protected override TestPlayer CreateReplayPlayer(Score score) => new ScoreAccessibleTestPlayer(score);
private class ScoreAccessibleTestPlayer : TestPlayer
{
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
public ScoreAccessibleTestPlayer(Score score)
: base(score)
{ {
} }
} }
} }
}

View File

@ -1,28 +0,0 @@
// 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 osu.Game.Rulesets.Mods;
using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Osu.Tests
{
[TestFixture]
public class TestSceneOsuModSandbox : ModSandboxTestScene
{
public override IReadOnlyList<Type> RequiredTypes => base.RequiredTypes.Append(typeof(TestSceneOsuModSandbox)).ToList();
public TestSceneOsuModSandbox()
: this(null)
{
}
public TestSceneOsuModSandbox(Mod mod = null)
: base(new OsuRuleset(), mod)
{
}
}
}

View File

@ -1,28 +0,0 @@
// 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 osu.Game.Rulesets.Mods;
using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Taiko.Tests
{
[TestFixture]
public class TestSceneTaikoModSandbox : ModSandboxTestScene
{
public override IReadOnlyList<Type> RequiredTypes => base.RequiredTypes.Append(typeof(TestSceneTaikoModSandbox)).ToList();
public TestSceneTaikoModSandbox()
: this(null)
{
}
public TestSceneTaikoModSandbox(Mod mod = null)
: base(new TaikoRuleset(), mod)
{
}
}
}

View File

@ -4,9 +4,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using JetBrains.Annotations;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Replays;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
@ -29,36 +32,78 @@ namespace osu.Game.Tests.Visual
{ {
foreach (var testCase in CreateTestCases()) foreach (var testCase in CreateTestCases())
{ {
AddStep("set test case", () => currentTest = testCase); AddStep(testCase.Name, () => currentTest = testCase);
base.SetUpSteps(); base.SetUpSteps();
AddUntilStep("test passed", () => testCase.PassCondition?.Invoke() ?? true);
} }
} }
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => currentTest.Beatmap; protected sealed override IBeatmap CreateBeatmap(RulesetInfo ruleset) => currentTest?.Beatmap ?? base.CreateBeatmap(ruleset);
protected override Player CreatePlayer(Ruleset ruleset) protected sealed override Player CreatePlayer(Ruleset ruleset)
{ {
SelectedMods.Value = SelectedMods.Value.Append(currentTest.Mod).ToArray(); SelectedMods.Value = SelectedMods.Value.Append(currentTest.Mod).ToArray();
if (currentTest.Autoplay) var score = currentTest.Autoplay
{ ? ruleset.GetAutoplayMod().CreateReplayScore(Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo, SelectedMods.Value))
// We're simulating an auto-play via a replay so that the auto-play mod does not interfere : new Score { Replay = new Replay() };
var beatmap = Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo, SelectedMods.Value);
var score = ruleset.GetAutoplayMod().CreateReplayScore(beatmap);
return new TestReplayPlayer(score, false, false); return CreateReplayPlayer(score);
}
return base.CreatePlayer(ruleset);
} }
/// <summary>
/// Creates the test cases for this test scene.
/// </summary>
protected abstract ModTestCaseData[] CreateTestCases(); protected abstract ModTestCaseData[] CreateTestCases();
/// <summary>
/// Creates the <see cref="TestPlayer"/> for a test case.
/// </summary>
/// <param name="score">The <see cref="Score"/>.</param>
protected virtual TestPlayer CreateReplayPlayer(Score score) => new TestPlayer(score);
protected class TestPlayer : TestReplayPlayer
{
public TestPlayer(Score score)
: base(score, false, false)
{
}
}
protected class ModTestCaseData protected class ModTestCaseData
{ {
public Mod Mod; /// <summary>
public bool Autoplay; /// Whether to use a replay to simulate an auto-play. True by default.
/// </summary>
public bool Autoplay = true;
/// <summary>
/// The beatmap for this test case.
/// </summary>
[CanBeNull]
public IBeatmap Beatmap; public IBeatmap Beatmap;
/// <summary>
/// The conditions that cause this test case to pass.
/// </summary>
[CanBeNull]
public Func<bool> PassCondition;
/// <summary>
/// The name of this test case, displayed in the test browser.
/// </summary>
public readonly string Name;
/// <summary>
/// The <see cref="Mod"/> this test case tests.
/// </summary>
public readonly Mod Mod;
public ModTestCaseData(string name, Mod mod)
{
Name = name;
Mod = mod;
}
} }
} }
} }