提交 16219e30 编写于 作者: V vladres

Remove some invalid GetHashCode tests, put the other under #if (changeset 1407835)

上级 af1b89e8
...@@ -1571,8 +1571,10 @@ class C<T, U, V> ...@@ -1571,8 +1571,10 @@ class C<T, U, V>
Assert.Equal(actualTypeParameters[0].GetHashCode(), actualTypeParameters[1].GetHashCode()); Assert.Equal(actualTypeParameters[0].GetHashCode(), actualTypeParameters[1].GetHashCode());
Assert.NotEqual(actualTypeParameters[0], actualTypeParameters[2]); Assert.NotEqual(actualTypeParameters[0], actualTypeParameters[2]);
Assert.NotEqual(actualTypeParameters[0].GetHashCode(), actualTypeParameters[2].GetHashCode());
#if !DISABLE_GOOD_HASH_TESTS
Assert.NotEqual(actualTypeParameters[0].GetHashCode(), actualTypeParameters[2].GetHashCode());
#endif
} }
[Fact] [Fact]
......
...@@ -134,19 +134,29 @@ public void ConstantValueGetHashCodeTest01() ...@@ -134,19 +134,29 @@ public void ConstantValueGetHashCodeTest01()
var cv82 = ConstantValue.Create((ulong)123456789); var cv82 = ConstantValue.Create((ulong)123456789);
Assert.Equal(cv81.GetHashCode(), cv82.GetHashCode()); Assert.Equal(cv81.GetHashCode(), cv82.GetHashCode());
cv11 = ConstantValue.Create("123"); var cv91 = ConstantValue.Create(1.1m);
cv12 = ConstantValue.Create("321"); var cv92 = ConstantValue.Create(1.1m);
Assert.NotEqual(cv11.GetHashCode(), cv12.GetHashCode()); Assert.Equal(cv91.GetHashCode(), cv92.GetHashCode());
}
cv11 = ConstantValue.Create(1.1m); // In general, different values are not required to have different hash codes.
cv12 = ConstantValue.Create(1.1m); // But for perf reasons we want hash functions with a good distribution,
Assert.Equal(cv11.GetHashCode(), cv12.GetHashCode()); // so we expect hash codes to differ if a single component is incremented.
// But program correctness should be preserved even with a null hash function,
// so we need a way to disable these tests during such correctness validation.
#if !DISABLE_GOOD_HASH_TESTS
[Fact]
public void ConstantValueGetHashCodeTest02()
{
var cv1 = ConstantValue.Create("1");
var cv2 = ConstantValue.Create("2");
cv11 = ConstantValue.Create(DateTime.Now); Assert.NotEqual(cv1.GetHashCode(), cv2.GetHashCode());
cv12 = ConstantValue.Create(new DateTime());
Assert.NotEqual(cv11.GetHashCode(), cv12.GetHashCode());
} }
#endif
[Fact] [Fact]
public void ConstantValueToStringTest01() public void ConstantValueToStringTest01()
{ {
......
...@@ -50,22 +50,32 @@ public void Ctor1() ...@@ -50,22 +50,32 @@ public void Ctor1()
}); });
} }
// In general, different values are not required to have different hash codes.
// But for perf reasons we want hash functions with a good distribution,
// so we expect hash codes to differ if a single component is incremented.
// But program correctness should be preserved even with a null hash function,
// so we need a way to disable these tests during such correctness validation.
#if !DISABLE_GOOD_HASH_TESTS
[Fact] [Fact]
public void SaneHashCode() public void SaneHashCode()
{ {
var hash1 = new FileLinePositionSpan("C:\\foo.cs", new LinePosition(1, 2), new LinePosition(3, 5)).GetHashCode(); var hash1 = new FileLinePositionSpan("C:\\foo.cs", new LinePosition(1, 2), new LinePosition(3, 5)).GetHashCode();
var hash2 = new FileLinePositionSpan("C:\\foo1.cs", new LinePosition(1, 2), new LinePosition(3, 5)).GetHashCode(); var hash2 = new FileLinePositionSpan("C:\\foo1.cs", new LinePosition(1, 2), new LinePosition(3, 5)).GetHashCode();
var hash3 = new FileLinePositionSpan("C:\\foo.cs", new LinePosition(1, 3), new LinePosition(3, 5)).GetHashCode(); var hash3 = new FileLinePositionSpan("C:\\foo.cs", new LinePosition(1, 3), new LinePosition(3, 5)).GetHashCode();
var hash4 = new FileLinePositionSpan("C:\\foo.cs", new LinePosition(1, 1), new LinePosition(6, 5)).GetHashCode(); var hash4 = new FileLinePositionSpan("C:\\foo.cs", new LinePosition(1, 2), new LinePosition(6, 5)).GetHashCode();
var hash5 = new FileLinePositionSpan("C:\\foo.cs", new LinePosition(2, 2), new LinePosition(6, 5)).GetHashCode();
var hash6 = new FileLinePositionSpan("C:\\foo.cs", new LinePosition(2, 2), new LinePosition(6, 8)).GetHashCode();
Assert.NotEqual(hash1, hash2); Assert.NotEqual(hash1, hash2);
Assert.NotEqual(hash1, hash3); Assert.NotEqual(hash1, hash3);
Assert.NotEqual(hash1, hash4);
Assert.NotEqual(hash2, hash3);
Assert.NotEqual(hash2, hash4);
Assert.NotEqual(hash3, hash4); Assert.NotEqual(hash3, hash4);
Assert.NotEqual(hash4, hash5);
Assert.NotEqual(hash6, hash6);
} }
#endif
[Fact] [Fact]
public void TestToString() public void TestToString()
{ {
......
...@@ -45,6 +45,13 @@ public void Ctor3() ...@@ -45,6 +45,13 @@ public void Ctor3()
Assert.Equal(13, lp.Character); Assert.Equal(13, lp.Character);
} }
// In general, different values are not required to have different hash codes.
// But for perf reasons we want hash functions with a good distribution,
// so we expect hash codes to differ if a single component is incremented.
// But program correctness should be preserved even with a null hash function,
// so we need a way to disable these tests during such correctness validation.
#if !DISABLE_GOOD_HASH_TESTS
[Fact] [Fact]
public void SaneHashCode() public void SaneHashCode()
{ {
...@@ -61,6 +68,8 @@ public void SaneHashCode() ...@@ -61,6 +68,8 @@ public void SaneHashCode()
Assert.NotEqual(hash3, hash4); Assert.NotEqual(hash3, hash4);
} }
#endif
[Fact] [Fact]
public void CompareTo() public void CompareTo()
{ {
......
...@@ -422,7 +422,6 @@ public void Fusion_TestEquals() ...@@ -422,7 +422,6 @@ public void Fusion_TestEquals()
policy2 = FusionAssemblyPortabilityPolicy.LoadFromFile(appConfig.Path); policy2 = FusionAssemblyPortabilityPolicy.LoadFromFile(appConfig.Path);
Assert.NotEqual(policy1, policy2); Assert.NotEqual(policy1, policy2);
Assert.NotEqual(policy1.GetHashCode(), policy2.GetHashCode());
var appConfig2 = Temp.CreateFile().WriteAllText(correctAppConfigText); var appConfig2 = Temp.CreateFile().WriteAllText(correctAppConfigText);
......
...@@ -434,7 +434,6 @@ End Class ...@@ -434,7 +434,6 @@ End Class
Assert.Null(method1Ret.ContainingSymbol) Assert.Null(method1Ret.ContainingSymbol)
Assert.Equal(ImmutableArray.Create(Of Location)(), method1Ret.Locations) Assert.Equal(ImmutableArray.Create(Of Location)(), method1Ret.Locations)
Assert.Equal(ImmutableArray.Create(Of SyntaxReference)(), method1Ret.DeclaringSyntaxReferences) Assert.Equal(ImmutableArray.Create(Of SyntaxReference)(), method1Ret.DeclaringSyntaxReferences)
Assert.NotEqual(0, method1Ret.GetHashCode)
Assert.True(classA.IsMustInherit) Assert.True(classA.IsMustInherit)
Assert.Equal(Accessibility.Public, classA.DeclaredAccessibility) Assert.Equal(Accessibility.Public, classA.DeclaredAccessibility)
......
...@@ -1617,15 +1617,6 @@ End Class ...@@ -1617,15 +1617,6 @@ End Class
Assert.NotEqual(mca1, Copymca1) Assert.NotEqual(mca1, Copymca1)
Assert.Equal(mca1.ToString, Copymca1.ToString) Assert.Equal(mca1.ToString, Copymca1.ToString)
Assert.Equal(mca1.Kind, Copymca1.Kind) Assert.Equal(mca1.Kind, Copymca1.Kind)
'With no alias this will result in hashcode of 0
Dim mrp1 As MetadataReferenceProperties = refa.Properties
Assert.Equal(0, mrp1.GetHashCode)
'With the use of the alias this will generate a hashcode
Dim refb = AssemblyMetadata.CreateFromImage(a.EmitToArray()).GetReference(display:="A", aliases:=ImmutableArray.Create("Alias1"))
Dim mrp2 As MetadataReferenceProperties = refb.Properties
Assert.NotEqual(0, mrp2.GetHashCode)
End Sub End Sub
<Fact, WorkItem(905495, "DevDiv")> <Fact, WorkItem(905495, "DevDiv")>
......
...@@ -2179,7 +2179,6 @@ Module M ...@@ -2179,7 +2179,6 @@ Module M
Assert.True(conv3 <> conv2, "Check equality implementation") Assert.True(conv3 <> conv2, "Check equality implementation")
Assert.False(conv3.Equals(conv2), "Check equality implementation") Assert.False(conv3.Equals(conv2), "Check equality implementation")
Assert.False(conv3.Equals(DirectCast(conv2, Object)), "Check equality implementation") Assert.False(conv3.Equals(DirectCast(conv2, Object)), "Check equality implementation")
Assert.False(conv3.GetHashCode() = conv2.GetHashCode(), "Check equality implementation")
CompilationUtils.AssertNoErrors(compilation) CompilationUtils.AssertNoErrors(compilation)
End Sub End Sub
......
...@@ -133,9 +133,10 @@ End Namespace ...@@ -133,9 +133,10 @@ End Namespace
Assert.Same(delegateB, delegateB.TypeParameters(0).ContainingSymbol) Assert.Same(delegateB, delegateB.TypeParameters(0).ContainingSymbol)
Assert.Equal(1, delegateB.Locations.Length()) Assert.Equal(1, delegateB.Locations.Length())
Assert.Equal("System.MulticastDelegate", delegateB.BaseType.ToTestDisplayString()) Assert.Equal("System.MulticastDelegate", delegateB.BaseType.ToTestDisplayString())
Assert.NotEqual(0, IdentifierComparison.GetHashCode("B"))
Assert.NotEqual(0, IdentifierComparison.GetHashCode("A")) #If Not DISABLE_GOOD_HASH_TESTS Then
Assert.NotEqual(IdentifierComparison.GetHashCode("A"), IdentifierComparison.GetHashCode("B")) Assert.NotEqual(IdentifierComparison.GetHashCode("A"), IdentifierComparison.GetHashCode("B"))
#End If
Dim enumE = DirectCast(membersOfN(2), NamedTypeSymbol) Dim enumE = DirectCast(membersOfN(2), NamedTypeSymbol)
Assert.Equal(nsN.GetTypeMembers("E", 0).First(), enumE) Assert.Equal(nsN.GetTypeMembers("E", 0).First(), enumE)
Assert.Equal(nsN, enumE.ContainingSymbol) Assert.Equal(nsN, enumE.ContainingSymbol)
......
...@@ -5,9 +5,9 @@ Imports System.Xml.Linq ...@@ -5,9 +5,9 @@ Imports System.Xml.Linq
Imports Microsoft.CodeAnalysis.Test.Utilities Imports Microsoft.CodeAnalysis.Test.Utilities
Imports Microsoft.CodeAnalysis.VisualBasic Imports Microsoft.CodeAnalysis.VisualBasic
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports Roslyn.Test.Utilities Imports Roslyn.Test.Utilities
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE
Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests
...@@ -22244,7 +22244,6 @@ End Class ...@@ -22244,7 +22244,6 @@ End Class
Assert.Equal("B", errTypeSym.Name) Assert.Equal("B", errTypeSym.Name)
Assert.Equal(0, errTypeSym.TypeArguments.Length) Assert.Equal(0, errTypeSym.TypeArguments.Length)
Assert.Equal(0, errTypeSym.TypeParameters.Length) Assert.Equal(0, errTypeSym.TypeParameters.Length)
Assert.NotEqual(0, errTypeSym.GetHashCode)
Assert.Equal(errTypeSym.CandidateSymbols.Length, errTypeSym.IErrorTypeSymbol_CandidateSymbols.Length) Assert.Equal(errTypeSym.CandidateSymbols.Length, errTypeSym.IErrorTypeSymbol_CandidateSymbols.Length)
End Sub End Sub
......
...@@ -110,8 +110,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests ...@@ -110,8 +110,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests
Loop Loop
End If End If
Assert.NotEqual(0, children.GetHashCode)
Assert.NotEqual(0, children.Reverse.GetHashCode)
Dim b1 As Integer = 0 Dim b1 As Integer = 0
Dim enumerator = children.GetEnumerator Dim enumerator = children.GetEnumerator
enumerator.Reset() enumerator.Reset()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册