mirror of
https://github.com/ppy/osu.git
synced 2026-05-19 01:49:53 +08:00
a996261304
It's been a while. Notes: - `SharpCompress` usages changed a bit. Manually adjusted these, mostly just renames or adjusted parameters. - nUnit 3 -> 4 migrated using https://gist.github.com/peppy/07994386d793a117350cb5f24b156585. there's a mode in this script to update to the newer `Assert.That` syntax but it requires fixes and couldn't really be bothered. - DeepEqual nuked as the only usage was on a disabled test. The reason it's disabled has been merged upstream, but it's failing for other (realm) reasons which I don't think is worthwhile to investigate for now. - This bumps Moq. I think the author is back in a sensible headspace and the new version has the stupid shit removed, so probably okay? Nice to be on a level playing field with packages for once in a long time. - Automapper is silly, but we've discussed this elsewhere. - `TestRealmKeyBindingStore` failures are a wildcard, but fixed by using a more standardised testing method. Dunno why, don't care. --------- Co-authored-by: Bartłomiej Dach <dach.bartlomiej@gmail.com>
87 lines
2.7 KiB
C#
87 lines
2.7 KiB
C#
// 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.Linq;
|
|
using NUnit.Framework;
|
|
using NUnit.Framework.Legacy;
|
|
using osu.Framework.Utils;
|
|
using osu.Game.Utils;
|
|
|
|
namespace osu.Game.Tests.NonVisual
|
|
{
|
|
[TestFixture]
|
|
public class PeriodTrackerTest
|
|
{
|
|
private static readonly Period[] single_period = { new Period(1.0, 2.0) };
|
|
|
|
private static readonly Period[] unordered_periods =
|
|
{
|
|
new Period(-9.1, -8.3),
|
|
new Period(-3.4, 2.1),
|
|
new Period(9.0, 50.0),
|
|
new Period(5.25, 10.50)
|
|
};
|
|
|
|
[Test]
|
|
public void TestCheckValueInsideSinglePeriod()
|
|
{
|
|
var tracker = new PeriodTracker(single_period);
|
|
|
|
var period = single_period.Single();
|
|
ClassicAssert.True(tracker.IsInAny(period.Start));
|
|
ClassicAssert.True(tracker.IsInAny(getMidpoint(period)));
|
|
ClassicAssert.True(tracker.IsInAny(period.End));
|
|
}
|
|
|
|
[Test]
|
|
public void TestCheckValuesInsidePeriods()
|
|
{
|
|
var tracker = new PeriodTracker(unordered_periods);
|
|
|
|
foreach (var period in unordered_periods)
|
|
ClassicAssert.True(tracker.IsInAny(getMidpoint(period)));
|
|
}
|
|
|
|
[Test]
|
|
public void TestCheckValuesInRandomOrder()
|
|
{
|
|
var tracker = new PeriodTracker(unordered_periods);
|
|
|
|
foreach (var period in unordered_periods.OrderBy(_ => RNG.Next()))
|
|
ClassicAssert.True(tracker.IsInAny(getMidpoint(period)));
|
|
}
|
|
|
|
[Test]
|
|
public void TestCheckValuesOutOfPeriods()
|
|
{
|
|
var tracker = new PeriodTracker(new[]
|
|
{
|
|
new Period(1.0, 2.0),
|
|
new Period(3.0, 4.0)
|
|
});
|
|
|
|
ClassicAssert.False(tracker.IsInAny(0.9), "Time before first period is being considered inside");
|
|
|
|
ClassicAssert.False(tracker.IsInAny(2.1), "Time right after first period is being considered inside");
|
|
ClassicAssert.False(tracker.IsInAny(2.9), "Time right before second period is being considered inside");
|
|
|
|
ClassicAssert.False(tracker.IsInAny(4.1), "Time after last period is being considered inside");
|
|
}
|
|
|
|
[Test]
|
|
public void TestReversedPeriodHandling()
|
|
{
|
|
Assert.Throws<ArgumentException>(() =>
|
|
{
|
|
_ = new PeriodTracker(new[]
|
|
{
|
|
new Period(2.0, 1.0)
|
|
});
|
|
});
|
|
}
|
|
|
|
private double getMidpoint(Period period) => period.Start + (period.End - period.Start) / 2;
|
|
}
|
|
}
|