public void GetHashCodeIsSameForEquivalentSubstrings() { const string s1 = "Hello"; const string s2 = "Hello"; var ss1 = new Substring(s1, 2); var ss2 = new Substring(s2, 2); ss1.GetHashCode().Should().Be(ss2.GetHashCode()); }
public void GetHashCodeIsDifferentForDifferentSubstrings() { var ss1 = new Substring("Hello", 2, 1); ss1.ToString().Should().Be("l"); var ss2 = new Substring("Hello", 3, 1); ss2.ToString().Should().Be("l"); ss1.GetHashCode().Should().NotBe(ss2.GetHashCode()); }
public override int GetHashCode() { return(Substring != null?Substring.GetHashCode() : 0); }