mirror of
https://github.com/ppy/osu.git
synced 2025-02-05 11:42:55 +08:00
Add parity checking OsuJsonDecoder test cases
This commit is contained in:
parent
ea2c67ca5f
commit
499ecb4edd
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using DeepEqual.Syntax;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
@ -18,10 +19,13 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class OsuJsonDecoderTest
|
public class OsuJsonDecoderTest
|
||||||
{
|
{
|
||||||
|
private const string beatmap_1 = "Soleily - Renatus (Gamu) [Insane].osu";
|
||||||
|
private const string beatmap_2 = "Within Temptation - The Unforgiving (Armin) [Marathon].osu";
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestDecodeMetadata()
|
public void TestDecodeMetadata()
|
||||||
{
|
{
|
||||||
var beatmap = decodeAsJson("Soleily - Renatus (Gamu) [Insane].osu");
|
var beatmap = decodeAsJson(beatmap_1);
|
||||||
var meta = beatmap.BeatmapInfo.Metadata;
|
var meta = beatmap.BeatmapInfo.Metadata;
|
||||||
Assert.AreEqual(241526, meta.OnlineBeatmapSetID);
|
Assert.AreEqual(241526, meta.OnlineBeatmapSetID);
|
||||||
Assert.AreEqual("Soleily", meta.Artist);
|
Assert.AreEqual("Soleily", meta.Artist);
|
||||||
@ -39,7 +43,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestDecodeGeneral()
|
public void TestDecodeGeneral()
|
||||||
{
|
{
|
||||||
var beatmap = decodeAsJson("Soleily - Renatus (Gamu) [Insane].osu");
|
var beatmap = decodeAsJson(beatmap_1);
|
||||||
var beatmapInfo = beatmap.BeatmapInfo;
|
var beatmapInfo = beatmap.BeatmapInfo;
|
||||||
Assert.AreEqual(0, beatmapInfo.AudioLeadIn);
|
Assert.AreEqual(0, beatmapInfo.AudioLeadIn);
|
||||||
Assert.AreEqual(false, beatmapInfo.Countdown);
|
Assert.AreEqual(false, beatmapInfo.Countdown);
|
||||||
@ -53,7 +57,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestDecodeEditor()
|
public void TestDecodeEditor()
|
||||||
{
|
{
|
||||||
var beatmap = decodeAsJson("Soleily - Renatus (Gamu) [Insane].osu");
|
var beatmap = decodeAsJson(beatmap_1);
|
||||||
var beatmapInfo = beatmap.BeatmapInfo;
|
var beatmapInfo = beatmap.BeatmapInfo;
|
||||||
|
|
||||||
int[] expectedBookmarks =
|
int[] expectedBookmarks =
|
||||||
@ -74,7 +78,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestDecodeDifficulty()
|
public void TestDecodeDifficulty()
|
||||||
{
|
{
|
||||||
var beatmap = decodeAsJson("Soleily - Renatus (Gamu) [Insane].osu");
|
var beatmap = decodeAsJson(beatmap_1);
|
||||||
var difficulty = beatmap.BeatmapInfo.BaseDifficulty;
|
var difficulty = beatmap.BeatmapInfo.BaseDifficulty;
|
||||||
Assert.AreEqual(6.5f, difficulty.DrainRate);
|
Assert.AreEqual(6.5f, difficulty.DrainRate);
|
||||||
Assert.AreEqual(4, difficulty.CircleSize);
|
Assert.AreEqual(4, difficulty.CircleSize);
|
||||||
@ -87,7 +91,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestDecodeColors()
|
public void TestDecodeColors()
|
||||||
{
|
{
|
||||||
var beatmap = decodeAsJson("Soleily - Renatus (Gamu) [Insane].osu");
|
var beatmap = decodeAsJson(beatmap_1);
|
||||||
Color4[] expected =
|
Color4[] expected =
|
||||||
{
|
{
|
||||||
new Color4(142, 199, 255, 255),
|
new Color4(142, 199, 255, 255),
|
||||||
@ -105,7 +109,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestDecodeHitObjects()
|
public void TestDecodeHitObjects()
|
||||||
{
|
{
|
||||||
var beatmap = decodeAsJson("Soleily - Renatus (Gamu) [Insane].osu");
|
var beatmap = decodeAsJson(beatmap_1);
|
||||||
|
|
||||||
var curveData = beatmap.HitObjects[0] as IHasCurve;
|
var curveData = beatmap.HitObjects[0] as IHasCurve;
|
||||||
var positionData = beatmap.HitObjects[0] as IHasPosition;
|
var positionData = beatmap.HitObjects[0] as IHasPosition;
|
||||||
@ -124,13 +128,29 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
Assert.IsTrue(beatmap.HitObjects[1].Samples.Any(s => s.Name == SampleInfo.HIT_CLAP));
|
Assert.IsTrue(beatmap.HitObjects[1].Samples.Any(s => s.Name == SampleInfo.HIT_CLAP));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestCase(beatmap_1)]
|
||||||
|
[TestCase(beatmap_2)]
|
||||||
|
public void TestParity(string beatmap)
|
||||||
|
{
|
||||||
|
var beatmaps = decode(beatmap);
|
||||||
|
beatmaps.jsonDecoded.ShouldDeepEqual(beatmaps.legacyDecoded);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads a .osu file first with a <see cref="OsuLegacyDecoder"/>, serializes the resulting <see cref="Beatmap"/> to JSON
|
/// Reads a .osu file first with a <see cref="OsuLegacyDecoder"/>, serializes the resulting <see cref="Beatmap"/> to JSON
|
||||||
/// and then deserializes the result back into a <see cref="Beatmap"/> through an <see cref="OsuJsonDecoder"/>.
|
/// and then deserializes the result back into a <see cref="Beatmap"/> through an <see cref="OsuJsonDecoder"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filename">The .osu file to decode.</param>
|
/// <param name="filename">The .osu file to decode.</param>
|
||||||
/// <returns>The <see cref="Beatmap"/> after being decoded by an <see cref="OsuLegacyDecoder"/>.</returns>
|
/// <returns>The <see cref="Beatmap"/> after being decoded by an <see cref="OsuLegacyDecoder"/>.</returns>
|
||||||
private Beatmap decodeAsJson(string filename)
|
private Beatmap decodeAsJson(string filename) => decode(filename).jsonDecoded;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads a .osu file first with a <see cref="OsuLegacyDecoder"/>, serializes the resulting <see cref="Beatmap"/> to JSON
|
||||||
|
/// and then deserializes the result back into a <see cref="Beatmap"/> through an <see cref="OsuJsonDecoder"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">The .osu file to decode.</param>
|
||||||
|
/// <returns>The <see cref="Beatmap"/> after being decoded by an <see cref="OsuLegacyDecoder"/>.</returns>
|
||||||
|
private (Beatmap legacyDecoded, Beatmap jsonDecoded) decode(string filename)
|
||||||
{
|
{
|
||||||
using (var stream = Resource.OpenResource(filename))
|
using (var stream = Resource.OpenResource(filename))
|
||||||
using (var sr = new StreamReader(stream))
|
using (var sr = new StreamReader(stream))
|
||||||
@ -145,7 +165,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
sw.Flush();
|
sw.Flush();
|
||||||
|
|
||||||
ms.Position = 0;
|
ms.Position = 0;
|
||||||
return new OsuJsonDecoder().Decode(sr2);
|
return (legacyDecoded, new OsuJsonDecoder().Decode(sr2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -30,6 +30,9 @@
|
|||||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="DeepEqual, Version=1.6.0.0, Culture=neutral, PublicKeyToken=null">
|
||||||
|
<HintPath>$(SolutionDir)\packages\DeepEqual.1.6.0.0\lib\net40\DeepEqual.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="nunit.framework, Version=3.8.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
<Reference Include="nunit.framework, Version=3.8.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||||
<HintPath>$(SolutionDir)\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll</HintPath>
|
<HintPath>$(SolutionDir)\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
@ -147,6 +150,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Resources\Soleily - Renatus %28Gamu%29 [Insane].osu" />
|
<EmbeddedResource Include="Resources\Soleily - Renatus %28Gamu%29 [Insane].osu" />
|
||||||
|
<EmbeddedResource Include="Resources\Within Temptation - The Unforgiving %28Armin%29 [Marathon].osu" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
@ -4,6 +4,7 @@ Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|||||||
Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
-->
|
-->
|
||||||
<packages>
|
<packages>
|
||||||
|
<package id="DeepEqual" version="1.6.0.0" targetFramework="net461" />
|
||||||
<package id="NUnit" version="3.8.1" targetFramework="net461" />
|
<package id="NUnit" version="3.8.1" targetFramework="net461" />
|
||||||
<package id="OpenTK" version="3.0.0-git00009" targetFramework="net461" />
|
<package id="OpenTK" version="3.0.0-git00009" targetFramework="net461" />
|
||||||
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
|
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
|
||||||
|
Loading…
Reference in New Issue
Block a user