mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 18:42:56 +08:00
Add tests (wip)
This commit is contained in:
parent
ef0acde458
commit
fbb7e9f12a
@ -3,7 +3,10 @@
|
|||||||
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Utils;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Tournament.Models;
|
using osu.Game.Tournament.Models;
|
||||||
|
using osu.Game.Users;
|
||||||
|
|
||||||
namespace osu.Game.Tournament.Tests
|
namespace osu.Game.Tournament.Tests
|
||||||
{
|
{
|
||||||
@ -12,5 +15,124 @@ namespace osu.Game.Tournament.Tests
|
|||||||
{
|
{
|
||||||
[Resolved]
|
[Resolved]
|
||||||
protected LadderInfo Ladder { get; private set; }
|
protected LadderInfo Ladder { get; private set; }
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
TournamentMatch match = CreateSampleMatch();
|
||||||
|
|
||||||
|
Ladder.Rounds.Clear();
|
||||||
|
Ladder.Rounds.Add(match.Round.Value);
|
||||||
|
|
||||||
|
Ladder.Matches.Clear();
|
||||||
|
Ladder.Matches.Add(match);
|
||||||
|
|
||||||
|
Ladder.Teams.Clear();
|
||||||
|
Ladder.Teams.Add(match.Team1.Value);
|
||||||
|
Ladder.Teams.Add(match.Team2.Value);
|
||||||
|
|
||||||
|
Ladder.CurrentMatch.Value = match;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TournamentMatch CreateSampleMatch() => new TournamentMatch
|
||||||
|
{
|
||||||
|
Team1 =
|
||||||
|
{
|
||||||
|
Value = new TournamentTeam
|
||||||
|
{
|
||||||
|
FlagName = { Value = "JP" },
|
||||||
|
FullName = { Value = "Japan" },
|
||||||
|
LastYearPlacing = { Value = 10 },
|
||||||
|
Seed = { Value = "Low" },
|
||||||
|
SeedingResults =
|
||||||
|
{
|
||||||
|
new SeedingResult
|
||||||
|
{
|
||||||
|
Mod = { Value = "NM" },
|
||||||
|
Seed = { Value = 10 },
|
||||||
|
Beatmaps =
|
||||||
|
{
|
||||||
|
new SeedingBeatmap
|
||||||
|
{
|
||||||
|
BeatmapInfo = CreateSampleBeatmapInfo(),
|
||||||
|
Score = 12345672,
|
||||||
|
Seed = { Value = 24 },
|
||||||
|
},
|
||||||
|
new SeedingBeatmap
|
||||||
|
{
|
||||||
|
BeatmapInfo = CreateSampleBeatmapInfo(),
|
||||||
|
Score = 1234567,
|
||||||
|
Seed = { Value = 12 },
|
||||||
|
},
|
||||||
|
new SeedingBeatmap
|
||||||
|
{
|
||||||
|
BeatmapInfo = CreateSampleBeatmapInfo(),
|
||||||
|
Score = 1234567,
|
||||||
|
Seed = { Value = 16 },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new SeedingResult
|
||||||
|
{
|
||||||
|
Mod = { Value = "DT" },
|
||||||
|
Seed = { Value = 5 },
|
||||||
|
Beatmaps =
|
||||||
|
{
|
||||||
|
new SeedingBeatmap
|
||||||
|
{
|
||||||
|
BeatmapInfo = CreateSampleBeatmapInfo(),
|
||||||
|
Score = 234567,
|
||||||
|
Seed = { Value = 3 },
|
||||||
|
},
|
||||||
|
new SeedingBeatmap
|
||||||
|
{
|
||||||
|
BeatmapInfo = CreateSampleBeatmapInfo(),
|
||||||
|
Score = 234567,
|
||||||
|
Seed = { Value = 6 },
|
||||||
|
},
|
||||||
|
new SeedingBeatmap
|
||||||
|
{
|
||||||
|
BeatmapInfo = CreateSampleBeatmapInfo(),
|
||||||
|
Score = 234567,
|
||||||
|
Seed = { Value = 12 },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Players =
|
||||||
|
{
|
||||||
|
new User { Username = "Hello", Statistics = new UserStatistics { Ranks = new UserStatistics.UserRanks { Global = 12 } } },
|
||||||
|
new User { Username = "Hello", Statistics = new UserStatistics { Ranks = new UserStatistics.UserRanks { Global = 16 } } },
|
||||||
|
new User { Username = "Hello", Statistics = new UserStatistics { Ranks = new UserStatistics.UserRanks { Global = 20 } } },
|
||||||
|
new User { Username = "Hello", Statistics = new UserStatistics { Ranks = new UserStatistics.UserRanks { Global = 24 } } },
|
||||||
|
new User { Username = "Hello", Statistics = new UserStatistics { Ranks = new UserStatistics.UserRanks { Global = 30 } } },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Team2 =
|
||||||
|
{
|
||||||
|
Value = new TournamentTeam
|
||||||
|
{
|
||||||
|
FlagName = { Value = "US" },
|
||||||
|
FullName = { Value = "United States" },
|
||||||
|
Players =
|
||||||
|
{
|
||||||
|
new User { Username = "Hello" },
|
||||||
|
new User { Username = "Hello" },
|
||||||
|
new User { Username = "Hello" },
|
||||||
|
new User { Username = "Hello" },
|
||||||
|
new User { Username = "Hello" },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Round =
|
||||||
|
{
|
||||||
|
Value = new TournamentRound { Name = { Value = "Quarterfinals" } }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static BeatmapInfo CreateSampleBeatmapInfo() =>
|
||||||
|
new BeatmapInfo { Metadata = new BeatmapMetadata { Title = "Test Title", Artist = "Test Artist", ID = RNG.Next(0, 1000000) } };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,93 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Tournament.Components;
|
||||||
|
using osu.Game.Tournament.Models;
|
||||||
using osu.Game.Tournament.Screens.MapPool;
|
using osu.Game.Tournament.Screens.MapPool;
|
||||||
|
|
||||||
namespace osu.Game.Tournament.Tests.Screens
|
namespace osu.Game.Tournament.Tests.Screens
|
||||||
{
|
{
|
||||||
public class TestSceneMapPoolScreen : LadderTestScene
|
public class TestSceneMapPoolScreen : LadderTestScene
|
||||||
{
|
{
|
||||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
private MapPoolScreen screen;
|
||||||
{
|
|
||||||
typeof(MapPoolScreen)
|
|
||||||
};
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
Add(new MapPoolScreen { Width = 0.7f });
|
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();
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("ensure layout width is 2", () => screen.ChildrenOfType<TournamentBeatmapPanel>().ElementAt(2).Y > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestManyMaps()
|
||||||
|
{
|
||||||
|
AddStep("load many maps", () =>
|
||||||
|
{
|
||||||
|
Ladder.CurrentMatch.Value.Round.Value.Beatmaps.Clear();
|
||||||
|
|
||||||
|
for (int i = 0; i < 17; i++)
|
||||||
|
addBeatmap();
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("reset match", () =>
|
||||||
|
{
|
||||||
|
Ladder.CurrentMatch.Value = new TournamentMatch();
|
||||||
|
Ladder.CurrentMatch.Value = Ladder.Matches.First();
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("ensure layout width is 3", () => screen.ChildrenOfType<TournamentBeatmapPanel>().ElementAt(2).Y == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestManyMods()
|
||||||
|
{
|
||||||
|
AddStep("load many maps", () =>
|
||||||
|
{
|
||||||
|
Ladder.CurrentMatch.Value.Round.Value.Beatmaps.Clear();
|
||||||
|
|
||||||
|
for (int i = 0; i < 13; i++)
|
||||||
|
addBeatmap(i < 4 ? $"M{i}" : "NM");
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("reset match", () =>
|
||||||
|
{
|
||||||
|
Ladder.CurrentMatch.Value = new TournamentMatch();
|
||||||
|
Ladder.CurrentMatch.Value = Ladder.Matches.First();
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("ensure layout width is 3", () => screen.ChildrenOfType<TournamentBeatmapPanel>().ElementAt(2).Y == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addBeatmap(string mods = "nm")
|
||||||
|
{
|
||||||
|
Ladder.CurrentMatch.Value.Round.Value.Beatmaps.Add(new RoundBeatmap
|
||||||
|
{
|
||||||
|
BeatmapInfo = CreateSampleBeatmapInfo(),
|
||||||
|
Mods = mods
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ namespace osu.Game.Tournament.Tests.Screens
|
|||||||
|
|
||||||
public TestSceneSeedingEditorScreen()
|
public TestSceneSeedingEditorScreen()
|
||||||
{
|
{
|
||||||
var match = TestSceneSeedingScreen.CreateSampleSeededMatch();
|
var match = CreateSampleMatch();
|
||||||
|
|
||||||
Add(new SeedingEditorScreen(match.Team1.Value)
|
Add(new SeedingEditorScreen(match.Team1.Value)
|
||||||
{
|
{
|
||||||
|
@ -3,10 +3,8 @@
|
|||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Tournament.Models;
|
using osu.Game.Tournament.Models;
|
||||||
using osu.Game.Tournament.Screens.TeamIntro;
|
using osu.Game.Tournament.Screens.TeamIntro;
|
||||||
using osu.Game.Users;
|
|
||||||
|
|
||||||
namespace osu.Game.Tournament.Tests.Screens
|
namespace osu.Game.Tournament.Tests.Screens
|
||||||
{
|
{
|
||||||
@ -18,110 +16,11 @@ namespace osu.Game.Tournament.Tests.Screens
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
ladder.CurrentMatch.Value = CreateSampleSeededMatch();
|
|
||||||
|
|
||||||
Add(new SeedingScreen
|
Add(new SeedingScreen
|
||||||
{
|
{
|
||||||
FillMode = FillMode.Fit,
|
FillMode = FillMode.Fit,
|
||||||
FillAspectRatio = 16 / 9f
|
FillAspectRatio = 16 / 9f
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TournamentMatch CreateSampleSeededMatch() => new TournamentMatch
|
|
||||||
{
|
|
||||||
Team1 =
|
|
||||||
{
|
|
||||||
Value = new TournamentTeam
|
|
||||||
{
|
|
||||||
FlagName = { Value = "JP" },
|
|
||||||
FullName = { Value = "Japan" },
|
|
||||||
LastYearPlacing = { Value = 10 },
|
|
||||||
Seed = { Value = "Low" },
|
|
||||||
SeedingResults =
|
|
||||||
{
|
|
||||||
new SeedingResult
|
|
||||||
{
|
|
||||||
Mod = { Value = "NM" },
|
|
||||||
Seed = { Value = 10 },
|
|
||||||
Beatmaps =
|
|
||||||
{
|
|
||||||
new SeedingBeatmap
|
|
||||||
{
|
|
||||||
BeatmapInfo = new BeatmapInfo { Metadata = new BeatmapMetadata { Title = "Test Title", Artist = "Test Artist" } },
|
|
||||||
Score = 12345672,
|
|
||||||
Seed = { Value = 24 },
|
|
||||||
},
|
|
||||||
new SeedingBeatmap
|
|
||||||
{
|
|
||||||
BeatmapInfo = new BeatmapInfo { Metadata = new BeatmapMetadata { Title = "Test Title", Artist = "Test Artist" } },
|
|
||||||
Score = 1234567,
|
|
||||||
Seed = { Value = 12 },
|
|
||||||
},
|
|
||||||
new SeedingBeatmap
|
|
||||||
{
|
|
||||||
BeatmapInfo = new BeatmapInfo { Metadata = new BeatmapMetadata { Title = "Test Title", Artist = "Test Artist" } },
|
|
||||||
Score = 1234567,
|
|
||||||
Seed = { Value = 16 },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new SeedingResult
|
|
||||||
{
|
|
||||||
Mod = { Value = "DT" },
|
|
||||||
Seed = { Value = 5 },
|
|
||||||
Beatmaps =
|
|
||||||
{
|
|
||||||
new SeedingBeatmap
|
|
||||||
{
|
|
||||||
BeatmapInfo = new BeatmapInfo { Metadata = new BeatmapMetadata { Title = "Test Title", Artist = "Test Artist" } },
|
|
||||||
Score = 234567,
|
|
||||||
Seed = { Value = 3 },
|
|
||||||
},
|
|
||||||
new SeedingBeatmap
|
|
||||||
{
|
|
||||||
BeatmapInfo = new BeatmapInfo { Metadata = new BeatmapMetadata { Title = "Test Title", Artist = "Test Artist" } },
|
|
||||||
Score = 234567,
|
|
||||||
Seed = { Value = 6 },
|
|
||||||
},
|
|
||||||
new SeedingBeatmap
|
|
||||||
{
|
|
||||||
BeatmapInfo = new BeatmapInfo { Metadata = new BeatmapMetadata { Title = "Test Title", Artist = "Test Artist" } },
|
|
||||||
Score = 234567,
|
|
||||||
Seed = { Value = 12 },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Players =
|
|
||||||
{
|
|
||||||
new User { Username = "Hello", Statistics = new UserStatistics { Ranks = new UserStatistics.UserRanks { Global = 12 } } },
|
|
||||||
new User { Username = "Hello", Statistics = new UserStatistics { Ranks = new UserStatistics.UserRanks { Global = 16 } } },
|
|
||||||
new User { Username = "Hello", Statistics = new UserStatistics { Ranks = new UserStatistics.UserRanks { Global = 20 } } },
|
|
||||||
new User { Username = "Hello", Statistics = new UserStatistics { Ranks = new UserStatistics.UserRanks { Global = 24 } } },
|
|
||||||
new User { Username = "Hello", Statistics = new UserStatistics { Ranks = new UserStatistics.UserRanks { Global = 30 } } },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Team2 =
|
|
||||||
{
|
|
||||||
Value = new TournamentTeam
|
|
||||||
{
|
|
||||||
FlagName = { Value = "US" },
|
|
||||||
FullName = { Value = "United States" },
|
|
||||||
Players =
|
|
||||||
{
|
|
||||||
new User { Username = "Hello" },
|
|
||||||
new User { Username = "Hello" },
|
|
||||||
new User { Username = "Hello" },
|
|
||||||
new User { Username = "Hello" },
|
|
||||||
new User { Username = "Hello" },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Round =
|
|
||||||
{
|
|
||||||
Value = new TournamentRound { Name = { Value = "Quarterfinals" } }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,6 @@ namespace osu.Game.Tournament.Screens.MapPool
|
|||||||
{
|
{
|
||||||
Y = 100,
|
Y = 100,
|
||||||
Spacing = new Vector2(10, 10),
|
Spacing = new Vector2(10, 10),
|
||||||
Padding = new MarginPadding(5) { Horizontal = 100 },
|
|
||||||
Direction = FillDirection.Vertical,
|
Direction = FillDirection.Vertical,
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
AutoSizeAxes = Axes.Y,
|
AutoSizeAxes = Axes.Y,
|
||||||
@ -212,6 +211,7 @@ namespace osu.Game.Tournament.Screens.MapPool
|
|||||||
private void matchChanged(ValueChangedEvent<TournamentMatch> match)
|
private void matchChanged(ValueChangedEvent<TournamentMatch> match)
|
||||||
{
|
{
|
||||||
mapFlows.Clear();
|
mapFlows.Clear();
|
||||||
|
mapFlows.Padding = new MarginPadding(5) { Horizontal = 100 };
|
||||||
|
|
||||||
int totalRows = 0;
|
int totalRows = 0;
|
||||||
|
|
||||||
@ -243,7 +243,7 @@ namespace osu.Game.Tournament.Screens.MapPool
|
|||||||
if (++flowCount > 2)
|
if (++flowCount > 2)
|
||||||
{
|
{
|
||||||
totalRows++;
|
totalRows++;
|
||||||
flowCount = 0;
|
flowCount = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentFlow.Add(new TournamentBeatmapPanel(b.BeatmapInfo, b.Mods)
|
currentFlow.Add(new TournamentBeatmapPanel(b.BeatmapInfo, b.Mods)
|
||||||
|
Loading…
Reference in New Issue
Block a user