mirror of
https://github.com/SabreTools/SabreTools.Matching.git
synced 2026-09-21 14:24:03 +00:00
Fix length-based comparison issue
This commit is contained in:
@@ -8,7 +8,7 @@ namespace SabreTools.Matching.Test.Compare
|
||||
public class NaturalComparerTests
|
||||
{
|
||||
[Fact]
|
||||
public void NaturalComparer_ListSortTest()
|
||||
public void NaturalComparer_ListSort_Numeric()
|
||||
{
|
||||
// Setup arrays
|
||||
string[] sortable = ["0", "100", "5", "2", "1000"];
|
||||
@@ -22,7 +22,21 @@ namespace SabreTools.Matching.Test.Compare
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NaturalReversedComparer_ListSortTest()
|
||||
public void NaturalComparer_ListSort_Mixed()
|
||||
{
|
||||
// Setup arrays
|
||||
string[] sortable = ["b3b", "c", "b", "a", "a1"];
|
||||
string[] expected = ["a", "a1", "b", "b3b", "c"];
|
||||
|
||||
// Run sorting on array
|
||||
Array.Sort(sortable, new NaturalComparer());
|
||||
|
||||
// Check the output
|
||||
Assert.True(sortable.SequenceEqual(expected));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NaturalReversedComparer_ListSort_Numeric()
|
||||
{
|
||||
// Setup arrays
|
||||
string[] sortable = ["0", "100", "5", "2", "1000"];
|
||||
@@ -34,5 +48,19 @@ namespace SabreTools.Matching.Test.Compare
|
||||
// Check the output
|
||||
Assert.True(sortable.SequenceEqual(expected));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NaturalReversedComparer_ListSort_Mixed()
|
||||
{
|
||||
// Setup arrays
|
||||
string[] sortable = ["b3b", "c", "b", "a", "a1"];
|
||||
string[] expected = ["c", "b3b", "b", "a1", "a"];
|
||||
|
||||
// Run sorting on array
|
||||
Array.Sort(sortable, new NaturalReversedComparer());
|
||||
|
||||
// Check the output
|
||||
Assert.True(sortable.SequenceEqual(expected));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,9 +66,9 @@ namespace SabreTools.Matching.Compare
|
||||
return PartCompare(x1[i], y1[i]);
|
||||
}
|
||||
|
||||
if (y1.Length > x1.Length)
|
||||
if (x1.Length > y1.Length)
|
||||
return 1;
|
||||
else if (x1.Length > y1.Length)
|
||||
else if (y1.Length > x1.Length)
|
||||
return -1;
|
||||
else
|
||||
return x.CompareTo(y);
|
||||
|
||||
Reference in New Issue
Block a user