mirror of
https://github.com/osukey/osukey.git
synced 2025-05-09 23:57:18 +09:00
Move to using test methods for better separation
This commit is contained in:
parent
239cfddcbb
commit
ce7cbf29ca
@ -4,6 +4,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using NUnit.Framework;
|
||||||
using osu.Game.Rulesets.Osu.Mods;
|
using osu.Game.Rulesets.Osu.Mods;
|
||||||
using osu.Game.Rulesets.Scoring;
|
using osu.Game.Rulesets.Scoring;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
@ -20,24 +21,26 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override ModTestCaseData[] CreateTestCases() => new[]
|
[Test]
|
||||||
|
public void TestNoAdjustment() => CreateModTest(new ModTestCaseData("no adjustment", new OsuModDifficultyAdjust())
|
||||||
{
|
{
|
||||||
new ModTestCaseData("no adjustment", new OsuModDifficultyAdjust())
|
Autoplay = true,
|
||||||
{
|
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
|
||||||
Autoplay = true,
|
});
|
||||||
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
|
|
||||||
},
|
[Test]
|
||||||
new ModTestCaseData("cs = 10", new OsuModDifficultyAdjust { CircleSize = { Value = 10 } })
|
public void TestCircleSize10() => CreateModTest(new ModTestCaseData("cs = 10", new OsuModDifficultyAdjust { CircleSize = { Value = 10 } })
|
||||||
{
|
{
|
||||||
Autoplay = true,
|
Autoplay = true,
|
||||||
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
|
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
|
||||||
},
|
});
|
||||||
new ModTestCaseData("ar = 10", new OsuModDifficultyAdjust { ApproachRate = { Value = 10 } })
|
|
||||||
{
|
[Test]
|
||||||
Autoplay = true,
|
public void TestApproachRate10() => CreateModTest(new ModTestCaseData("ar = 10", new OsuModDifficultyAdjust { ApproachRate = { Value = 10 } })
|
||||||
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
|
{
|
||||||
},
|
Autoplay = true,
|
||||||
};
|
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
|
||||||
|
});
|
||||||
|
|
||||||
protected override TestPlayer CreateReplayPlayer(Score score) => new ScoreAccessibleTestPlayer(score);
|
protected override TestPlayer CreateReplayPlayer(Score score) => new ScoreAccessibleTestPlayer(score);
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@ namespace osu.Game.Tests.Visual
|
|||||||
{
|
{
|
||||||
public abstract class ModSandboxTestScene : PlayerTestScene
|
public abstract class ModSandboxTestScene : PlayerTestScene
|
||||||
{
|
{
|
||||||
|
protected sealed override bool HasCustomSteps => true;
|
||||||
|
|
||||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
{
|
{
|
||||||
typeof(ModSandboxTestScene)
|
typeof(ModSandboxTestScene)
|
||||||
@ -28,14 +30,15 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
private ModTestCaseData currentTest;
|
private ModTestCaseData currentTest;
|
||||||
|
|
||||||
public override void SetUpSteps()
|
protected void CreateModTest(ModTestCaseData testCaseData) => CreateTest(() =>
|
||||||
{
|
{
|
||||||
foreach (var testCase in CreateTestCases())
|
AddStep("set test data", () => currentTest = testCaseData);
|
||||||
{
|
});
|
||||||
AddStep(testCase.Name, () => currentTest = testCase);
|
|
||||||
base.SetUpSteps();
|
public override void TearDownSteps()
|
||||||
AddUntilStep("test passed", () => testCase.PassCondition?.Invoke() ?? true);
|
{
|
||||||
}
|
AddUntilStep("test passed", () => currentTest?.PassCondition?.Invoke() ?? true);
|
||||||
|
base.TearDownSteps();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected sealed override IBeatmap CreateBeatmap(RulesetInfo ruleset) => currentTest?.Beatmap ?? base.CreateBeatmap(ruleset);
|
protected sealed override IBeatmap CreateBeatmap(RulesetInfo ruleset) => currentTest?.Beatmap ?? base.CreateBeatmap(ruleset);
|
||||||
@ -51,11 +54,6 @@ namespace osu.Game.Tests.Visual
|
|||||||
return CreateReplayPlayer(score);
|
return CreateReplayPlayer(score);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates the test cases for this test scene.
|
|
||||||
/// </summary>
|
|
||||||
protected abstract ModTestCaseData[] CreateTestCases();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the <see cref="TestPlayer"/> for a test case.
|
/// Creates the <see cref="TestPlayer"/> for a test case.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -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;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
@ -14,6 +15,11 @@ namespace osu.Game.Tests.Visual
|
|||||||
{
|
{
|
||||||
public abstract class PlayerTestScene : RateAdjustedBeatmapTestScene
|
public abstract class PlayerTestScene : RateAdjustedBeatmapTestScene
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Whether custom test steps are provided. Custom tests should invoke <see cref="CreateTest"/> to create the test steps.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual bool HasCustomSteps { get; } = false;
|
||||||
|
|
||||||
private readonly Ruleset ruleset;
|
private readonly Ruleset ruleset;
|
||||||
|
|
||||||
protected Player Player;
|
protected Player Player;
|
||||||
@ -37,6 +43,17 @@ namespace osu.Game.Tests.Visual
|
|||||||
{
|
{
|
||||||
base.SetUpSteps();
|
base.SetUpSteps();
|
||||||
|
|
||||||
|
if (!HasCustomSteps)
|
||||||
|
CreateTest(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void CreateTest(Action action)
|
||||||
|
{
|
||||||
|
if (action != null && !HasCustomSteps)
|
||||||
|
throw new InvalidOperationException($"Cannot add custom test steps without {nameof(HasCustomSteps)} being set.");
|
||||||
|
|
||||||
|
action?.Invoke();
|
||||||
|
|
||||||
AddStep(ruleset.RulesetInfo.Name, LoadPlayer);
|
AddStep(ruleset.RulesetInfo.Name, LoadPlayer);
|
||||||
AddUntilStep("player loaded", () => Player.IsLoaded && Player.Alpha == 1);
|
AddUntilStep("player loaded", () => Player.IsLoaded && Player.Alpha == 1);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
public virtual void SetUpSteps() => addExitAllScreensStep();
|
public virtual void SetUpSteps() => addExitAllScreensStep();
|
||||||
|
|
||||||
[TearDownSteps]
|
[TearDownSteps]
|
||||||
public void TearDownSteps() => addExitAllScreensStep();
|
public virtual void TearDownSteps() => addExitAllScreensStep();
|
||||||
|
|
||||||
private void addExitAllScreensStep()
|
private void addExitAllScreensStep()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user