Add parity checking OsuJsonDecoder test cases

This commit is contained in:
smoogipoo 2017-12-07 11:11:38 +09:00
parent ea2c67ca5f
commit 499ecb4edd
4 changed files with 7135 additions and 8 deletions

View File

@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using DeepEqual.Syntax;
using NUnit.Framework;
using osu.Game.Audio;
using osu.Game.Beatmaps;
@ -18,10 +19,13 @@ namespace osu.Game.Tests.Beatmaps.Formats
[TestFixture]
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]
public void TestDecodeMetadata()
{
var beatmap = decodeAsJson("Soleily - Renatus (Gamu) [Insane].osu");
var beatmap = decodeAsJson(beatmap_1);
var meta = beatmap.BeatmapInfo.Metadata;
Assert.AreEqual(241526, meta.OnlineBeatmapSetID);
Assert.AreEqual("Soleily", meta.Artist);
@ -39,7 +43,7 @@ public void TestDecodeMetadata()
[Test]
public void TestDecodeGeneral()
{
var beatmap = decodeAsJson("Soleily - Renatus (Gamu) [Insane].osu");
var beatmap = decodeAsJson(beatmap_1);
var beatmapInfo = beatmap.BeatmapInfo;
Assert.AreEqual(0, beatmapInfo.AudioLeadIn);
Assert.AreEqual(false, beatmapInfo.Countdown);
@ -53,7 +57,7 @@ public void TestDecodeGeneral()
[Test]
public void TestDecodeEditor()
{
var beatmap = decodeAsJson("Soleily - Renatus (Gamu) [Insane].osu");
var beatmap = decodeAsJson(beatmap_1);
var beatmapInfo = beatmap.BeatmapInfo;
int[] expectedBookmarks =
@ -74,7 +78,7 @@ public void TestDecodeEditor()
[Test]
public void TestDecodeDifficulty()
{
var beatmap = decodeAsJson("Soleily - Renatus (Gamu) [Insane].osu");
var beatmap = decodeAsJson(beatmap_1);
var difficulty = beatmap.BeatmapInfo.BaseDifficulty;
Assert.AreEqual(6.5f, difficulty.DrainRate);
Assert.AreEqual(4, difficulty.CircleSize);
@ -87,7 +91,7 @@ public void TestDecodeDifficulty()
[Test]
public void TestDecodeColors()
{
var beatmap = decodeAsJson("Soleily - Renatus (Gamu) [Insane].osu");
var beatmap = decodeAsJson(beatmap_1);
Color4[] expected =
{
new Color4(142, 199, 255, 255),
@ -105,7 +109,7 @@ public void TestDecodeColors()
[Test]
public void TestDecodeHitObjects()
{
var beatmap = decodeAsJson("Soleily - Renatus (Gamu) [Insane].osu");
var beatmap = decodeAsJson(beatmap_1);
var curveData = beatmap.HitObjects[0] as IHasCurve;
var positionData = beatmap.HitObjects[0] as IHasPosition;
@ -124,13 +128,29 @@ public void TestDecodeHitObjects()
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>
/// 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 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 sr = new StreamReader(stream))
@ -145,7 +165,7 @@ private Beatmap decodeAsJson(string filename)
sw.Flush();
ms.Position = 0;
return new OsuJsonDecoder().Decode(sr2);
return (legacyDecoded, new OsuJsonDecoder().Decode(sr2));
}
}
}

View File

@ -30,6 +30,9 @@
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<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">
<HintPath>$(SolutionDir)\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
@ -147,6 +150,7 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Soleily - Renatus %28Gamu%29 [Insane].osu" />
<EmbeddedResource Include="Resources\Within Temptation - The Unforgiving %28Armin%29 [Marathon].osu" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -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
-->
<packages>
<package id="DeepEqual" version="1.6.0.0" targetFramework="net461" />
<package id="NUnit" version="3.8.1" targetFramework="net461" />
<package id="OpenTK" version="3.0.0-git00009" targetFramework="net461" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />