mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 07:07:45 +08:00
Improve test scenes/cases
This commit is contained in:
parent
5c15704c81
commit
239cfddcbb
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -5,16 +5,50 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
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
|
||||
{
|
||||
public class TestSceneOsuModDifficultyAdjust : TestSceneOsuModSandbox
|
||||
public class TestSceneOsuModDifficultyAdjust : ModSandboxTestScene
|
||||
{
|
||||
public override IReadOnlyList<Type> RequiredTypes => base.RequiredTypes.Append(typeof(OsuModDifficultyAdjust)).ToList();
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -4,9 +4,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Replays;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens.Play;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
@ -29,36 +32,78 @@ namespace osu.Game.Tests.Visual
|
||||
{
|
||||
foreach (var testCase in CreateTestCases())
|
||||
{
|
||||
AddStep("set test case", () => currentTest = testCase);
|
||||
AddStep(testCase.Name, () => currentTest = testCase);
|
||||
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();
|
||||
|
||||
if (currentTest.Autoplay)
|
||||
{
|
||||
// We're simulating an auto-play via a replay so that the auto-play mod does not interfere
|
||||
var beatmap = Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo, SelectedMods.Value);
|
||||
var score = ruleset.GetAutoplayMod().CreateReplayScore(beatmap);
|
||||
var score = currentTest.Autoplay
|
||||
? ruleset.GetAutoplayMod().CreateReplayScore(Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo, SelectedMods.Value))
|
||||
: new Score { Replay = new Replay() };
|
||||
|
||||
return new TestReplayPlayer(score, false, false);
|
||||
}
|
||||
|
||||
return base.CreatePlayer(ruleset);
|
||||
return CreateReplayPlayer(score);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the test cases for this test scene.
|
||||
/// </summary>
|
||||
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
|
||||
{
|
||||
public Mod Mod;
|
||||
public bool Autoplay;
|
||||
/// <summary>
|
||||
/// 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;
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user