mirror of
https://github.com/ppy/osu
synced 2024-12-27 09:23:15 +00:00
Add tests
This commit is contained in:
parent
ee7e2b0854
commit
41caa37856
@ -1,6 +1,7 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore.Internal;
|
||||
using NUnit.Framework;
|
||||
@ -162,5 +163,69 @@ namespace osu.Game.Tests.Beatmaps
|
||||
Assert.That(editorBeatmap.HitObjects.Count(h => h == hitCircle), Is.EqualTo(1));
|
||||
Assert.That(editorBeatmap.HitObjects.IndexOf(hitCircle), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that multiple hitobjects are updated simultaneously.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestMultipleHitObjectUpdate()
|
||||
{
|
||||
var updatedObjects = new List<HitObject>();
|
||||
var allHitObjects = new List<HitObject>();
|
||||
EditorBeatmap editorBeatmap = null;
|
||||
|
||||
AddStep("add beatmap", () =>
|
||||
{
|
||||
updatedObjects.Clear();
|
||||
|
||||
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap());
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
var h = new HitCircle();
|
||||
editorBeatmap.Add(h);
|
||||
allHitObjects.Add(h);
|
||||
}
|
||||
});
|
||||
|
||||
AddStep("change all start times", () =>
|
||||
{
|
||||
editorBeatmap.HitObjectUpdated += h => updatedObjects.Add(h);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
allHitObjects[i].StartTime += 10;
|
||||
});
|
||||
|
||||
// Distinct ensures that all hitobjects have been updated once, debounce is tested below.
|
||||
AddAssert("all hitobjects updated", () => updatedObjects.Distinct().Count() == 10);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that hitobject updates are debounced when they happen too soon.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestDebouncedUpdate()
|
||||
{
|
||||
var updatedObjects = new List<HitObject>();
|
||||
EditorBeatmap editorBeatmap = null;
|
||||
|
||||
AddStep("add beatmap", () =>
|
||||
{
|
||||
updatedObjects.Clear();
|
||||
|
||||
Child = editorBeatmap = new EditorBeatmap(new OsuBeatmap());
|
||||
editorBeatmap.Add(new HitCircle());
|
||||
});
|
||||
|
||||
AddStep("change start time twice", () =>
|
||||
{
|
||||
editorBeatmap.HitObjectUpdated += h => updatedObjects.Add(h);
|
||||
|
||||
editorBeatmap.HitObjects[0].StartTime = 10;
|
||||
editorBeatmap.HitObjects[0].StartTime = 20;
|
||||
});
|
||||
|
||||
AddAssert("only updated once", () => updatedObjects.Count == 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user