mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add RecalculateStats tests
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using SabreTools.DatItems;
|
using SabreTools.DatItems;
|
||||||
using SabreTools.DatItems.Formats;
|
using SabreTools.DatItems.Formats;
|
||||||
|
using SabreTools.Hashing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace SabreTools.DatFiles.Test
|
namespace SabreTools.DatFiles.Test
|
||||||
@@ -521,7 +522,40 @@ namespace SabreTools.DatFiles.Test
|
|||||||
|
|
||||||
#region RecalculateStats
|
#region RecalculateStats
|
||||||
|
|
||||||
// TODO: Add RecalculateStats tests
|
[Fact]
|
||||||
|
public void RecalculateStatsTest()
|
||||||
|
{
|
||||||
|
Source source = new Source(0, source: null);
|
||||||
|
|
||||||
|
Machine machine = new Machine();
|
||||||
|
machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, "machine");
|
||||||
|
|
||||||
|
DatItem item = new Rom();
|
||||||
|
item.SetName("rom");
|
||||||
|
item.SetFieldValue<long?>(Models.Metadata.Rom.SizeKey, 12345);
|
||||||
|
item.SetFieldValue<string?>(Models.Metadata.Rom.CRCKey, "deadbeef");
|
||||||
|
|
||||||
|
var dict = new ItemDictionaryDB();
|
||||||
|
long sourceIndex = dict.AddSource(source);
|
||||||
|
long machineIndex = dict.AddMachine(machine);
|
||||||
|
_ = dict.AddItem(item, machineIndex, sourceIndex, statsOnly: false);
|
||||||
|
|
||||||
|
Assert.Equal(1, dict.DatStatistics.TotalCount);
|
||||||
|
Assert.Equal(1, dict.DatStatistics.ItemCounts[ItemType.Rom]);
|
||||||
|
Assert.Equal(12345, dict.DatStatistics.TotalSize);
|
||||||
|
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.CRC32]);
|
||||||
|
Assert.Equal(0, dict.DatStatistics.HashCounts[HashType.MD5]);
|
||||||
|
|
||||||
|
item.SetFieldValue<string?>(Models.Metadata.Rom.MD5Key, "deadbeef");
|
||||||
|
|
||||||
|
dict.RecalculateStats();
|
||||||
|
|
||||||
|
Assert.Equal(1, dict.DatStatistics.TotalCount);
|
||||||
|
Assert.Equal(1, dict.DatStatistics.ItemCounts[ItemType.Rom]);
|
||||||
|
Assert.Equal(12345, dict.DatStatistics.TotalSize);
|
||||||
|
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.CRC32]);
|
||||||
|
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.MD5]);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using SabreTools.DatItems;
|
using SabreTools.DatItems;
|
||||||
using SabreTools.DatItems.Formats;
|
using SabreTools.DatItems.Formats;
|
||||||
|
using SabreTools.Hashing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace SabreTools.DatFiles.Test
|
namespace SabreTools.DatFiles.Test
|
||||||
@@ -360,7 +361,40 @@ namespace SabreTools.DatFiles.Test
|
|||||||
|
|
||||||
#region RecalculateStats
|
#region RecalculateStats
|
||||||
|
|
||||||
// TODO: Add RecalculateStats tests
|
[Fact]
|
||||||
|
public void RecalculateStatsTest()
|
||||||
|
{
|
||||||
|
Source source = new Source(0, source: null);
|
||||||
|
|
||||||
|
Machine machine = new Machine();
|
||||||
|
machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, "machine");
|
||||||
|
|
||||||
|
DatItem item = new Rom();
|
||||||
|
item.SetName("rom");
|
||||||
|
item.SetFieldValue<long?>(Models.Metadata.Rom.SizeKey, 12345);
|
||||||
|
item.SetFieldValue<string?>(Models.Metadata.Rom.CRCKey, "deadbeef");
|
||||||
|
item.SetFieldValue<Source?>(DatItem.SourceKey, source);
|
||||||
|
item.SetFieldValue<Machine?>(DatItem.MachineKey, machine);
|
||||||
|
|
||||||
|
var dict = new ItemDictionary();
|
||||||
|
_ = dict.AddItem(item, statsOnly: false);
|
||||||
|
|
||||||
|
Assert.Equal(1, dict.DatStatistics.TotalCount);
|
||||||
|
Assert.Equal(1, dict.DatStatistics.ItemCounts[ItemType.Rom]);
|
||||||
|
Assert.Equal(12345, dict.DatStatistics.TotalSize);
|
||||||
|
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.CRC32]);
|
||||||
|
Assert.Equal(0, dict.DatStatistics.HashCounts[HashType.MD5]);
|
||||||
|
|
||||||
|
item.SetFieldValue<string?>(Models.Metadata.Rom.MD5Key, "deadbeef");
|
||||||
|
|
||||||
|
dict.RecalculateStats();
|
||||||
|
|
||||||
|
Assert.Equal(1, dict.DatStatistics.TotalCount);
|
||||||
|
Assert.Equal(1, dict.DatStatistics.ItemCounts[ItemType.Rom]);
|
||||||
|
Assert.Equal(12345, dict.DatStatistics.TotalSize);
|
||||||
|
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.CRC32]);
|
||||||
|
Assert.Equal(1, dict.DatStatistics.HashCounts[HashType.MD5]);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user