1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 15:33:22 +08:00
osu-lazer/osu.Game.Rulesets.Osu.Tests/OsuBeatmapConversionTest.cs

78 lines
2.6 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
using System;
using System.Collections.Generic;
using NUnit.Framework;
2020-01-09 12:43:44 +08:00
using osu.Framework.Utils;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Tests.Beatmaps;
namespace osu.Game.Rulesets.Osu.Tests
{
[TestFixture]
public class OsuBeatmapConversionTest : BeatmapConversionTest<ConvertValue>
2018-04-13 17:19:50 +08:00
{
protected override string ResourceAssembly => "osu.Game.Rulesets.Osu";
[TestCase("basic")]
[TestCase("colinear-perfect-curve")]
2018-06-14 00:28:28 +08:00
[TestCase("slider-ticks")]
[TestCase("slider-ticks-edge-case")]
2023-09-19 00:02:20 +08:00
[TestCase("slider-paths-edge-case")]
2019-08-01 16:31:08 +08:00
[TestCase("repeat-slider")]
[TestCase("uneven-repeat-slider")]
[TestCase("old-stacking")]
2021-04-05 16:47:12 +08:00
[TestCase("multi-segment-slider")]
[TestCase("nan-slider")]
public void Test(string name) => base.Test(name);
2018-04-13 17:19:50 +08:00
protected override IEnumerable<ConvertValue> CreateConvertValue(HitObject hitObject)
{
switch (hitObject)
{
case Slider slider:
foreach (var nested in slider.NestedHitObjects)
yield return createConvertValue((OsuHitObject)nested);
2019-02-28 12:31:40 +08:00
break;
2019-04-01 11:44:46 +08:00
default:
yield return createConvertValue((OsuHitObject)hitObject);
2019-02-28 12:31:40 +08:00
break;
}
2018-04-13 17:19:50 +08:00
2019-11-12 18:37:20 +08:00
static ConvertValue createConvertValue(OsuHitObject obj) => new ConvertValue
2018-04-13 17:19:50 +08:00
{
StartTime = obj.StartTime,
EndTime = obj.GetEndTime(),
X = obj.StackedPosition.X,
Y = obj.StackedPosition.Y
2018-04-13 17:19:50 +08:00
};
}
protected override Ruleset CreateRuleset() => new OsuRuleset();
2018-04-13 17:19:50 +08:00
}
public struct ConvertValue : IEquatable<ConvertValue>
2018-04-13 17:19:50 +08:00
{
/// <summary>
/// A sane value to account for osu!stable using <see cref="int"/>s everywhere.
2018-04-13 17:19:50 +08:00
/// </summary>
private const double conversion_lenience = 2;
public double StartTime;
public double EndTime;
public float X;
public float Y;
2018-04-13 17:19:50 +08:00
public bool Equals(ConvertValue other)
=> Precision.AlmostEquals(StartTime, other.StartTime, conversion_lenience)
2018-04-13 17:19:50 +08:00
&& Precision.AlmostEquals(EndTime, other.EndTime, conversion_lenience)
&& Precision.AlmostEquals(X, other.X, conversion_lenience)
&& Precision.AlmostEquals(Y, other.Y, conversion_lenience);
2018-04-13 17:19:50 +08:00
}
}