From 1d1b85551000586cda3aef40ea26d447242bd754 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 6 Dec 2023 11:57:04 +0900 Subject: [PATCH] Refactor test for readability --- .../Screens/TestSceneMapPoolScreen.cs | 47 +++++++------------ 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/osu.Game.Tournament.Tests/Screens/TestSceneMapPoolScreen.cs b/osu.Game.Tournament.Tests/Screens/TestSceneMapPoolScreen.cs index 2911ba6acb..dcf9dc47b9 100644 --- a/osu.Game.Tournament.Tests/Screens/TestSceneMapPoolScreen.cs +++ b/osu.Game.Tournament.Tests/Screens/TestSceneMapPoolScreen.cs @@ -169,44 +169,26 @@ public void TestPickBanOrder() AddStep("update displayed maps", () => Ladder.SplitMapPoolByMods.Value = false); AddStep("start bans from blue team", () => screen.ChildrenOfType().First(btn => btn.Text == "Blue Ban").TriggerClick()); + AddStep("ban map", () => clickBeatmapPanel(0)); - AddAssert("one ban registered", () => Ladder.CurrentMatch.Value!.PicksBans, () => Has.Count.EqualTo(1)); - AddAssert("ban was blue's", - () => Ladder.CurrentMatch.Value!.PicksBans.Count(pb => pb.Type == ChoiceType.Ban && pb.Team == TeamColour.Blue), - () => Is.EqualTo(1)); + checkTotalPickBans(1); + checkLastPick(ChoiceType.Ban, TeamColour.Blue); AddStep("ban map", () => clickBeatmapPanel(1)); - AddAssert("two bans registered", () => Ladder.CurrentMatch.Value!.PicksBans, () => Has.Count.EqualTo(2)); - AddAssert("one ban for red team", - () => Ladder.CurrentMatch.Value!.PicksBans.Count(pb => pb.Type == ChoiceType.Ban && pb.Team == TeamColour.Red), - () => Is.EqualTo(1)); - AddAssert("one ban for blue team", - () => Ladder.CurrentMatch.Value!.PicksBans.Count(pb => pb.Type == ChoiceType.Ban && pb.Team == TeamColour.Blue), - () => Is.EqualTo(1)); + checkTotalPickBans(2); + checkLastPick(ChoiceType.Ban, TeamColour.Red); AddStep("pick map", () => clickBeatmapPanel(2)); - AddAssert("one pick registered", - () => Ladder.CurrentMatch.Value!.PicksBans.Count(pb => pb.Type == ChoiceType.Pick), - () => Is.EqualTo(1)); - AddAssert("pick was red's", - () => Ladder.CurrentMatch.Value!.PicksBans.Last().Team, - () => Is.EqualTo(TeamColour.Red)); + checkTotalPickBans(3); + checkLastPick(ChoiceType.Pick, TeamColour.Red); AddStep("pick map", () => clickBeatmapPanel(3)); - AddAssert("two picks registered", - () => Ladder.CurrentMatch.Value!.PicksBans.Count(pb => pb.Type == ChoiceType.Pick), - () => Is.EqualTo(2)); - AddAssert("pick was blue's", - () => Ladder.CurrentMatch.Value!.PicksBans.Last().Team, - () => Is.EqualTo(TeamColour.Blue)); + checkTotalPickBans(4); + checkLastPick(ChoiceType.Pick, TeamColour.Blue); AddStep("pick map", () => clickBeatmapPanel(4)); - AddAssert("three picks registered", - () => Ladder.CurrentMatch.Value!.PicksBans.Count(pb => pb.Type == ChoiceType.Pick), - () => Is.EqualTo(3)); - AddAssert("pick was red's", - () => Ladder.CurrentMatch.Value!.PicksBans.Last().Team, - () => Is.EqualTo(TeamColour.Red)); + checkTotalPickBans(5); + checkLastPick(ChoiceType.Pick, TeamColour.Red); AddStep("reset match", () => { @@ -214,6 +196,13 @@ public void TestPickBanOrder() Ladder.CurrentMatch.Value = Ladder.Matches.First(); Ladder.CurrentMatch.Value.PicksBans.Clear(); }); + + void checkTotalPickBans(int expected) => AddAssert($"total pickbans is {expected}", () => Ladder.CurrentMatch.Value!.PicksBans, () => Has.Count.EqualTo(expected)); + + void checkLastPick(ChoiceType expectedChoice, TeamColour expectedColour) => + AddAssert($"last choice was {expectedChoice} by {expectedColour}", + () => Ladder.CurrentMatch.Value!.PicksBans.Select(pb => (pb.Type, pb.Team)).Last(), + () => Is.EqualTo((expectedChoice, expectedColour))); } [Test]