예제 #1
0
        public void CombineHashCodes()
        {
            Assert.AreEqual(76781240, HashCodeUtility.CombineHashCodes(0));
            Assert.AreEqual(1923623579, HashCodeUtility.CombineHashCodes(1));
            Assert.AreEqual(76781240, HashCodeUtility.CombineHashCodes(new[] { 0 }));

            Assert.AreEqual(1489077439, HashCodeUtility.CombineHashCodes(0, 0));
            Assert.AreEqual(-1105120207, HashCodeUtility.CombineHashCodes(0, 1));
            Assert.AreEqual(1489077439, HashCodeUtility.CombineHashCodes(new[] { 0, 0 }));

            Assert.AreEqual(459859287, HashCodeUtility.CombineHashCodes(0, 0, 0));
            Assert.AreEqual(-935278042, HashCodeUtility.CombineHashCodes(0, 0, 1));
            Assert.AreEqual(459859287, HashCodeUtility.CombineHashCodes(new[] { 0, 0, 0 }));

            Assert.AreEqual(-1158084724, HashCodeUtility.CombineHashCodes(0, 0, 0, 0));
            Assert.AreEqual(1498382024, HashCodeUtility.CombineHashCodes(0, 0, 0, 1));
            Assert.AreEqual(-1158084724, HashCodeUtility.CombineHashCodes(new[] { 0, 0, 0, 0 }));

            Assert.AreEqual(1762635120, HashCodeUtility.CombineHashCodes(0, 0, 0, 0, 0));
            Assert.AreEqual(951675744, HashCodeUtility.CombineHashCodes(0, 0, 0, 0, 1));
            Assert.AreEqual(1762635120, HashCodeUtility.CombineHashCodes(new[] { 0, 0, 0, 0, 0 }));

            Assert.AreEqual(1002546726, HashCodeUtility.CombineHashCodes(0, 0, 0, 0, 0, 0));
            Assert.AreEqual(-1323428179, HashCodeUtility.CombineHashCodes(0, 0, 0, 0, 0, 1));
            Assert.AreEqual(1002546726, HashCodeUtility.CombineHashCodes(new[] { 0, 0, 0, 0, 0, 0 }));

            Assert.AreEqual(-1222849262, HashCodeUtility.CombineHashCodes(0, 0, 0, 0, 0, 0, 0));
            Assert.AreEqual(1531490892, HashCodeUtility.CombineHashCodes(0, 0, 0, 0, 0, 0, 1));
            Assert.AreEqual(-1222849262, HashCodeUtility.CombineHashCodes(new[] { 0, 0, 0, 0, 0, 0, 0 }));
        }
예제 #2
0
 public override int GetHashCode()
 {
     return(HashCodeUtility.Combine(
                EqualityComparer <T> .Default.GetHashCode(Value),
                EqualityComparer <T2> .Default.GetHashCode(Value2)
                ));
 }
예제 #3
0
 private static string GetHashPostfix(string originalName)
 {
     // return a persistant hash code so that the code stays stable
     // and comparable between different compiler versions.
     // also 4 characters should suffice.
     return("_" + Math.Abs(HashCodeUtility.GetPersistentHashCode(originalName))
            .ToString("0000").Substring(0, 4));
 }
예제 #4
0
        public void CombineHashCodesDuplicate()
        {
            // test for bad hash code generation
            const string str = "happy";

            Assert.AreNotEqual(0, HashCodeUtility.CombineHashCodes(str.GetHashCode(), str.GetHashCode()));
            Assert.AreNotEqual(str.GetHashCode(), HashCodeUtility.CombineHashCodes(str.GetHashCode(), str.GetHashCode()));
        }
예제 #5
0
 public void GetPersistentIntHashCode(int nValue, int nExpected)
 {
     Assert.AreEqual(nExpected, HashCodeUtility.GetPersistentHashCode((sbyte)nValue));
     Assert.AreEqual(nExpected, HashCodeUtility.GetPersistentHashCode((short)nValue));
     if (nValue >= 0)
     {
         Assert.AreEqual(nExpected, HashCodeUtility.GetPersistentHashCode((char)nValue));
     }
     Assert.AreEqual(nExpected, HashCodeUtility.GetPersistentHashCode(nValue));
 }
 public void GetPersistentIntHashCode(int value, int expected)
 {
     Assert.That(HashCodeUtility.GetPersistentHashCode((sbyte)value), Is.EqualTo(expected));
     Assert.That(HashCodeUtility.GetPersistentHashCode((short)value), Is.EqualTo(expected));
     if (value >= 0)
     {
         Assert.That(HashCodeUtility.GetPersistentHashCode((char)value), Is.EqualTo(expected));
     }
     Assert.That(HashCodeUtility.GetPersistentHashCode(value), Is.EqualTo(expected));
 }
        /// <summary>
        /// Returns the hash code for this instance.
        /// </summary>
        /// <returns>
        /// A 32-bit signed integer hash code.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public override int GetHashCode()
        {
            unchecked
            {
                HashCodeUtility codeUtility = new HashCodeUtility();
                codeUtility.AddObject(this.Name.ToLowerInvariant());
                codeUtility.AddObject(this.InjectedType);

                int result = codeUtility.CombinedHash32;
                return(result);
            }
        }
        public void Should_generate_from_relative_uri()
        {
            var report = new ErrorReportEntity(1, "kffk", DateTime.UtcNow, new ErrorReportException(), new[]
            {
                new ErrorReportContextCollection("Yadayada",
                                                 new Dictionary <string, string>
                {
                    { "Url", "/some/path?hada=yada" },
                    { "HttpCode", "404" }
                })
            });

            var sut  = new HttpErrorGenerator();
            var code = sut.GenerateHashCode(report);

            var source = $"404;/some/path";

            code.HashCode.Should().Be(HashCodeUtility.GetPersistentHashCode(source).ToString("X"));
        }
