osu/osu.Game.Tournament.Tests/Screens/TestSceneMapPoolScreen.cs

141 lines
4.0 KiB
C#
Raw Normal View History

2019-03-04 04:24:19 +00: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 09:09:22 +00:00
2020-03-11 06:34:52 +00:00
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
2020-03-11 06:34:52 +00:00
using osu.Framework.Testing;
using osu.Game.Tournament.Components;
using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.MapPool;
2018-10-14 09:09:22 +00:00
2019-06-18 06:28:36 +00:00
namespace osu.Game.Tournament.Tests.Screens
2018-10-14 09:09:22 +00:00
{
public class TestSceneMapPoolScreen : TournamentTestScene
2018-10-14 09:09:22 +00:00
{
2020-03-11 06:34:52 +00:00
private MapPoolScreen screen;
2018-11-07 21:29:04 +00:00
[BackgroundDependencyLoader]
private void load()
2018-10-14 09:09:22 +00:00
{
2020-03-11 06:34:52 +00:00
Add(screen = new MapPoolScreen { Width = 0.7f });
}
[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();
2020-03-11 06:34:52 +00:00
}
2020-03-13 05:25:25 +00:00
[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();
2020-03-13 05:25:25 +00:00
}
2020-03-11 06:34:52 +00:00
[Test]
public void TestManyMaps()
{
AddStep("load many maps", () =>
{
Ladder.CurrentMatch.Value.Round.Value.Beatmaps.Clear();
2020-03-13 05:25:25 +00:00
for (int i = 0; i < 19; i++)
2020-03-11 06:34:52 +00:00
addBeatmap();
});
AddStep("reset match", () =>
{
Ladder.CurrentMatch.Value = new TournamentMatch();
Ladder.CurrentMatch.Value = Ladder.Matches.First();
});
assertThreeWide();
2020-03-11 06:34:52 +00:00
}
2020-03-13 05:25:25 +00:00
[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 ? $"M{i}" : "NM");
});
AddStep("reset match", () =>
{
Ladder.CurrentMatch.Value = new TournamentMatch();
Ladder.CurrentMatch.Value = Ladder.Matches.First();
});
assertTwoWide();
2020-03-13 05:25:25 +00: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 06:34:52 +00:00
[Test]
public void TestManyMods()
{
AddStep("load many maps", () =>
{
Ladder.CurrentMatch.Value.Round.Value.Beatmaps.Clear();
2020-03-13 05:25:25 +00:00
for (int i = 0; i < 12; i++)
addBeatmap(i > 4 ? $"M{i}" : "NM");
2020-03-11 06:34:52 +00:00
});
AddStep("reset match", () =>
{
Ladder.CurrentMatch.Value = new TournamentMatch();
Ladder.CurrentMatch.Value = Ladder.Matches.First();
});
assertThreeWide();
2020-03-11 06:34:52 +00:00
}
private void addBeatmap(string mods = "nm")
{
Ladder.CurrentMatch.Value.Round.Value.Beatmaps.Add(new RoundBeatmap
{
BeatmapInfo = CreateSampleBeatmapInfo(),
Mods = mods
});
2018-10-14 09:09:22 +00:00
}
}
}