public override int GetHashCode()
 {
     unchecked
     {
         return((Candidate?.GetHashCode() ?? 0) * 397);
     }
 }
Example #2
0
        public void Equals_CaseInsensitive(string expectedName, string actualName)
        {
            // set up
            var expected = new Candidate(expectedName);

            // act
            var actual = new Candidate(actualName);

            // assert
            if (StringComparer.OrdinalIgnoreCase.Equals(expectedName, actualName))
            {
                Assert.Equal(expectedName, actualName, ignoreCase: true);
                Assert.Equal(expected, actual);
                Assert.True(expected.Equals((Candidate)actual));
                Assert.True(expected.Equals((object)actual));
                Assert.True(expected == actual);
                Assert.False(expected != actual);

                // hashcode should always be the same for two objects that are equal
                Assert.Equal(expected.GetHashCode(), actual.GetHashCode());
            }
            else
            {
                Assert.NotEqual(expectedName, actualName, StringComparer.OrdinalIgnoreCase);
                Assert.NotEqual(expected, actual);
                Assert.False(expected.Equals((Candidate)actual));
                Assert.False(expected.Equals((object)actual));
                Assert.False(expected == actual);
                Assert.True(expected != actual);
                // hashcode is not guaranteed different for unequal objects
            }
        }
Example #3
0
    public override int GetHashCode()
    {
        int hash = 1;

        if (Candidate.Length != 0)
        {
            hash ^= Candidate.GetHashCode();
        }
        if (PhraseId != 0L)
        {
            hash ^= PhraseId.GetHashCode();
        }
        if (Score != 0D)
        {
            hash ^= Score.GetHashCode();
        }
        return(hash);
    }