2019-10-16 22:19:50 +00:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2021-11-22 05:26:51 +00:00
|
|
|
using System;
|
2022-07-13 10:40:57 +00:00
|
|
|
using System.Linq;
|
2019-10-16 22:19:50 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Game.Beatmaps;
|
2021-11-15 05:43:31 +00:00
|
|
|
using osu.Game.Extensions;
|
2022-07-13 10:40:57 +00:00
|
|
|
using osu.Game.Models;
|
|
|
|
using osu.Game.Tests.Resources;
|
2019-10-16 22:19:50 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.NonVisual
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class BeatmapSetInfoEqualityTest
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void TestOnlineWithOnline()
|
|
|
|
{
|
2021-11-12 08:50:31 +00:00
|
|
|
var ourInfo = new BeatmapSetInfo { OnlineID = 123 };
|
|
|
|
var otherInfo = new BeatmapSetInfo { OnlineID = 123 };
|
2019-10-16 22:19:50 +00:00
|
|
|
|
2021-11-15 05:43:31 +00:00
|
|
|
Assert.AreNotEqual(ourInfo, otherInfo);
|
|
|
|
Assert.IsTrue(ourInfo.MatchesOnlineID(otherInfo));
|
2019-10-16 22:19:50 +00:00
|
|
|
}
|
|
|
|
|
2022-07-13 10:40:57 +00:00
|
|
|
[Test]
|
|
|
|
public void TestAudioEqualityNoFile()
|
|
|
|
{
|
|
|
|
var beatmapSetA = TestResources.CreateTestBeatmapSetInfo(1);
|
|
|
|
var beatmapSetB = TestResources.CreateTestBeatmapSetInfo(1);
|
|
|
|
|
|
|
|
Assert.AreNotEqual(beatmapSetA, beatmapSetB);
|
|
|
|
Assert.IsTrue(beatmapSetA.Beatmaps.Single().AudioEquals(beatmapSetB.Beatmaps.Single()));
|
|
|
|
}
|
|
|
|
|
2022-08-10 07:03:40 +00:00
|
|
|
[Test]
|
|
|
|
public void TestAudioEqualityCaseSensitivity()
|
|
|
|
{
|
|
|
|
var beatmapSetA = TestResources.CreateTestBeatmapSetInfo(1);
|
|
|
|
var beatmapSetB = TestResources.CreateTestBeatmapSetInfo(1);
|
|
|
|
|
|
|
|
// empty by default so let's set it..
|
|
|
|
beatmapSetA.Beatmaps.First().Metadata.AudioFile = "audio.mp3";
|
|
|
|
beatmapSetB.Beatmaps.First().Metadata.AudioFile = "audio.mp3";
|
|
|
|
|
|
|
|
addAudioFile(beatmapSetA, "abc", "AuDiO.mP3");
|
|
|
|
addAudioFile(beatmapSetB, "abc", "audio.mp3");
|
|
|
|
|
|
|
|
Assert.AreNotEqual(beatmapSetA, beatmapSetB);
|
|
|
|
Assert.IsTrue(beatmapSetA.Beatmaps.Single().AudioEquals(beatmapSetB.Beatmaps.Single()));
|
|
|
|
}
|
|
|
|
|
2022-07-13 10:40:57 +00:00
|
|
|
[Test]
|
|
|
|
public void TestAudioEqualitySameHash()
|
|
|
|
{
|
|
|
|
var beatmapSetA = TestResources.CreateTestBeatmapSetInfo(1);
|
|
|
|
var beatmapSetB = TestResources.CreateTestBeatmapSetInfo(1);
|
|
|
|
|
|
|
|
addAudioFile(beatmapSetA, "abc");
|
|
|
|
addAudioFile(beatmapSetB, "abc");
|
|
|
|
|
|
|
|
Assert.AreNotEqual(beatmapSetA, beatmapSetB);
|
|
|
|
Assert.IsTrue(beatmapSetA.Beatmaps.Single().AudioEquals(beatmapSetB.Beatmaps.Single()));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAudioEqualityDifferentHash()
|
|
|
|
{
|
|
|
|
var beatmapSetA = TestResources.CreateTestBeatmapSetInfo(1);
|
|
|
|
var beatmapSetB = TestResources.CreateTestBeatmapSetInfo(1);
|
|
|
|
|
|
|
|
addAudioFile(beatmapSetA);
|
|
|
|
addAudioFile(beatmapSetB);
|
|
|
|
|
|
|
|
Assert.AreNotEqual(beatmapSetA, beatmapSetB);
|
|
|
|
Assert.IsTrue(beatmapSetA.Beatmaps.Single().AudioEquals(beatmapSetB.Beatmaps.Single()));
|
|
|
|
}
|
|
|
|
|
2022-07-18 08:01:45 +00:00
|
|
|
[Test]
|
|
|
|
public void TestAudioEqualityBeatmapInfoSameHash()
|
|
|
|
{
|
|
|
|
var beatmapSet = TestResources.CreateTestBeatmapSetInfo(2);
|
|
|
|
|
|
|
|
addAudioFile(beatmapSet);
|
|
|
|
|
|
|
|
var beatmap1 = beatmapSet.Beatmaps.First();
|
|
|
|
var beatmap2 = beatmapSet.Beatmaps.Last();
|
|
|
|
|
|
|
|
Assert.AreNotEqual(beatmap1, beatmap2);
|
|
|
|
Assert.IsTrue(beatmap1.AudioEquals(beatmap2));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAudioEqualityBeatmapInfoDifferentHash()
|
|
|
|
{
|
|
|
|
var beatmapSet = TestResources.CreateTestBeatmapSetInfo(2);
|
|
|
|
|
|
|
|
const string filename1 = "audio1.mp3";
|
|
|
|
const string filename2 = "audio2.mp3";
|
|
|
|
|
|
|
|
addAudioFile(beatmapSet, filename: filename1);
|
|
|
|
addAudioFile(beatmapSet, filename: filename2);
|
|
|
|
|
|
|
|
var beatmap1 = beatmapSet.Beatmaps.First();
|
|
|
|
var beatmap2 = beatmapSet.Beatmaps.Last();
|
|
|
|
|
|
|
|
Assert.AreNotEqual(beatmap1, beatmap2);
|
|
|
|
|
|
|
|
beatmap1.Metadata.AudioFile = filename1;
|
|
|
|
beatmap2.Metadata.AudioFile = filename2;
|
|
|
|
|
|
|
|
Assert.IsFalse(beatmap1.AudioEquals(beatmap2));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void addAudioFile(BeatmapSetInfo beatmapSetInfo, string hash = null, string filename = null)
|
2022-07-13 10:40:57 +00:00
|
|
|
{
|
2022-07-18 08:01:45 +00:00
|
|
|
beatmapSetInfo.Files.Add(new RealmNamedFileUsage(new RealmFile { Hash = hash ?? Guid.NewGuid().ToString() }, filename ?? "audio.mp3"));
|
2022-07-13 10:40:57 +00:00
|
|
|
}
|
|
|
|
|
2019-10-16 22:19:50 +00:00
|
|
|
[Test]
|
|
|
|
public void TestDatabasedWithDatabased()
|
|
|
|
{
|
2021-11-22 05:26:51 +00:00
|
|
|
var guid = Guid.NewGuid();
|
|
|
|
|
|
|
|
var ourInfo = new BeatmapSetInfo { ID = guid };
|
|
|
|
var otherInfo = new BeatmapSetInfo { ID = guid };
|
2019-10-16 22:19:50 +00:00
|
|
|
|
|
|
|
Assert.AreEqual(ourInfo, otherInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestDatabasedWithOnline()
|
|
|
|
{
|
2021-11-22 05:26:51 +00:00
|
|
|
var ourInfo = new BeatmapSetInfo { ID = Guid.NewGuid(), OnlineID = 12 };
|
2021-11-12 08:50:31 +00:00
|
|
|
var otherInfo = new BeatmapSetInfo { OnlineID = 12 };
|
2019-10-16 22:19:50 +00:00
|
|
|
|
2021-11-15 05:43:31 +00:00
|
|
|
Assert.AreNotEqual(ourInfo, otherInfo);
|
|
|
|
Assert.IsTrue(ourInfo.MatchesOnlineID(otherInfo));
|
2019-10-16 22:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCheckNullID()
|
|
|
|
{
|
2021-11-01 06:42:12 +00:00
|
|
|
var ourInfo = new BeatmapSetInfo { Hash = "1" };
|
|
|
|
var otherInfo = new BeatmapSetInfo { Hash = "2" };
|
2019-10-16 22:19:50 +00:00
|
|
|
|
|
|
|
Assert.AreNotEqual(ourInfo, otherInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|