diff --git a/SabreTools.Matching.Test/Compare/NaturalComparerTests.cs b/SabreTools.Matching.Test/Compare/NaturalComparerTests.cs index 366ed54..f636593 100644 --- a/SabreTools.Matching.Test/Compare/NaturalComparerTests.cs +++ b/SabreTools.Matching.Test/Compare/NaturalComparerTests.cs @@ -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)); + } } } \ No newline at end of file diff --git a/SabreTools.Matching/Compare/NaturalComparer.cs b/SabreTools.Matching/Compare/NaturalComparer.cs index f297c25..5fb7d3b 100644 --- a/SabreTools.Matching/Compare/NaturalComparer.cs +++ b/SabreTools.Matching/Compare/NaturalComparer.cs @@ -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);