Does this make sense to anyone? Is it a bug in String.Compare()?
Given the following unit test:
<Test()>
Public Sub TestSortingAlgorithm()
Dim test1, test2, test3, test4 As String test1 = "'"
test2 = "*"
test3 = "',"
test4 = "*,"
Dim formatString As String = "Compare ""{0}"" to ""{1}"": Result: {2}.{3}" Dim Result1 As Integer = String.Compare(test1, test2) Dim Result2 As Integer = String.Compare(test3, test4) Debug.WriteLine(
String.Format(formatString, test1, test2, Result1, vbCrLf)) Debug.WriteLine(
String.Format(formatString, test3, test4, Result2, vbCrLf)) Assert.AreEqual(Result1, Result2, "It doesn't make sense that these two sets of strings should be sorted differently.")
End Sub Here is the output:
Compare "'" to "*": Result: -1.
Compare "'," to "*,": Result: 1.
TestCase 'TestFixture.TestSortingAlgorithm' failed: It doesn't make sense that these two sets of strings should be sorted differently.
expected:<-1>
but was:<1>
UPDATE:
The following SQL (by way of comparison)
DECLARE @Temp TABLE
(
string varchar(50)
)
INSERT INTO @Temp (string)
VALUES('''')
INSERT INTO @Temp (string)
VALUES('*')
INSERT INTO @Temp (string)
VALUES(''',')
INSERT INTO @Temp (string)
VALUES('*,')
SELECT *
FROM @Temp
ORDER BY String ASC
GO
Yields the following Output:
'
',
*
*,