Skip to content

Commit

Permalink
Merge branch 'master' into fix-multiplayer-participant-panel-null-rul…
Browse files Browse the repository at this point in the history
…eset
  • Loading branch information
frenzibyte authored Jul 18, 2022
2 parents 2789a97 + e14e2cc commit f1133ca
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
40 changes: 38 additions & 2 deletions osu.Game.Tests/NonVisual/BeatmapSetInfoEqualityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,45 @@ public void TestAudioEqualityDifferentHash()
Assert.IsTrue(beatmapSetA.Beatmaps.Single().AudioEquals(beatmapSetB.Beatmaps.Single()));
}

private static void addAudioFile(BeatmapSetInfo beatmapSetInfo, string hash = null)
[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)
{
beatmapSetInfo.Files.Add(new RealmNamedFileUsage(new RealmFile { Hash = hash ?? Guid.NewGuid().ToString() }, "audio.mp3"));
beatmapSetInfo.Files.Add(new RealmNamedFileUsage(new RealmFile { Hash = hash ?? Guid.NewGuid().ToString() }, filename ?? "audio.mp3"));
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Tests/Resources/TestResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ IEnumerable<BeatmapInfo> getBeatmaps(int count)
BPM = bpm,
Hash = Guid.NewGuid().ToString().ComputeMD5Hash(),
Ruleset = rulesetInfo,
Metadata = metadata,
Metadata = metadata.DeepClone(),
Difficulty = new BeatmapDifficulty
{
OverallDifficulty = diff,
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Beatmaps/BeatmapInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ private static bool compareFiles(BeatmapInfo x, BeatmapInfo y, Func<IBeatmapMeta
Debug.Assert(x.BeatmapSet != null);
Debug.Assert(y.BeatmapSet != null);

string? fileHashX = x.BeatmapSet.Files.FirstOrDefault(f => f.Filename == getFilename(x.BeatmapSet.Metadata))?.File.Hash;
string? fileHashY = y.BeatmapSet.Files.FirstOrDefault(f => f.Filename == getFilename(y.BeatmapSet.Metadata))?.File.Hash;
string? fileHashX = x.BeatmapSet.Files.FirstOrDefault(f => f.Filename == getFilename(x.Metadata))?.File.Hash;
string? fileHashY = y.BeatmapSet.Files.FirstOrDefault(f => f.Filename == getFilename(y.Metadata))?.File.Hash;

return fileHashX == fileHashY;
}
Expand Down

0 comments on commit f1133ca

Please sign in to comment.