예제 #1
0
        public static void TreeId_equality()
        {
            var treeId1 = new TreeId(Sha1.Hash("abc"));
            var treeId2 = new TreeId(Sha1.Hash("abc"));
            var treeId3 = new TreeId(Sha1.Hash("def"));

            Assert.True(treeId1 == treeId2);
            Assert.False(treeId1 != treeId2);
            Assert.True(treeId1.Equals((object)treeId2));

            Assert.Equal(treeId1.Sha1.ToString(), treeId1.ToString());
            Assert.Equal(treeId2.Sha1.ToString(), treeId2.ToString());
            Assert.Equal(treeId3.Sha1.ToString(), treeId3.ToString());

            Assert.Equal(treeId1, treeId2);
            Assert.Equal(treeId1.GetHashCode(), treeId2.GetHashCode());
            Assert.Equal(treeId1.ToString(), treeId2.ToString());

            Assert.NotEqual(TreeId.Empty, treeId1);
            Assert.NotEqual(TreeId.Empty.GetHashCode(), treeId1.GetHashCode());
            Assert.NotEqual(TreeId.Empty.ToString(), treeId1.ToString());

            Assert.NotEqual(treeId3, treeId1);
            Assert.NotEqual(treeId3.GetHashCode(), treeId1.GetHashCode());
            Assert.NotEqual(treeId3.ToString(), treeId1.ToString());
        }
예제 #2
0
        public override int GetHashCode()
        {
            int hash = 1;

            hash ^= parents_.GetHashCode();
            if (treeId_ != null)
            {
                hash ^= TreeId.GetHashCode();
            }
            if (author_ != null)
            {
                hash ^= Author.GetHashCode();
            }
            if (committer_ != null)
            {
                hash ^= Committer.GetHashCode();
            }
            if (Message.Length != 0)
            {
                hash ^= Message.GetHashCode();
            }
            return(hash);
        }