Add tests (wip)

This commit is contained in:
Dean Herbert
2020-03-11 15:34:52 +09:00
parent ef0acde458
commit fbb7e9f12a
5 changed files with 201 additions and 111 deletions

View File

@ -1,24 +1,93 @@
// 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;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
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 class TestSceneMapPoolScreen : LadderTestScene
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(MapPoolScreen)
};
private MapPoolScreen screen;
[BackgroundDependencyLoader]
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
});
}
}
}