public void SortKeyMiscTest() { CompareInfo ci = new CultureInfo("en-US").CompareInfo; string s1 = "abc"; string s2 = "ABC"; SortKey sk1 = ci.GetSortKey(s1); SortKey sk2 = ci.GetSortKey(s1); SortKey sk3 = ci.GetSortKey(s2); SortKey sk4 = ci.GetSortKey(s2, CompareOptions.IgnoreCase); SortKey sk5 = ci.GetSortKey(s1, CompareOptions.IgnoreCase); Assert.Equal(sk2, sk1); Assert.Equal(sk2.GetHashCode(), sk1.GetHashCode()); Assert.Equal(sk2.KeyData, sk1.KeyData); Assert.NotEqual(sk3, sk1); Assert.NotEqual(sk3.GetHashCode(), sk1.GetHashCode()); Assert.NotEqual(sk3.KeyData, sk1.KeyData); Assert.NotEqual(sk4, sk3); Assert.NotEqual(sk4.GetHashCode(), sk3.GetHashCode()); Assert.NotEqual(sk4.KeyData, sk3.KeyData); Assert.Equal(sk4, sk5); Assert.Equal(sk4.GetHashCode(), sk5.GetHashCode()); Assert.Equal(sk4.KeyData, sk5.KeyData); Assert.False(sk1.Equals(null)); Assert.True(sk1.Equals(sk1)); AssertExtensions.Throws <ArgumentNullException>("source", () => ci.GetSortKey(null)); AssertExtensions.Throws <ArgumentException>("options", () => ci.GetSortKey(s1, CompareOptions.Ordinal)); }
public void SortKeyTest(CompareInfo compareInfo, string string1, string string2, CompareOptions options, int expectedSign) { SortKey sk1 = compareInfo.GetSortKey(string1, options); SortKey sk2 = compareInfo.GetSortKey(string2, options); Assert.Equal(expectedSign, Math.Sign(SortKey.Compare(sk1, sk2))); Assert.Equal(expectedSign == 0, sk1.Equals(sk2)); if (!WindowsVersionHasTheCompareStringRegression) { Assert.Equal(Math.Sign(compareInfo.Compare(string1, string2, options)), Math.Sign(SortKey.Compare(sk1, sk2))); } Assert.Equal(compareInfo.GetHashCode(string1, options), sk1.GetHashCode()); Assert.Equal(compareInfo.GetHashCode(string2, options), sk2.GetHashCode()); Assert.Equal(string1, sk1.OriginalString); Assert.Equal(string2, sk2.OriginalString); // Now try the span-based versions - use BoundedMemory to detect buffer overruns RunSpanSortKeyTest(compareInfo, string1, options, sk1.KeyData); RunSpanSortKeyTest(compareInfo, string2, options, sk2.KeyData); unsafe static void RunSpanSortKeyTest(CompareInfo compareInfo, ReadOnlySpan <char> source, CompareOptions options, byte[] expectedSortKey)
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns> /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// </returns> public override int GetHashCode() { var hashCode = -329965925; hashCode = hashCode * -1521134295 + SortKey.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <Texture2D> .Default.GetHashCode(Texture); hashCode = hashCode * -1521134295 + EqualityComparer <VertexPositionColorTexture[]> .Default.GetHashCode(actualPositions); return(hashCode); }
public void SortKeyTest(CompareInfo compareInfo, string string1, string string2, CompareOptions options, int expectedSign) { SortKey sk1 = compareInfo.GetSortKey(string1, options); SortKey sk2 = compareInfo.GetSortKey(string2, options); Assert.Equal(expectedSign, Math.Sign(SortKey.Compare(sk1, sk2))); Assert.Equal(expectedSign == 0, sk1.Equals(sk2)); Assert.Equal(Math.Sign(compareInfo.Compare(string1, string2, options)), Math.Sign(SortKey.Compare(sk1, sk2))); Assert.Equal(compareInfo.GetHashCode(string1, options), sk1.GetHashCode()); Assert.Equal(compareInfo.GetHashCode(string2, options), sk2.GetHashCode()); Assert.Equal(string1, sk1.OriginalString); Assert.Equal(string2, sk2.OriginalString); }
/// <summary> /// Get the hashcode of this object. /// </summary> public override Int32 GetHashCode() => SortKey.GetHashCode();