1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 20:13:20 +08:00

Extract assert step addition out of assertion method

This commit is contained in:
Salman Ahmed 2021-05-19 22:53:21 +03:00
parent 21ca9c8431
commit 71da960000

View File

@ -43,26 +43,24 @@ namespace osu.Game.Tests.Visual.Gameplay
public void TestEmptyDefaultBeatmapSkinFallsBack() public void TestEmptyDefaultBeatmapSkinFallsBack()
{ {
CreateSkinTest(DefaultLegacySkin.Info, () => new TestWorkingBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo)).Skin); CreateSkinTest(DefaultLegacySkin.Info, () => new TestWorkingBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo)).Skin);
AssertComponentsFromExpectedSource(SkinnableTarget.MainHUDComponents, () => skinManager.CurrentSkin.Value); AddAssert("hud from default legacy skin", () => AssertComponentsFromExpectedSource(SkinnableTarget.MainHUDComponents, skinManager.CurrentSkin.Value));
} }
protected void CreateSkinTest(SkinInfo gameCurrentSkin, Func<ISkin> beatmapSkin) protected void CreateSkinTest(SkinInfo gameCurrentSkin, Func<ISkin> getBeatmapSkin)
{ {
CreateTest(() => CreateTest(() =>
{ {
AddStep("setup skins", () => AddStep("setup skins", () =>
{ {
skinManager.CurrentSkinInfo.Value = gameCurrentSkin; skinManager.CurrentSkinInfo.Value = gameCurrentSkin;
currentBeatmapSkin = beatmapSkin(); currentBeatmapSkin = getBeatmapSkin();
}); });
}); });
} }
protected void AssertComponentsFromExpectedSource(SkinnableTarget target, Func<ISkin> expectedSource) protected bool AssertComponentsFromExpectedSource(SkinnableTarget target, ISkin expectedSource)
{ {
AddAssert($"{target} from {expectedSource.GetType().Name}", () => var expectedComponentsContainer = (SkinnableTargetComponentsContainer)expectedSource.GetDrawableComponent(new SkinnableTargetComponent(target));
{
var expectedComponentsContainer = (SkinnableTargetComponentsContainer)expectedSource().GetDrawableComponent(new SkinnableTargetComponent(target));
Add(expectedComponentsContainer); Add(expectedComponentsContainer);
expectedComponentsContainer?.UpdateSubTree(); expectedComponentsContainer?.UpdateSubTree();
@ -73,7 +71,6 @@ namespace osu.Game.Tests.Visual.Gameplay
.ChildrenOfType<SkinnableTargetComponentsContainer>().Single().CreateSkinnableInfo(); .ChildrenOfType<SkinnableTargetComponentsContainer>().Single().CreateSkinnableInfo();
return almostEqual(actualInfo, expectedInfo, 2f); return almostEqual(actualInfo, expectedInfo, 2f);
});
static bool almostEqual(SkinnableInfo info, SkinnableInfo other, float positionTolerance) => static bool almostEqual(SkinnableInfo info, SkinnableInfo other, float positionTolerance) =>
other != null other != null