Skip to content

Commit

Permalink
Add unit test for duplicate firmware filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshiRulz committed Dec 6, 2024
1 parent 69b61b5 commit 384b6f1
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
using System.Collections.Generic;
using System.Linq;

using BizHawk.Common.CollectionExtensions;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;

Expand All @@ -20,5 +24,28 @@ static void CustomAssert(string hash)
foreach (var hash in FirmwareDatabase.FirmwareFilesByHash.Keys) CustomAssert(hash);
foreach (var fo in FirmwareDatabase.FirmwareOptions) CustomAssert(fo.Hash);
}

[TestMethod]
public void CheckOrganizeFilenames()
{
SortedList<string, FirmwareFile> seen = new();
List<FirmwareFile> dupes = new();
foreach (var ff in FirmwareDatabase.FirmwareFilesByHash.Values)
{
if (seen.TryGetValue(ff.RecommendedName, out var ffExisting))
{
dupes.Add(ffExisting);
dupes.Add(ff);
}
else
{
seen.Add(ff.RecommendedName, ff);
}
}
if (dupes.Count is 0) return;
Assert.Fail($"multiple {nameof(FirmwareFile)}s have the same suggested filename (breaks Organize function):\n{
string.Join("\n", dupes.Select(static ff => $"\t{ff.RecommendedName} {ff.Hash}").Order())
}");
}
}
}

0 comments on commit 384b6f1

Please sign in to comment.