From afe9ac174025ea1d392eec0f75ca4cb0c464efbe Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 22 Jun 2019 16:11:47 +0200 Subject: [PATCH 1/3] fix assert descriptions --- osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs index e97983dd8b..0e98206acb 100644 --- a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs +++ b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs @@ -74,7 +74,7 @@ namespace osu.Game.Tests.Visual.Components { AddStep("move mouse", () => InputManager.MoveMouseTo(box2.ScreenSpaceDrawQuad.Centre)); - AddAssert("check not idle", () => box1.IsIdle); + AddAssert("check idle", () => box1.IsIdle); AddAssert("check not idle", () => !box2.IsIdle); AddAssert("check idle", () => box3.IsIdle); AddAssert("check idle", () => box4.IsIdle); @@ -82,10 +82,10 @@ namespace osu.Game.Tests.Visual.Components AddStep("move mouse", () => InputManager.MoveMouseTo(box3.ScreenSpaceDrawQuad.Centre)); AddStep("move mouse", () => InputManager.MoveMouseTo(box4.ScreenSpaceDrawQuad.Centre)); - AddAssert("check not idle", () => box1.IsIdle); + AddAssert("check idle", () => box1.IsIdle); AddAssert("check not idle", () => !box2.IsIdle); - AddAssert("check idle", () => !box3.IsIdle); - AddAssert("check idle", () => !box4.IsIdle); + AddAssert("check not idle", () => !box3.IsIdle); + AddAssert("check not idle", () => !box4.IsIdle); AddUntilStep("Wait for all idle", () => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle); } From 35d9f5841c57a2fb4eb289aec86b8e7729b4434e Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 22 Jun 2019 17:34:06 +0200 Subject: [PATCH 2/3] simplify asserts, clarify asserts --- .../Visual/Components/TestSceneIdleTracker.cs | 77 +++++++++++++------ 1 file changed, 55 insertions(+), 22 deletions(-) diff --git a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs index 0e98206acb..0960e98fdc 100644 --- a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs +++ b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs @@ -25,6 +25,7 @@ namespace osu.Game.Tests.Visual.Components { box1 = new IdleTrackingBox(1000) { + Name = "TopLeft", RelativeSizeAxes = Axes.Both, Colour = Color4.Red, Anchor = Anchor.TopLeft, @@ -32,6 +33,7 @@ namespace osu.Game.Tests.Visual.Components }, box2 = new IdleTrackingBox(2000) { + Name = "TopRight", RelativeSizeAxes = Axes.Both, Colour = Color4.Green, Anchor = Anchor.TopRight, @@ -39,6 +41,7 @@ namespace osu.Game.Tests.Visual.Components }, box3 = new IdleTrackingBox(3000) { + Name = "BottomLeft", RelativeSizeAxes = Axes.Both, Colour = Color4.Blue, Anchor = Anchor.BottomLeft, @@ -46,6 +49,7 @@ namespace osu.Game.Tests.Visual.Components }, box4 = new IdleTrackingBox(4000) { + Name = "BottomRight", RelativeSizeAxes = Axes.Both, Colour = Color4.Orange, Anchor = Anchor.BottomRight, @@ -57,51 +61,80 @@ namespace osu.Game.Tests.Visual.Components [Test] public void TestNudge() { - AddStep("move mouse to top left", () => InputManager.MoveMouseTo(box1.ScreenSpaceDrawQuad.Centre)); + AddStep("move to top left", () => InputManager.MoveMouseTo(box1.ScreenSpaceDrawQuad.Centre)); - AddUntilStep("Wait for all idle", () => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle); + waitForAllIdle(); AddStep("nudge mouse", () => InputManager.MoveMouseTo(box1.ScreenSpaceDrawQuad.Centre + new Vector2(1))); - AddAssert("check not idle", () => !box1.IsIdle); - AddAssert("check idle", () => box2.IsIdle); - AddAssert("check idle", () => box3.IsIdle); - AddAssert("check idle", () => box4.IsIdle); + checkIdleStatus(box1, false); + checkIdleStatus(box2, true); + checkIdleStatus(box3, true); + checkIdleStatus(box4, true); } [Test] public void TestMovement() { - AddStep("move mouse", () => InputManager.MoveMouseTo(box2.ScreenSpaceDrawQuad.Centre)); + AddStep("move to top right", () => InputManager.MoveMouseTo(box2.ScreenSpaceDrawQuad.Centre)); - AddAssert("check idle", () => box1.IsIdle); - AddAssert("check not idle", () => !box2.IsIdle); - AddAssert("check idle", () => box3.IsIdle); - AddAssert("check idle", () => box4.IsIdle); + checkIdleStatus(box1, true); + checkIdleStatus(box2, false); + checkIdleStatus(box3, true); + checkIdleStatus(box4, true); - AddStep("move mouse", () => InputManager.MoveMouseTo(box3.ScreenSpaceDrawQuad.Centre)); - AddStep("move mouse", () => InputManager.MoveMouseTo(box4.ScreenSpaceDrawQuad.Centre)); + AddStep("move to bottom left", () => InputManager.MoveMouseTo(box3.ScreenSpaceDrawQuad.Centre)); + AddStep("move to bottom right", () => InputManager.MoveMouseTo(box4.ScreenSpaceDrawQuad.Centre)); - AddAssert("check idle", () => box1.IsIdle); - AddAssert("check not idle", () => !box2.IsIdle); - AddAssert("check not idle", () => !box3.IsIdle); - AddAssert("check not idle", () => !box4.IsIdle); + checkIdleStatus(box1, true); + checkIdleStatus(box2, false); + checkIdleStatus(box3, false); + checkIdleStatus(box4, false); - AddUntilStep("Wait for all idle", () => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle); + waitForAllIdle(); } [Test] public void TestTimings() { - AddStep("move mouse", () => InputManager.MoveMouseTo(ScreenSpaceDrawQuad.Centre)); + AddStep("move to centre", () => InputManager.MoveMouseTo(ScreenSpaceDrawQuad.Centre)); + + checkIdleStatus(box1, false); + checkIdleStatus(box2, false); + checkIdleStatus(box3, false); + checkIdleStatus(box4, false); - AddAssert("check not idle", () => !box1.IsIdle && !box2.IsIdle && !box3.IsIdle && !box4.IsIdle); AddUntilStep("Wait for idle", () => box1.IsIdle); - AddAssert("check not idle", () => !box2.IsIdle && !box3.IsIdle && !box4.IsIdle); + + checkIdleStatus(box1, true); + checkIdleStatus(box2, false); + checkIdleStatus(box3, false); + checkIdleStatus(box4, false); + AddUntilStep("Wait for idle", () => box2.IsIdle); - AddAssert("check not idle", () => !box3.IsIdle && !box4.IsIdle); + + checkIdleStatus(box1, true); + checkIdleStatus(box2, true); + checkIdleStatus(box3, false); + checkIdleStatus(box4, false); + AddUntilStep("Wait for idle", () => box3.IsIdle); + checkIdleStatus(box1, true); + checkIdleStatus(box2, true); + checkIdleStatus(box3, true); + checkIdleStatus(box4, false); + + waitForAllIdle(); + } + + private void checkIdleStatus(IdleTrackingBox box, bool expectedIdle) + { + AddAssert($"{box.Name} is {(expectedIdle ? "idle" : "active")}", () => box.IsIdle == expectedIdle); + } + + private void waitForAllIdle() + { AddUntilStep("Wait for all idle", () => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle); } From cf193cb26f83c1aeb1066f19af273fde555c0469 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 22 Jun 2019 17:43:24 +0200 Subject: [PATCH 3/3] call MoveMouseTo with Drawable --- .../Visual/Components/TestSceneIdleTracker.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs index 0960e98fdc..ef889e29a8 100644 --- a/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs +++ b/osu.Game.Tests/Visual/Components/TestSceneIdleTracker.cs @@ -61,7 +61,7 @@ namespace osu.Game.Tests.Visual.Components [Test] public void TestNudge() { - AddStep("move to top left", () => InputManager.MoveMouseTo(box1.ScreenSpaceDrawQuad.Centre)); + AddStep("move to top left", () => InputManager.MoveMouseTo(box1)); waitForAllIdle(); @@ -76,15 +76,15 @@ namespace osu.Game.Tests.Visual.Components [Test] public void TestMovement() { - AddStep("move to top right", () => InputManager.MoveMouseTo(box2.ScreenSpaceDrawQuad.Centre)); + AddStep("move to top right", () => InputManager.MoveMouseTo(box2)); checkIdleStatus(box1, true); checkIdleStatus(box2, false); checkIdleStatus(box3, true); checkIdleStatus(box4, true); - AddStep("move to bottom left", () => InputManager.MoveMouseTo(box3.ScreenSpaceDrawQuad.Centre)); - AddStep("move to bottom right", () => InputManager.MoveMouseTo(box4.ScreenSpaceDrawQuad.Centre)); + AddStep("move to bottom left", () => InputManager.MoveMouseTo(box3)); + AddStep("move to bottom right", () => InputManager.MoveMouseTo(box4)); checkIdleStatus(box1, true); checkIdleStatus(box2, false); @@ -97,7 +97,7 @@ namespace osu.Game.Tests.Visual.Components [Test] public void TestTimings() { - AddStep("move to centre", () => InputManager.MoveMouseTo(ScreenSpaceDrawQuad.Centre)); + AddStep("move to centre", () => InputManager.MoveMouseTo(Content)); checkIdleStatus(box1, false); checkIdleStatus(box2, false);