1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 13:37:25 +08:00
osu-lazer/osu.Game.Tournament.Tests/Screens/TestSceneMapPoolScreen.cs
Bartłomiej Dach 2c7db61a5c
Improve test
2023-12-05 21:19:35 +01:00

326 lines
12 KiB
C#

// 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.
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Game.Tournament.Components;
using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.MapPool;
namespace osu.Game.Tournament.Tests.Screens
{
public partial class TestSceneMapPoolScreen : TournamentScreenTestScene
{
private MapPoolScreen screen = null!;
[BackgroundDependencyLoader]
private void load()
{
Add(screen = new MapPoolScreen { Width = 0.7f });
}
[SetUp]
public void SetUp() => Schedule(() => Ladder.SplitMapPoolByMods.Value = true);
[Test]
public void TestFewMaps()
{
AddStep("load few maps", () =>
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Clear();
for (int i = 0; i < 8; i++)
addBeatmap();
});
AddStep("reset match", () =>
{
Ladder.CurrentMatch.Value = new TournamentMatch();
Ladder.CurrentMatch.Value = Ladder.Matches.First();
});
assertTwoWide();
}
[Test]
public void TestJustEnoughMaps()
{
AddStep("load just enough maps", () =>
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Clear();
for (int i = 0; i < 18; i++)
addBeatmap();
});
AddStep("reset match", () =>
{
Ladder.CurrentMatch.Value = new TournamentMatch();
Ladder.CurrentMatch.Value = Ladder.Matches.First();
});
assertTwoWide();
}
[Test]
public void TestManyMaps()
{
AddStep("load many maps", () =>
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Clear();
for (int i = 0; i < 19; i++)
addBeatmap();
});
AddStep("reset match", () =>
{
Ladder.CurrentMatch.Value = new TournamentMatch();
Ladder.CurrentMatch.Value = Ladder.Matches.First();
});
assertThreeWide();
}
[Test]
public void TestJustEnoughMods()
{
AddStep("load many maps", () =>
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Clear();
for (int i = 0; i < 11; i++)
addBeatmap(i > 4 ? Ruleset.Value.CreateInstance().AllMods.ElementAt(i).Acronym : "NM");
});
AddStep("reset match", () =>
{
Ladder.CurrentMatch.Value = new TournamentMatch();
Ladder.CurrentMatch.Value = Ladder.Matches.First();
});
assertTwoWide();
}
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);
[Test]
public void TestManyMods()
{
AddStep("load many maps", () =>
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Clear();
for (int i = 0; i < 12; i++)
addBeatmap(i > 4 ? Ruleset.Value.CreateInstance().AllMods.ElementAt(i).Acronym : "NM");
});
AddStep("reset match", () =>
{
Ladder.CurrentMatch.Value = new TournamentMatch();
Ladder.CurrentMatch.Value = Ladder.Matches.First();
});
assertThreeWide();
}
[Test]
public void TestSplitMapPoolByMods()
{
AddStep("load many maps", () =>
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Clear();
for (int i = 0; i < 12; i++)
addBeatmap(i > 4 ? Ruleset.Value.CreateInstance().AllMods.ElementAt(i).Acronym : "NM");
});
AddStep("disable splitting map pool by mods", () => Ladder.SplitMapPoolByMods.Value = false);
AddStep("reset match", () =>
{
Ladder.CurrentMatch.Value = new TournamentMatch();
Ladder.CurrentMatch.Value = Ladder.Matches.First();
});
}
[Test]
public void TestSingleTeamBan()
{
AddStep("set ban count", () => Ladder.CurrentMatch.Value!.Round.Value!.BanCount.Value = 1);
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));
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));
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));
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));
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));
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));
AddStep("reset match", () =>
{
InputManager.UseParentInput = true;
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);
AddStep("start bans with red team", () => screen.ChildrenOfType<TourneyButton>().First(btn => btn.Text == "Red Ban").TriggerClick());
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));
AddStep("ban two more maps", () =>
{
clickBeatmapPanel(1);
clickBeatmapPanel(2);
});
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));
AddStep("ban two more maps", () =>
{
clickBeatmapPanel(3);
clickBeatmapPanel(4);
});
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", () =>
{
InputManager.UseParentInput = true;
Ladder.CurrentMatch.Value = new TournamentMatch();
Ladder.CurrentMatch.Value = Ladder.Matches.First();
Ladder.CurrentMatch.Value.PicksBans.Clear();
});
}
private void addBeatmap(string mods = "NM")
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Add(new RoundBeatmap
{
Beatmap = CreateSampleBeatmap(),
Mods = mods
});
}
private void clickBeatmapPanel(int index)
{
InputManager.MoveMouseTo(screen.ChildrenOfType<TournamentBeatmapPanel>().ElementAt(index));
InputManager.Click(osuTK.Input.MouseButton.Left);
}
}
}