예제 #9
0
 public void CombineHashCodesNull()
 {
     HashCodeUtility.CombineHashCodes(null);
 }
예제 #10
0
 public override int GetHashCode()
 {
     return(HashCodeUtility.GetHashCode(Full));
 }
예제 #11
0
 public override int GetHashCode()
 {
     return(HashCodeUtility.GetHashCode(Length, OpCode));
 }
예제 #12
0
 public void GetPersistentLongHashCode(long nValue, int nExpected)
 {
     Assert.AreEqual(nExpected, HashCodeUtility.GetPersistentHashCode(nValue));
 }
예제 #13
0
 public void GetPersistentBoolHashCode(bool value, int expected)
 {
     Assert.AreEqual(expected, HashCodeUtility.GetPersistentHashCode(value));
 }
예제 #14
0
 public void HashOne(int value)
 {
     Assert.That(HashCodeUtility.CombineHashCodes(value), Is.EqualTo(HashCodeUtility.CombineHashCodes(new[] { value })));
 }
예제 #15
0
 public override int GetHashCode()
 {
     return(unchecked (_rawData.Aggregate(0, (acc, b) => acc + HashCodeUtility.GetHashCode(b))));
 }
예제 #16
0
 /// <summary>
 /// Returns a hash code for the current object.
 /// </summary>
 /// <returns>A hash code for the current object.</returns>
 public override int GetHashCode()
 {
     // combine the hash codes of the various components of this class
     return(HashCodeUtility.CombineHashCodes(ObjectUtility.GetHashCode(m_text), m_count));
 }
예제 #17
0
 public override int GetHashCode()
 {
     return(unchecked (Family.GetHashCode() + _upperBoundary.Aggregate(0, (acc, b) => acc + HashCodeUtility.GetHashCode(b)) +
                       _lowerBoundary.Aggregate(0, (acc, b) => acc + HashCodeUtility.GetHashCode(b))));
 }
 public override int GetHashCode()
 {
     return(HashCodeUtility.Combine(_identifiers.Select(i => i.GetHashCode())));
 }
예제 #19
0
 public void GetPersistentHash(string value, int expected)
 {
     Assert.That(HashCodeUtility.GetPersistentHashCode(value), Is.EqualTo(expected));
 }
예제 #20
0
 public void HashFour(int value1, int value2, int value3, int value4)
 {
     Assert.That(HashCodeUtility.CombineHashCodes(value1, value2, value3, value4), Is.EqualTo(HashCodeUtility.CombineHashCodes(new[] { value1, value2, value3, value4 })));
 }
예제 #21
0
 public void HashThree(int value1, int value2, int value3)
 {
     Assert.That(HashCodeUtility.CombineHashCodes(value1, value2, value3), Is.EqualTo(HashCodeUtility.CombineHashCodes(new[] { value1, value2, value3 })));
 }
예제 #22
0
 public void HashTwo(int value1, int value2)
 {
     Assert.That(HashCodeUtility.CombineHashCodes(value1, value2), Is.EqualTo(HashCodeUtility.CombineHashCodes(new[] { value1, value2 })));
 }
예제 #23
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Returns a hash code for this instance.
 /// </summary>
 /// <returns>
 /// A hash code for this instance, suitable for use in hashing algorithms and data
 /// structures like a hash table.
 /// </returns>
 /// ------------------------------------------------------------------------------------
 public override int GetHashCode()
 {
     return(HashCodeUtility.CombineHashCodes(m_startRef.BBCCCVVV, m_endRef.BBCCCVVV,
                                             Text.GetHashCode(), TextStartIndex, TextLength, VerseStartIndex, Para.Hvo));
 }
예제 #24
0
 public override int GetHashCode()
 {
     return(HashCodeUtility.GetHashCode(Byte, SByte, UInt16, Int16, UInt32, Int32, UInt64, Int64, Char, Single, Double, Decimal));
 }
 public override int GetHashCode()
 {
     return(HashCodeUtility.CombineHashCodes(m_first, m_second, m_third));
 }
예제 #26
0
 public override int GetHashCode()
 {
     return(HashCodeUtility.CombineHashCodes(AttackerActionId.GetHashCode(), DefenderActionId.GetHashCode()));
 }