Add test scene

This commit is contained in:
Andrei Zavatski
2020-03-11 23:09:29 +03:00
parent 09b9983286
commit e46c070d95
2 changed files with 48 additions and 15 deletions

View File

@ -4,7 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using NUnit.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -34,8 +34,8 @@ namespace osu.Game.Rulesets.Catch.Tests
private DrawableCatchRuleset drawableRuleset; private DrawableCatchRuleset drawableRuleset;
private double playfieldTime => drawableRuleset.Playfield.Time.Current; private double playfieldTime => drawableRuleset.Playfield.Time.Current;
[BackgroundDependencyLoader] [SetUp]
private void load() public void Setup() => Schedule(() =>
{ {
var controlPointInfo = new ControlPointInfo(); var controlPointInfo = new ControlPointInfo();
controlPointInfo.Add(0, new TimingControlPoint()); controlPointInfo.Add(0, new TimingControlPoint());
@ -57,7 +57,7 @@ namespace osu.Game.Rulesets.Catch.Tests
ControlPointInfo = controlPointInfo ControlPointInfo = controlPointInfo
}); });
Add(new Container Child = new Container
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -66,16 +66,49 @@ namespace osu.Game.Rulesets.Catch.Tests
{ {
drawableRuleset = new DrawableCatchRuleset(new CatchRuleset(), beatmap.GetPlayableBeatmap(new CatchRuleset().RulesetInfo)) drawableRuleset = new DrawableCatchRuleset(new CatchRuleset(), beatmap.GetPlayableBeatmap(new CatchRuleset().RulesetInfo))
} }
};
}); });
AddStep("miss fruits", () => spawnFruits()); [Test]
public void TestFruits()
{
AddStep("hit fruits", () => spawnFruits(true)); AddStep("hit fruits", () => spawnFruits(true));
AddStep("miss juicestream", () => spawnJuiceStream()); AddUntilStep("wait for completion", () => playfieldIsEmpty);
AddStep("hit juicestream", () => spawnJuiceStream(true)); AddAssert("catcher state is idle", () => catcherState == CatcherAnimationState.Idle);
AddStep("miss bananas", () => spawnBananas());
AddStep("hit bananas", () => spawnBananas(true)); AddStep("miss fruits", () => spawnFruits());
AddUntilStep("wait for completion", () => playfieldIsEmpty);
AddAssert("catcher state is failed", () => catcherState == CatcherAnimationState.Fail);
} }
[Test]
public void TestJuicestream()
{
AddStep("hit juicestream", () => spawnJuiceStream(true));
AddUntilStep("wait for completion", () => playfieldIsEmpty);
AddAssert("catcher state is idle", () => catcherState == CatcherAnimationState.Idle);
AddStep("miss juicestream", () => spawnJuiceStream());
AddUntilStep("wait for completion", () => playfieldIsEmpty);
AddAssert("catcher state is failed", () => catcherState == CatcherAnimationState.Fail);
}
[Test]
public void TestBananas()
{
AddStep("hit bananas", () => spawnBananas(true));
AddUntilStep("wait for completion", () => playfieldIsEmpty);
AddAssert("catcher state is idle", () => catcherState == CatcherAnimationState.Idle);
AddStep("miss bananas", () => spawnBananas());
AddUntilStep("wait for completion", () => playfieldIsEmpty);
AddAssert("catcher state is idle", () => catcherState == CatcherAnimationState.Idle);
}
private bool playfieldIsEmpty => !((CatchPlayfield)drawableRuleset.Playfield).AllHitObjects.Any(h => h.IsAlive);
private CatcherAnimationState catcherState => ((CatchPlayfield)drawableRuleset.Playfield).CatcherArea.MovableCatcher.CurrentState;
private void spawnFruits(bool hit = false) private void spawnFruits(bool hit = false)
{ {
for (int i = 1; i <= 4; i++) for (int i = 1; i <= 4; i++)

View File

@ -188,7 +188,7 @@ namespace osu.Game.Rulesets.Catch.UI
CatcherSprite current; CatcherSprite current;
switch (currentState) switch (CurrentState)
{ {
default: default:
current = catcherIdle; current = catcherIdle;
@ -274,7 +274,7 @@ namespace osu.Game.Rulesets.Catch.UI
return additive; return additive;
} }
private Drawable createCatcherSprite() => new CatcherSprite(currentState); private Drawable createCatcherSprite() => new CatcherSprite(CurrentState);
/// <summary> /// <summary>
/// Add a caught fruit to the catcher's stack. /// Add a caught fruit to the catcher's stack.
@ -355,14 +355,14 @@ namespace osu.Game.Rulesets.Catch.UI
private void updateState(CatcherAnimationState state) private void updateState(CatcherAnimationState state)
{ {
if (currentState == state) if (CurrentState == state)
return; return;
currentState = state; CurrentState = state;
updateCatcher(); updateCatcher();
} }
private CatcherAnimationState currentState; public CatcherAnimationState CurrentState;
private double hyperDashModifier = 1; private double hyperDashModifier = 1;
private int hyperDashDirection; private int hyperDashDirection;