コード例 #1
0
ファイル: Sha256HashTests.cs プロジェクト: w1r2p1/Paymetheus
        public static void HasReferenceSemantics()
        {
            var firstArray  = new byte[Sha256Hash.Length];
            var secondArray = new byte[Sha256Hash.Length];

            for (var i = 0; i < Sha256Hash.Length; i++)
            {
                firstArray[i]  = (byte)i;
                secondArray[i] = (byte)i;
            }

            var firstHash  = new Sha256Hash(firstArray);
            var secondHash = new Sha256Hash(secondArray);

            // Value equality
            Assert.Equal(firstHash, secondHash);
            Assert.True(firstHash.Equals(secondHash));
            Assert.Equal(firstHash.GetHashCode(), secondHash.GetHashCode());

            // Reference equality
            Assert.False(firstHash == secondHash);

            var hashSet = new HashSet <Sha256Hash> {
                firstHash
            };

            Assert.True(hashSet.Contains(secondHash));
        }
コード例 #2
0
        public static void HasReferenceSemantics()
        {
            var firstArray = new byte[Sha256Hash.Length];
            var secondArray = new byte[Sha256Hash.Length];

            for (var i = 0; i < Sha256Hash.Length; i++)
            {
                firstArray[i] = (byte)i;
                secondArray[i] = (byte)i;
            }

            var firstHash = new Sha256Hash(firstArray);
            var secondHash = new Sha256Hash(secondArray);

            // Value equality
            Assert.Equal(firstHash, secondHash);
            Assert.True(firstHash.Equals(secondHash));
            Assert.Equal(firstHash.GetHashCode(), secondHash.GetHashCode());

            // Reference equality
            Assert.False(firstHash == secondHash);

            var hashSet = new HashSet<Sha256Hash> { firstHash };
            Assert.True(hashSet.Contains(secondHash));
        }