Skip to content

Commit

Permalink
Add some test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Jul 2, 2020
1 parent 92854d6 commit faecef9
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 7 deletions.
44 changes: 44 additions & 0 deletions osu.Game.Rulesets.Karaoke.Tests/Ranking/TestKaraokeScoreInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using osu.Game.Rulesets.Karaoke.Mods;
using osu.Game.Rulesets.Karaoke.Tests.Beatmaps;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Users;

namespace osu.Game.Rulesets.Karaoke.Tests.Ranking
{
public class TestKaraokeScoreInfo : ScoreInfo
{
public TestKaraokeScoreInfo()
{
var ruleset = new KaraokeRuleset().RulesetInfo;

User = new User
{
Id = 11111,
Username = "andy840119",
CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
};

Beatmap = new TestKaraokeBeatmap(ruleset).BeatmapInfo;
Ruleset = ruleset;
RulesetID = ruleset.ID ?? 0;
Mods = new Mod[] { new KaraokeModFlashlight(), new KaraokeModSnow() };

TotalScore = 2845370;
Accuracy = 0.95;
MaxCombo = 999;
Rank = ScoreRank.S;
Date = DateTimeOffset.Now;

Statistics[HitResult.Miss] = 1;
Statistics[HitResult.Meh] = 50;
Statistics[HitResult.Good] = 100;
Statistics[HitResult.Great] = 300;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL 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.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Ranking.Statistics;
using osu.Game.Tests.Visual;
using osuTK;

namespace osu.Game.Rulesets.Karaoke.Tests.Ranking
{
public class TestSceneHitEventTimingDistributionGraph : OsuTestScene
{
[Test]
public void TestManyDistributedEvents()
{
createTest(CreateDistributedHitEvents());
}

[Test]
public void TestZeroTimeOffset()
{
createTest(Enumerable.Range(0, 100).Select(_ => new HitEvent(0, HitResult.Perfect, new Note(), new Note(), null)).ToList());
}

[Test]
public void TestNoEvents()
{
createTest(new List<HitEvent>());
}

private void createTest(List<HitEvent> events) => AddStep("create test", () =>
{
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex("#333")
},
new HitEventTimingDistributionGraph(events)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(600, 130)
}
};
});

public static List<HitEvent> CreateDistributedHitEvents()
{
var hitEvents = new List<HitEvent>();

for (int i = 0; i < 50; i++)
{
int count = (int)(Math.Pow(25 - Math.Abs(i - 25), 2));

for (int j = 0; j < count; j++)
hitEvents.Add(new HitEvent(i - 25, HitResult.Perfect, new Note(), new Note(), null));
}

return hitEvents;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using NUnit.Framework;
Expand All @@ -7,7 +7,6 @@
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking.Statistics;
using osu.Game.Tests;
using osu.Game.Tests.Visual;
using System.Collections.Generic;

Expand All @@ -18,10 +17,9 @@ public class TestSceneStatisticsPanel : OsuTestScene
[Test]
public void TestScoreWithStatistics()
{
var score = new TestScoreInfo(new KaraokeRuleset().RulesetInfo)
var score = new TestKaraokeScoreInfo()
{
//TODO : add hit event.
HitEvents = new List<HitEvent>()
HitEvents = TestSceneHitEventTimingDistributionGraph.CreateDistributedHitEvents()
};

loadPanel(score);
Expand All @@ -30,7 +28,7 @@ public void TestScoreWithStatistics()
[Test]
public void TestScoreWithoutStatistics()
{
loadPanel(new TestScoreInfo(new KaraokeRuleset().RulesetInfo));
loadPanel(new TestKaraokeScoreInfo());
}

[Test]
Expand Down

0 comments on commit faecef9

Please sign in to comment.