mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add CompareTo tests and make changes
This commit is contained in:
@@ -128,7 +128,59 @@ namespace SabreTools.DatItems.Test
|
||||
|
||||
#region CompareTo
|
||||
|
||||
// TODO: Implement CompareTo tests
|
||||
[Fact]
|
||||
public void CompareTo_NullOther_Returns1()
|
||||
{
|
||||
DatItem self = new Rom();
|
||||
DatItem? other = null;
|
||||
|
||||
int actual = self.CompareTo(other);
|
||||
Assert.Equal(1, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CompareTo_DifferentOther_Returns1()
|
||||
{
|
||||
DatItem self = new Rom();
|
||||
self.SetName("name");
|
||||
|
||||
DatItem? other = new Disk();
|
||||
other.SetName("name");
|
||||
|
||||
int actual = self.CompareTo(other);
|
||||
Assert.Equal(1, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CompareTo_Empty_Returns1()
|
||||
{
|
||||
DatItem self = new Rom();
|
||||
DatItem? other = new Rom();
|
||||
|
||||
int actual = self.CompareTo(other);
|
||||
Assert.Equal(1, actual);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, null, 0)]
|
||||
[InlineData("name", null, 1)]
|
||||
[InlineData("name", "other", -1)]
|
||||
[InlineData(null, "name", -1)]
|
||||
[InlineData("other", "name", 1)]
|
||||
[InlineData("name", "name", 0)]
|
||||
public void CompareTo_NamesOnly(string? selfName, string? otherName, int expected)
|
||||
{
|
||||
DatItem self = new Rom();
|
||||
self.SetName(selfName);
|
||||
self.SetFieldValue(Models.Metadata.Rom.CRCKey, "DEADBEEF");
|
||||
|
||||
DatItem? other = new Rom();
|
||||
other.SetName(otherName);
|
||||
other.SetFieldValue(Models.Metadata.Rom.CRCKey, "DEADBEEF");
|
||||
|
||||
int actual = self.CompareTo(other);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -161,24 +161,17 @@ namespace SabreTools.DatItems
|
||||
if (other == null)
|
||||
return 1;
|
||||
|
||||
try
|
||||
{
|
||||
// Get the names to avoid changing values
|
||||
string? selfName = GetName();
|
||||
string? otherName = other.GetName();
|
||||
// Get the names to avoid changing values
|
||||
string? selfName = GetName();
|
||||
string? otherName = other.GetName();
|
||||
|
||||
// If the names are equal
|
||||
if (selfName == otherName)
|
||||
return Equals(other) ? 0 : 1;
|
||||
// If the names are equal
|
||||
if (selfName == otherName)
|
||||
return Equals(other) ? 0 : 1;
|
||||
|
||||
// If `otherName` is null, Compare will return > 0
|
||||
// If `selfName` is null, Compare will return < 0
|
||||
return string.Compare(selfName, otherName, StringComparison.Ordinal);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
// If `otherName` is null, Compare will return > 0
|
||||
// If `selfName` is null, Compare will return < 0
|
||||
return string.Compare(selfName, otherName, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -558,24 +551,17 @@ namespace SabreTools.DatItems
|
||||
if (other == null)
|
||||
return 1;
|
||||
|
||||
try
|
||||
{
|
||||
// Get the names to avoid changing values
|
||||
string? selfName = GetName();
|
||||
string? otherName = other.GetName();
|
||||
// Get the names to avoid changing values
|
||||
string? selfName = GetName();
|
||||
string? otherName = other.GetName();
|
||||
|
||||
// If the names are equal
|
||||
if (selfName == otherName)
|
||||
return Equals(other) ? 0 : 1;
|
||||
// If the names are equal
|
||||
if (selfName == otherName)
|
||||
return Equals(other) ? 0 : 1;
|
||||
|
||||
// If `otherName` is null, Compare will return > 0
|
||||
// If `selfName` is null, Compare will return < 0
|
||||
return string.Compare(selfName, otherName, StringComparison.Ordinal);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
// If `otherName` is null, Compare will return > 0
|
||||
// If `selfName` is null, Compare will return < 0
|
||||
return string.Compare(selfName, otherName, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user