mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add GetMachine and GetSource GetItem DB tests, fix
This commit is contained in:
@@ -112,7 +112,22 @@ namespace SabreTools.DatFiles.Test
|
|||||||
|
|
||||||
#region GetMachineForItem
|
#region GetMachineForItem
|
||||||
|
|
||||||
// TODO: Add GetMachineForItem tests
|
[Fact]
|
||||||
|
public void GetMachineForItemTest()
|
||||||
|
{
|
||||||
|
Source source = new Source(0, source: null);
|
||||||
|
Machine machine = new Machine();
|
||||||
|
DatItem item = new Rom();
|
||||||
|
|
||||||
|
var dict = new ItemDictionaryDB();
|
||||||
|
long machineIndex = dict.AddMachine(machine);
|
||||||
|
long sourceIndex = dict.AddSource(source);
|
||||||
|
long itemIndex = dict.AddItem(item, machineIndex, sourceIndex);
|
||||||
|
|
||||||
|
var actual = dict.GetMachineForItem(itemIndex);
|
||||||
|
Assert.Equal(0, actual.Key);
|
||||||
|
Assert.NotNull(actual.Value);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -134,7 +149,22 @@ namespace SabreTools.DatFiles.Test
|
|||||||
|
|
||||||
#region GetSourceForItem
|
#region GetSourceForItem
|
||||||
|
|
||||||
// TODO: Add GetSourceForItem tests
|
[Fact]
|
||||||
|
public void GetSourceForItemTest()
|
||||||
|
{
|
||||||
|
Source source = new Source(0, source: null);
|
||||||
|
Machine machine = new Machine();
|
||||||
|
DatItem item = new Rom();
|
||||||
|
|
||||||
|
var dict = new ItemDictionaryDB();
|
||||||
|
long machineIndex = dict.AddMachine(machine);
|
||||||
|
long sourceIndex = dict.AddSource(source);
|
||||||
|
long itemIndex = dict.AddItem(item, machineIndex, sourceIndex);
|
||||||
|
|
||||||
|
var actual = dict.GetSourceForItem(itemIndex);
|
||||||
|
Assert.Equal(0, actual.Key);
|
||||||
|
Assert.NotNull(actual.Value);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -421,7 +421,6 @@ namespace SabreTools.DatFiles
|
|||||||
|
|
||||||
var machine = _machines[machineIndex];
|
var machine = _machines[machineIndex];
|
||||||
return new KeyValuePair<long, Machine?>(machineIndex, machine);
|
return new KeyValuePair<long, Machine?>(machineIndex, machine);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,6 +445,15 @@ namespace SabreTools.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public KeyValuePair<long, Source?> GetSourceForItem(long itemIndex)
|
public KeyValuePair<long, Source?> GetSourceForItem(long itemIndex)
|
||||||
{
|
{
|
||||||
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
|
if (!_itemToSourceMapping.TryGetValue(itemIndex, out long sourceIndex))
|
||||||
|
return new KeyValuePair<long, Source?>(-1, null);
|
||||||
|
|
||||||
|
if (!_sources.TryGetValue(sourceIndex, out var source))
|
||||||
|
return new KeyValuePair<long, Source?>(-1, null);
|
||||||
|
|
||||||
|
return new KeyValuePair<long, Source?>(sourceIndex, source);
|
||||||
|
#else
|
||||||
if (!_itemToSourceMapping.ContainsKey(itemIndex))
|
if (!_itemToSourceMapping.ContainsKey(itemIndex))
|
||||||
return new KeyValuePair<long, Source?>(-1, null);
|
return new KeyValuePair<long, Source?>(-1, null);
|
||||||
|
|
||||||
@@ -453,7 +461,9 @@ namespace SabreTools.DatFiles
|
|||||||
if (!_sources.ContainsKey(sourceIndex))
|
if (!_sources.ContainsKey(sourceIndex))
|
||||||
return new KeyValuePair<long, Source?>(-1, null);
|
return new KeyValuePair<long, Source?>(-1, null);
|
||||||
|
|
||||||
return new KeyValuePair<long, Source?>(sourceIndex, _sources[sourceIndex]);
|
var source = _sources[sourceIndex];
|
||||||
|
return new KeyValuePair<long, Source?>(sourceIndex, source);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -612,7 +622,7 @@ namespace SabreTools.DatFiles
|
|||||||
PerformItemBucketing(index, _bucketedBy, lower: true, norename: true);
|
PerformItemBucketing(index, _bucketedBy, lower: true, norename: true);
|
||||||
|
|
||||||
// Return the used index
|
// Return the used index
|
||||||
return index - 1;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user