public void PaddedShouldNotEqualShort()
        {
            var v1 = new TypedValue(NHibernateUtil.Int32, ToLazyEnumerable(3, 2, 1, 0, 0, 0), true);
            var v2 = new TypedValue(NHibernateUtil.Int32, ToLazyEnumerable(3, 2, 1, 0), true);

            Warn.If(v1.GetHashCode(), Is.EqualTo(v2.GetHashCode()), "Equal hash codes");
            Assert.That(v1, Is.Not.EqualTo(v2));
        }
        public void ShortShouldNotEqualLonger()
        {
            var v1 = new TypedValue(NHibernateUtil.Int32, ToLazyEnumerable(1, 2, 3), true);
            var v2 = new TypedValue(NHibernateUtil.Int32, ToLazyEnumerable(1, 2, 3, 1, -1), true);

            Warn.If(v1.GetHashCode(), Is.EqualTo(v2.GetHashCode()), "Equal hash codes");
            Assert.That(v1, Is.Not.EqualTo(v2));
        }
        public void TestTypedValue()
        {
            var tv1 = new TypedValue("hello");
            var tv2 = new TypedValue("hello");
            var tv3 = new TypedValue("bye");

            Assert.Equal(typeof(string), tv1.TypeDescriptor);
            Assert.Equal("TypedValue: 'hello' of [System.String]", tv1.ToString());
            Assert.Equal(tv1, tv2);
            Assert.Equal(tv2, tv1);
            Assert.NotEqual(tv1, tv3);
            Assert.NotEqual(tv2, tv3);
            Assert.NotEqual(tv3, tv1);
            Assert.NotEqual(tv3, tv2);
            Assert.Equal(tv1.GetHashCode(), tv2.GetHashCode());
            Assert.NotEqual(tv1.GetHashCode(), tv3.GetHashCode());
            Assert.NotEqual(tv2.GetHashCode(), tv3.GetHashCode());
        }
Example #4
0
 // it's not directly suit for hashtable, because it's always calculating address
 public override int GetHashCode()
 {
     if (_hashcode != -1)
     {
         return(_hashcode);
     }
     _hashcode = 0;  // indicate it's changed. even the calculated hashcode below is 0
     for (int i = 0; i < _ks.Length; i++)
     {
         // extract its primitive value to calculate hashcode
         // decimal is handled differently to enable among different CLR types
         _ks[i].SetDecimal();
         if (_ks[i].IsDecimal)
         {
             for (int j = 0; j < _ks[i].Dim; j++)
             {
                 _hashcode += _ks[i].Dvalue[j].GetHashCode();
             }
         }
         // BUGBUG: will need to change below parts, using canonical presentation.
         else
         {
             if (_ks[i].Value is Array arr)
             {
                 XmlAtomicValue[]? atomicValues = arr as XmlAtomicValue[];
                 if (atomicValues != null)
                 {
                     for (int j = 0; j < atomicValues.Length; j++)
                     {
                         _hashcode += ((XmlAtomicValue)atomicValues.GetValue(j) !).TypedValue.GetHashCode();
                     }
                 }
                 else
                 {
                     for (int j = 0; j < ((Array)_ks[i].Value !).Length; j++)
                     {
                         _hashcode += ((Array)_ks[i].Value !).GetValue(j) !.GetHashCode();
                     }
                 }
             }
             else
             { //not a list
                 _hashcode += _ks[i].Value !.GetHashCode();
             }
         }
     }
     return(_hashcode);
 }
Example #5
0
 public override int GetHashCode() => TypedValue.GetHashCode();