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 ;
2018-10-16 06:20:12 +00:00
using osu.Framework.Allocation ;
2020-03-18 06:38:19 +00:00
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 ;
2018-11-06 05:49:09 +00:00
using osu.Game.Tournament.Screens.MapPool ;
2023-12-05 20:49:04 +00:00
using osuTK ;
2023-12-05 20:49:32 +00:00
using osuTK.Input ;
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
{
2023-07-24 09:22:32 +00:00
public partial class TestSceneMapPoolScreen : TournamentScreenTestScene
2018-10-14 09:09:22 +00:00
{
2023-07-29 13:41:26 +00:00
private MapPoolScreen screen = null ! ;
2018-11-07 21:29:04 +00:00
2018-10-16 06:20:12 +00:00
[BackgroundDependencyLoader]
private void load ( )
2018-10-14 09:09:22 +00:00
{
2023-12-05 20:49:04 +00:00
Add ( screen = new TestMapPoolScreen { Width = 0.7f } ) ;
2020-03-11 06:34:52 +00:00
}
2023-12-06 03:03:54 +00:00
[SetUpSteps]
public override void SetUpSteps ( )
{
AddStep ( "reset state" , resetState ) ;
}
private void resetState ( )
2023-12-06 03:00:32 +00:00
{
Ladder . SplitMapPoolByMods . Value = true ;
Ladder . CurrentMatch . Value = new TournamentMatch ( ) ;
Ladder . CurrentMatch . Value = Ladder . Matches . First ( ) ;
Ladder . CurrentMatch . Value . PicksBans . Clear ( ) ;
2023-12-06 03:03:54 +00:00
}
[SetUp]
public void SetUp ( ) = > Schedule ( ( ) = >
{
2023-12-06 03:00:32 +00:00
} ) ;
2023-06-14 07:01:52 +00:00
2020-03-11 06:34:52 +00:00
[Test]
public void TestFewMaps ( )
{
AddStep ( "load few maps" , ( ) = >
{
2023-08-09 15:20:37 +00:00
Ladder . CurrentMatch . Value ! . Round . Value ! . Beatmaps . Clear ( ) ;
2020-03-11 06:34:52 +00:00
for ( int i = 0 ; i < 8 ; i + + )
addBeatmap ( ) ;
} ) ;
AddStep ( "reset match" , ( ) = >
{
Ladder . CurrentMatch . Value = new TournamentMatch ( ) ;
} ) ;
2020-03-18 06:38:19 +00:00
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" , ( ) = >
{
2023-08-09 15:20:37 +00:00
Ladder . CurrentMatch . Value ! . Round . Value ! . Beatmaps . Clear ( ) ;
2020-03-13 05:25:25 +00:00
for ( int i = 0 ; i < 18 ; i + + )
addBeatmap ( ) ;
} ) ;
2023-12-06 03:03:54 +00:00
AddStep ( "reset state" , resetState ) ;
2020-03-13 05:25:25 +00:00
2020-03-18 06:38:19 +00:00
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" , ( ) = >
{
2023-08-09 15:20:37 +00:00
Ladder . CurrentMatch . Value ! . Round . Value ! . Beatmaps . Clear ( ) ;
2020-03-11 06:34:52 +00:00
2020-03-13 05:25:25 +00:00
for ( int i = 0 ; i < 19 ; i + + )
2020-03-11 06:34:52 +00:00
addBeatmap ( ) ;
} ) ;
2023-12-06 03:03:54 +00:00
AddStep ( "reset state" , resetState ) ;
2020-03-11 06:34:52 +00:00
2020-03-18 06:38:19 +00:00
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" , ( ) = >
{
2023-08-09 15:20:37 +00:00
Ladder . CurrentMatch . Value ! . Round . Value ! . Beatmaps . Clear ( ) ;
2020-03-13 05:25:25 +00:00
for ( int i = 0 ; i < 11 ; i + + )
2023-06-14 06:58:39 +00:00
addBeatmap ( i > 4 ? Ruleset . Value . CreateInstance ( ) . AllMods . ElementAt ( i ) . Acronym : "NM" ) ;
2020-03-13 05:25:25 +00:00
} ) ;
2023-12-06 03:03:54 +00:00
AddStep ( "reset state" , resetState ) ;
2020-03-13 05:25:25 +00:00
2020-03-18 06:38:19 +00:00
assertTwoWide ( ) ;
2020-03-13 05:25:25 +00:00
}
2020-03-18 06:38:19 +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" , ( ) = >
{
2023-08-09 15:20:37 +00:00
Ladder . CurrentMatch . Value ! . Round . Value ! . Beatmaps . Clear ( ) ;
2020-03-11 06:34:52 +00:00
2020-03-13 05:25:25 +00:00
for ( int i = 0 ; i < 12 ; i + + )
2023-06-14 06:58:39 +00:00
addBeatmap ( i > 4 ? Ruleset . Value . CreateInstance ( ) . AllMods . ElementAt ( i ) . Acronym : "NM" ) ;
2020-03-11 06:34:52 +00:00
} ) ;
2023-12-06 03:03:54 +00:00
AddStep ( "reset state" , resetState ) ;
2020-03-11 06:34:52 +00:00
2020-03-18 06:38:19 +00:00
assertThreeWide ( ) ;
2020-03-11 06:34:52 +00:00
}
2023-06-14 07:01:52 +00:00
[Test]
2023-06-14 19:33:11 +00:00
public void TestSplitMapPoolByMods ( )
2023-06-14 07:01:52 +00:00
{
AddStep ( "load many maps" , ( ) = >
{
2023-08-09 15:20:37 +00:00
Ladder . CurrentMatch . Value ! . Round . Value ! . Beatmaps . Clear ( ) ;
2023-06-14 07:01:52 +00:00
for ( int i = 0 ; i < 12 ; i + + )
addBeatmap ( i > 4 ? Ruleset . Value . CreateInstance ( ) . AllMods . ElementAt ( i ) . Acronym : "NM" ) ;
} ) ;
2023-06-14 19:33:11 +00:00
AddStep ( "disable splitting map pool by mods" , ( ) = > Ladder . SplitMapPoolByMods . Value = false ) ;
2023-06-14 07:01:52 +00:00
2023-12-06 03:03:54 +00:00
AddStep ( "reset state" , resetState ) ;
2023-06-14 07:01:52 +00:00
}
2023-12-06 03:00:32 +00: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 ) ;
}
2023-12-05 12:56:24 +00:00
[Test]
2023-12-06 02:50:43 +00:00
public void TestPickBanOrder ( )
2023-12-05 12:56:24 +00:00
{
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-05 20:19:35 +00:00
for ( int i = 0 ; i < 5 ; i + + )
2023-12-05 12:56:24 +00:00
addBeatmap ( ) ;
} ) ;
AddStep ( "update displayed maps" , ( ) = > Ladder . SplitMapPoolByMods . Value = false ) ;
2023-12-05 20:19:35 +00:00
AddStep ( "start bans from blue team" , ( ) = > screen . ChildrenOfType < TourneyButton > ( ) . First ( btn = > btn . Text = = "Blue Ban" ) . TriggerClick ( ) ) ;
2023-12-06 02:57:04 +00:00
2023-12-05 20:19:35 +00:00
AddStep ( "ban map" , ( ) = > clickBeatmapPanel ( 0 ) ) ;
2023-12-06 02:57:04 +00:00
checkTotalPickBans ( 1 ) ;
checkLastPick ( ChoiceType . Ban , TeamColour . Blue ) ;
2023-12-05 20:19:35 +00:00
AddStep ( "ban map" , ( ) = > clickBeatmapPanel ( 1 ) ) ;
2023-12-06 02:57:04 +00:00
checkTotalPickBans ( 2 ) ;
checkLastPick ( ChoiceType . Ban , TeamColour . Red ) ;
2023-12-05 20:19:35 +00:00
AddStep ( "pick map" , ( ) = > clickBeatmapPanel ( 2 ) ) ;
2023-12-06 02:57:04 +00:00
checkTotalPickBans ( 3 ) ;
checkLastPick ( ChoiceType . Pick , TeamColour . Red ) ;
2023-12-05 20:19:35 +00:00
AddStep ( "pick map" , ( ) = > clickBeatmapPanel ( 3 ) ) ;
2023-12-06 02:57:04 +00:00
checkTotalPickBans ( 4 ) ;
checkLastPick ( ChoiceType . Pick , TeamColour . Blue ) ;
2023-12-05 20:19:35 +00:00
AddStep ( "pick map" , ( ) = > clickBeatmapPanel ( 4 ) ) ;
2023-12-06 02:57:04 +00:00
checkTotalPickBans ( 5 ) ;
checkLastPick ( ChoiceType . Pick , TeamColour . Red ) ;
2023-12-05 12:56:24 +00:00
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-05 20:19:35 +00:00
AddStep ( "start bans with red team" , ( ) = > screen . ChildrenOfType < TourneyButton > ( ) . First ( btn = > btn . Text = = "Red Ban" ) . TriggerClick ( ) ) ;
2023-12-05 12:56:24 +00:00
2023-12-05 20:19:35 +00: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-05 12:56:24 +00:00
2023-12-05 20:19:35 +00:00
AddStep ( "ban two more maps" , ( ) = >
2023-12-05 12:56:24 +00:00
{
2023-12-05 20:19:35 +00:00
clickBeatmapPanel ( 1 ) ;
clickBeatmapPanel ( 2 ) ;
2023-12-05 12:56:24 +00:00
} ) ;
2023-12-05 20:19:35 +00: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-05 12:56:24 +00:00
2023-12-05 20:19:35 +00:00
AddStep ( "ban two more maps" , ( ) = >
2023-12-05 12:56:24 +00:00
{
2023-12-05 20:19:35 +00:00
clickBeatmapPanel ( 3 ) ;
clickBeatmapPanel ( 4 ) ;
2023-12-05 12:56:24 +00:00
} ) ;
2023-12-05 20:19:35 +00: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 ) ) ;
2023-12-05 12:56:24 +00:00
AddStep ( "reset match" , ( ) = >
{
Ladder . CurrentMatch . Value = new TournamentMatch ( ) ;
Ladder . CurrentMatch . Value = Ladder . Matches . First ( ) ;
Ladder . CurrentMatch . Value . PicksBans . Clear ( ) ;
} ) ;
}
2023-12-05 20:19:35 +00:00
2023-12-06 03:00:32 +00: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 ) ) ) ;
2023-06-14 06:58:39 +00:00
private void addBeatmap ( string mods = "NM" )
2020-03-11 06:34:52 +00:00
{
2023-08-09 15:20:37 +00:00
Ladder . CurrentMatch . Value ! . Round . Value ! . Beatmaps . Add ( new RoundBeatmap
2020-03-11 06:34:52 +00:00
{
2021-10-27 09:25:23 +00:00
Beatmap = CreateSampleBeatmap ( ) ,
2020-03-11 06:34:52 +00:00
Mods = mods
} ) ;
2018-10-14 09:09:22 +00:00
}
2023-12-05 12:56:24 +00:00
2023-12-05 20:19:35 +00:00
private void clickBeatmapPanel ( int index )
2023-12-05 12:56:24 +00:00
{
2023-12-05 20:19:35 +00:00
InputManager . MoveMouseTo ( screen . ChildrenOfType < TournamentBeatmapPanel > ( ) . ElementAt ( index ) ) ;
2023-12-05 20:49:32 +00:00
InputManager . Click ( MouseButton . Left ) ;
2023-12-05 12:56:24 +00:00
}
2023-12-05 20:49:04 +00:00
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 09:09:22 +00:00
}
}