1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 02:17:46 +08:00
osu-lazer/osu.Game.Tournament.Tests/Screens/TestSceneMapPoolScreen.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

360 lines
13 KiB
C#
Raw Normal View History

2019-03-04 12:24:19 +08:00
// 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.
2018-10-14 17:09:22 +08:00
2020-03-11 14:34:52 +08:00
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
2020-03-11 14:34:52 +08:00
using osu.Framework.Testing;
using osu.Game.Tournament.Components;
using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.MapPool;
using osuTK;
using osuTK.Input;
2018-10-14 17:09:22 +08:00
2019-06-18 14:28:36 +08:00
namespace osu.Game.Tournament.Tests.Screens
2018-10-14 17:09:22 +08:00
{
public partial class TestSceneMapPoolScreen : TournamentScreenTestScene
2018-10-14 17:09:22 +08:00
{
2023-07-29 21:41:26 +08:00
private MapPoolScreen screen = null!;
2018-11-08 05:29:04 +08:00
[BackgroundDependencyLoader]
private void load()
2018-10-14 17:09:22 +08:00
{
Add(screen = new TestMapPoolScreen { Width = 0.7f });
2020-03-11 14:34:52 +08:00
}
2023-12-06 11:03:54 +08:00
[SetUpSteps]
public override void SetUpSteps()
{
AddStep("reset state", resetState);
}
private void resetState()
{
Ladder.SplitMapPoolByMods.Value = true;
Ladder.CurrentMatch.Value = new TournamentMatch();
Ladder.CurrentMatch.Value = Ladder.Matches.First();
Ladder.CurrentMatch.Value.PicksBans.Clear();
2023-12-06 11:03:54 +08:00
}
[SetUp]
public void SetUp() => Schedule(() =>
{
});
2023-06-14 15:01:52 +08:00
2020-03-11 14:34:52 +08:00
[Test]
public void TestFewMaps()
{
AddStep("load few maps", () =>
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Clear();
2020-03-11 14:34:52 +08:00
for (int i = 0; i < 8; i++)
addBeatmap();
});
AddStep("reset match", () =>
{
Ladder.CurrentMatch.Value = new TournamentMatch();
});
assertTwoWide();
2020-03-11 14:34:52 +08:00
}
2020-03-13 13:25:25 +08:00
[Test]
public void TestJustEnoughMaps()
{
AddStep("load just enough maps", () =>
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Clear();
2020-03-13 13:25:25 +08:00
for (int i = 0; i < 18; i++)
addBeatmap();
});
2023-12-06 11:03:54 +08:00
AddStep("reset state", resetState);
2020-03-13 13:25:25 +08:00
assertTwoWide();
2020-03-13 13:25:25 +08:00
}
2020-03-11 14:34:52 +08:00
[Test]
public void TestManyMaps()
{
AddStep("load many maps", () =>
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Clear();
2020-03-11 14:34:52 +08:00
2020-03-13 13:25:25 +08:00
for (int i = 0; i < 19; i++)
2020-03-11 14:34:52 +08:00
addBeatmap();
});
2023-12-06 11:03:54 +08:00
AddStep("reset state", resetState);
2020-03-11 14:34:52 +08:00
assertThreeWide();
2020-03-11 14:34:52 +08:00
}
2020-03-13 13:25:25 +08:00
[Test]
public void TestJustEnoughMods()
{
AddStep("load many maps", () =>
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Clear();
2020-03-13 13:25:25 +08:00
for (int i = 0; i < 11; i++)
addBeatmap(i > 4 ? Ruleset.Value.CreateInstance().AllMods.ElementAt(i).Acronym : "NM");
2020-03-13 13:25:25 +08:00
});
2023-12-06 11:03:54 +08:00
AddStep("reset state", resetState);
2020-03-13 13:25:25 +08:00
assertTwoWide();
2020-03-13 13:25:25 +08:00
}
private void assertTwoWide() =>
AddAssert("ensure layout width is 2", () => screen.ChildrenOfType<FillFlowContainer<FillFlowContainer<TournamentBeatmapPanel>>>().First().Padding.Left > 0);
private void assertThreeWide() =>
AddAssert("ensure layout width is 3", () => screen.ChildrenOfType<FillFlowContainer<FillFlowContainer<TournamentBeatmapPanel>>>().First().Padding.Left == 0);
2020-03-11 14:34:52 +08:00
[Test]
public void TestManyMods()
{
AddStep("load many maps", () =>
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Clear();
2020-03-11 14:34:52 +08:00
2020-03-13 13:25:25 +08:00
for (int i = 0; i < 12; i++)
addBeatmap(i > 4 ? Ruleset.Value.CreateInstance().AllMods.ElementAt(i).Acronym : "NM");
2020-03-11 14:34:52 +08:00
});
2023-12-06 11:03:54 +08:00
AddStep("reset state", resetState);
2020-03-11 14:34:52 +08:00
assertThreeWide();
2020-03-11 14:34:52 +08:00
}
2023-06-14 15:01:52 +08:00
[Test]
2023-06-15 03:33:11 +08:00
public void TestSplitMapPoolByMods()
2023-06-14 15:01:52 +08:00
{
AddStep("load many maps", () =>
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Clear();
2023-06-14 15:01:52 +08:00
for (int i = 0; i < 12; i++)
addBeatmap(i > 4 ? Ruleset.Value.CreateInstance().AllMods.ElementAt(i).Acronym : "NM");
});
2023-06-15 03:33:11 +08:00
AddStep("disable splitting map pool by mods", () => Ladder.SplitMapPoolByMods.Value = false);
2023-06-14 15:01:52 +08:00
2023-12-06 11:03:54 +08:00
AddStep("reset state", resetState);
2023-06-14 15:01:52 +08:00
}
[Test]
public void TestBanOrderMultipleBans()
{
AddStep("set ban count", () => Ladder.CurrentMatch.Value!.Round.Value!.BanCount.Value = 2);
AddStep("load some maps", () =>
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Clear();
for (int i = 0; i < 5; i++)
addBeatmap();
});
AddStep("update displayed maps", () => Ladder.SplitMapPoolByMods.Value = false);
AddStep("start bans from blue team", () => screen.ChildrenOfType<TourneyButton>().First(btn => btn.Text == "Blue Ban").TriggerClick());
AddStep("ban map", () => clickBeatmapPanel(0));
checkTotalPickBans(1);
checkLastPick(ChoiceType.Ban, TeamColour.Blue);
AddStep("ban map", () => clickBeatmapPanel(1));
checkTotalPickBans(2);
checkLastPick(ChoiceType.Ban, TeamColour.Red);
AddStep("ban map", () => clickBeatmapPanel(2));
checkTotalPickBans(3);
checkLastPick(ChoiceType.Ban, TeamColour.Red);
AddStep("pick map", () => clickBeatmapPanel(3));
checkTotalPickBans(4);
checkLastPick(ChoiceType.Ban, TeamColour.Blue);
AddStep("pick map", () => clickBeatmapPanel(4));
checkTotalPickBans(5);
checkLastPick(ChoiceType.Pick, TeamColour.Blue);
}
[Test]
2023-12-06 10:50:43 +08:00
public void TestPickBanOrder()
{
AddStep("set ban count", () => Ladder.CurrentMatch.Value!.Round.Value!.BanCount.Value = 1);
AddStep("load some maps", () =>
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Clear();
2023-12-06 04:19:35 +08:00
for (int i = 0; i < 5; i++)
addBeatmap();
});
AddStep("update displayed maps", () => Ladder.SplitMapPoolByMods.Value = false);
2023-12-06 04:19:35 +08:00
AddStep("start bans from blue team", () => screen.ChildrenOfType<TourneyButton>().First(btn => btn.Text == "Blue Ban").TriggerClick());
2023-12-06 10:57:04 +08:00
2023-12-06 04:19:35 +08:00
AddStep("ban map", () => clickBeatmapPanel(0));
2023-12-06 10:57:04 +08:00
checkTotalPickBans(1);
checkLastPick(ChoiceType.Ban, TeamColour.Blue);
2023-12-06 04:19:35 +08:00
AddStep("ban map", () => clickBeatmapPanel(1));
2023-12-06 10:57:04 +08:00
checkTotalPickBans(2);
checkLastPick(ChoiceType.Ban, TeamColour.Red);
2023-12-06 04:19:35 +08:00
AddStep("pick map", () => clickBeatmapPanel(2));
2023-12-06 10:57:04 +08:00
checkTotalPickBans(3);
checkLastPick(ChoiceType.Pick, TeamColour.Red);
2023-12-06 04:19:35 +08:00
AddStep("pick map", () => clickBeatmapPanel(3));
2023-12-06 10:57:04 +08:00
checkTotalPickBans(4);
checkLastPick(ChoiceType.Pick, TeamColour.Blue);
2023-12-06 04:19:35 +08:00
AddStep("pick map", () => clickBeatmapPanel(4));
2023-12-06 10:57:04 +08:00
checkTotalPickBans(5);
checkLastPick(ChoiceType.Pick, TeamColour.Red);
AddStep("reset match", () =>
{
Ladder.CurrentMatch.Value = new TournamentMatch();
Ladder.CurrentMatch.Value = Ladder.Matches.First();
Ladder.CurrentMatch.Value.PicksBans.Clear();
});
}
[Test]
public void TestMultipleTeamBans()
{
AddStep("set ban count", () => Ladder.CurrentMatch.Value!.Round.Value!.BanCount.Value = 3);
AddStep("load some maps", () =>
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Clear();
for (int i = 0; i < 12; i++)
addBeatmap();
});
AddStep("update displayed maps", () => Ladder.SplitMapPoolByMods.Value = false);
2023-12-06 04:19:35 +08:00
AddStep("start bans with red team", () => screen.ChildrenOfType<TourneyButton>().First(btn => btn.Text == "Red Ban").TriggerClick());
2023-12-06 04:19:35 +08:00
AddStep("first ban", () => clickBeatmapPanel(0));
AddAssert("red ban registered",
() => Ladder.CurrentMatch.Value!.PicksBans.Count(pb => pb.Type == ChoiceType.Ban && pb.Team == TeamColour.Red),
() => Is.EqualTo(1));
2023-12-06 04:19:35 +08:00
AddStep("ban two more maps", () =>
{
2023-12-06 04:19:35 +08:00
clickBeatmapPanel(1);
clickBeatmapPanel(2);
});
2023-12-06 04:19:35 +08:00
AddAssert("three bans registered",
() => Ladder.CurrentMatch.Value!.PicksBans.Count(pb => pb.Type == ChoiceType.Ban),
() => Is.EqualTo(3));
AddAssert("both new bans for blue team",
() => Ladder.CurrentMatch.Value!.PicksBans.Count(pb => pb.Type == ChoiceType.Ban && pb.Team == TeamColour.Blue),
() => Is.EqualTo(2));
2023-12-06 04:19:35 +08:00
AddStep("ban two more maps", () =>
{
2023-12-06 04:19:35 +08:00
clickBeatmapPanel(3);
clickBeatmapPanel(4);
});
2023-12-06 04:19:35 +08:00
AddAssert("five bans registered",
() => Ladder.CurrentMatch.Value!.PicksBans.Count(pb => pb.Type == ChoiceType.Ban),
() => Is.EqualTo(5));
AddAssert("both new bans for red team",
() => Ladder.CurrentMatch.Value!.PicksBans.Count(pb => pb.Type == ChoiceType.Ban && pb.Team == TeamColour.Red),
() => Is.EqualTo(3));
AddStep("ban last map", () => clickBeatmapPanel(5));
AddAssert("six bans registered",
() => Ladder.CurrentMatch.Value!.PicksBans.Count(pb => pb.Type == ChoiceType.Ban),
() => Is.EqualTo(6));
AddAssert("red banned three",
() => Ladder.CurrentMatch.Value!.PicksBans.Count(pb => pb.Type == ChoiceType.Ban && pb.Team == TeamColour.Red),
() => Is.EqualTo(3));
AddAssert("blue banned three",
() => Ladder.CurrentMatch.Value!.PicksBans.Count(pb => pb.Type == ChoiceType.Ban && pb.Team == TeamColour.Blue),
() => Is.EqualTo(3));
AddStep("pick map", () => clickBeatmapPanel(6));
AddAssert("one pick registered",
() => Ladder.CurrentMatch.Value!.PicksBans.Count(pb => pb.Type == ChoiceType.Pick),
() => Is.EqualTo(1));
AddAssert("pick was blue's",
() => Ladder.CurrentMatch.Value!.PicksBans.Last().Team,
() => Is.EqualTo(TeamColour.Blue));
AddStep("pick map", () => clickBeatmapPanel(7));
AddAssert("two picks registered",
() => Ladder.CurrentMatch.Value!.PicksBans.Count(pb => pb.Type == ChoiceType.Pick),
() => Is.EqualTo(2));
AddAssert("pick was red's",
() => Ladder.CurrentMatch.Value!.PicksBans.Last().Team,
() => Is.EqualTo(TeamColour.Red));
AddStep("pick map", () => clickBeatmapPanel(8));
AddAssert("three picks registered",
() => Ladder.CurrentMatch.Value!.PicksBans.Count(pb => pb.Type == ChoiceType.Pick),
() => Is.EqualTo(3));
AddAssert("pick was blue's",
() => Ladder.CurrentMatch.Value!.PicksBans.Last().Team,
() => Is.EqualTo(TeamColour.Blue));
AddStep("reset match", () =>
{
Ladder.CurrentMatch.Value = new TournamentMatch();
Ladder.CurrentMatch.Value = Ladder.Matches.First();
Ladder.CurrentMatch.Value.PicksBans.Clear();
});
}
2023-12-06 04:19:35 +08:00
private void checkTotalPickBans(int expected) => AddAssert($"total pickbans is {expected}", () => Ladder.CurrentMatch.Value!.PicksBans, () => Has.Count.EqualTo(expected));
private 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)));
private void addBeatmap(string mods = "NM")
2020-03-11 14:34:52 +08:00
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Add(new RoundBeatmap
2020-03-11 14:34:52 +08:00
{
Beatmap = CreateSampleBeatmap(),
2020-03-11 14:34:52 +08:00
Mods = mods
});
2018-10-14 17:09:22 +08:00
}
2023-12-06 04:19:35 +08:00
private void clickBeatmapPanel(int index)
{
2023-12-06 04:19:35 +08:00
InputManager.MoveMouseTo(screen.ChildrenOfType<TournamentBeatmapPanel>().ElementAt(index));
InputManager.Click(MouseButton.Left);
}
private partial class TestMapPoolScreen : MapPoolScreen
{
// this is a bit of a test-specific workaround.
// the way pick/ban is implemented is a bit funky; the screen itself is what handles the mouse there,
// rather than the beatmap panels themselves.
// in some extreme situations headless it may turn out that the panels overflow the screen,
// and as such picking stops working anymore outside of the bounds of the screen drawable.
// this override makes it so the screen sees all of the input at all times, making that impossible to happen.
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
}
2018-10-14 17:09:22 +08:00
}
}