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
2022-06-17 15:37:17 +08:00
#nullable disable
2020-03-11 14:34:52 +08:00
using System.Linq ;
using NUnit.Framework ;
2018-10-16 14:20:12 +08:00
using osu.Framework.Allocation ;
2020-03-18 14:38:19 +08:00
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 ;
2018-11-06 13:49:09 +08:00
using osu.Game.Tournament.Screens.MapPool ;
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
{
2022-11-24 13:32:20 +08:00
public partial class TestSceneMapPoolScreen : TournamentTestScene
2018-10-14 17:09:22 +08:00
{
2020-03-11 14:34:52 +08:00
private MapPoolScreen screen ;
2018-11-08 05:29:04 +08:00
2018-10-16 14:20:12 +08:00
[BackgroundDependencyLoader]
private void load ( )
2018-10-14 17:09:22 +08:00
{
2020-03-11 14:34:52 +08:00
Add ( screen = new MapPoolScreen { Width = 0.7f } ) ;
}
2023-06-14 15:01:52 +08:00
[SetUp]
public void SetUp ( ) = > Schedule ( ( ) = > Ladder . SplitMapPoolByMods . Value = true ) ;
2020-03-11 14:34:52 +08:00
[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 ( ) ;
} ) ;
2020-03-18 14:38:19 +08:00
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 ( ) ;
for ( int i = 0 ; i < 18 ; i + + )
addBeatmap ( ) ;
} ) ;
AddStep ( "reset match" , ( ) = >
{
Ladder . CurrentMatch . Value = new TournamentMatch ( ) ;
Ladder . CurrentMatch . Value = Ladder . Matches . First ( ) ;
} ) ;
2020-03-18 14:38:19 +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-13 13:25:25 +08:00
for ( int i = 0 ; i < 19 ; i + + )
2020-03-11 14:34:52 +08:00
addBeatmap ( ) ;
} ) ;
AddStep ( "reset match" , ( ) = >
{
Ladder . CurrentMatch . Value = new TournamentMatch ( ) ;
Ladder . CurrentMatch . Value = Ladder . Matches . First ( ) ;
} ) ;
2020-03-18 14:38:19 +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 ( ) ;
for ( int i = 0 ; i < 11 ; i + + )
2023-06-14 14:58:39 +08:00
addBeatmap ( i > 4 ? Ruleset . Value . CreateInstance ( ) . AllMods . ElementAt ( i ) . Acronym : "NM" ) ;
2020-03-13 13:25:25 +08:00
} ) ;
AddStep ( "reset match" , ( ) = >
{
Ladder . CurrentMatch . Value = new TournamentMatch ( ) ;
Ladder . CurrentMatch . Value = Ladder . Matches . First ( ) ;
} ) ;
2020-03-18 14:38:19 +08:00
assertTwoWide ( ) ;
2020-03-13 13:25:25 +08:00
}
2020-03-18 14:38:19 +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-13 13:25:25 +08:00
for ( int i = 0 ; i < 12 ; i + + )
2023-06-14 14:58:39 +08:00
addBeatmap ( i > 4 ? Ruleset . Value . CreateInstance ( ) . AllMods . ElementAt ( i ) . Acronym : "NM" ) ;
2020-03-11 14:34:52 +08:00
} ) ;
AddStep ( "reset match" , ( ) = >
{
Ladder . CurrentMatch . Value = new TournamentMatch ( ) ;
Ladder . CurrentMatch . Value = Ladder . Matches . First ( ) ;
} ) ;
2020-03-18 14:38:19 +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 ( ) ;
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
AddStep ( "reset match" , ( ) = >
{
Ladder . CurrentMatch . Value = new TournamentMatch ( ) ;
Ladder . CurrentMatch . Value = Ladder . Matches . First ( ) ;
} ) ;
}
2023-06-14 14:58:39 +08:00
private void addBeatmap ( string mods = "NM" )
2020-03-11 14:34:52 +08:00
{
Ladder . CurrentMatch . Value . Round . Value . Beatmaps . Add ( new RoundBeatmap
{
2021-10-27 17:25:23 +08:00
Beatmap = CreateSampleBeatmap ( ) ,
2020-03-11 14:34:52 +08:00
Mods = mods
} ) ;
2018-10-14 17:09:22 +08:00
}
}
}