Beispiel #1
0
 public static void EqualsTest(UInt128 i1, object obj, bool expected)
 {
     if (obj is UInt128 i2)
     {
         Assert.Equal(expected, i1.Equals(i2));
         Assert.Equal(expected, i1.GetHashCode().Equals(i2.GetHashCode()));
     }
     Assert.Equal(expected, i1.Equals(obj));
 }
Beispiel #2
0
        public void UInt128Test()
        {
            Random random = new Random();

            for (int i = 0; i != 1000; ++i)
            {
                UInt128 value = random.NextUInt128();

                // Test comparisons.
                Assert.AreEqual(value, value);
                Assert.AreNotEqual(value, string.Empty);
                Assert.AreNotEqual(value, UInt128.MaxValue);
                Assert.AreNotEqual(value, UInt128.Zero);
                // ReSharper disable EqualExpressionComparison
                Assert.IsTrue(value == value);
                Assert.IsFalse(value != value);
                Assert.IsTrue(value <= value);
                Assert.IsTrue(value >= value);
                // ReSharper restore EqualExpressionComparison
                if (value != UInt128.MaxValue)
                {
                    Assert.IsTrue(value < value + 1);
                    Assert.IsTrue(value <= value + 1);
                    Assert.IsTrue(value + 1 > value);
                    Assert.IsTrue(value + 1 >= value);
                }

                // Test GetHashCode
                Assert.IsNotNull(value.GetHashCode());

                // Test Parse()
                Assert.AreEqual(value, UInt128.Parse(value.ToString()));
                Assert.AreEqual(value, UInt128.Parse(value.ToString(), CultureInfo.InvariantCulture));
                Assert.AreEqual(value, UInt128.Parse(value.ToString(), NumberStyles.Integer));

                // Test TryParse()
                UInt128 actualValue;
                Assert.IsTrue(UInt128.TryParse(value.ToString(), out actualValue));
                Assert.AreEqual(value, actualValue);
                Assert.IsTrue(UInt128.TryParse(value.ToString(CultureInfo.InvariantCulture), out actualValue));
                Assert.AreEqual(value, actualValue);

                // Cast to UInt64
                ulong smallValue = random.NextULong();
                Assert.AreEqual(smallValue, (ulong)((UInt128)smallValue));
            }
        }
Beispiel #3
0
        public void UInt128Equality()
        {
            UInt128 zero = UInt128.Zero;
            UInt128 one  = UInt128.One;
            UInt128 m    = UInt64.MaxValue;
            UInt128 n    = m + 1;

            Assert.IsTrue(UInt128.MinValue == UInt128.Zero);
            Assert.IsTrue(UInt128.Equals(UInt128.MaxValue, UInt128.MaxValue));
            Assert.IsTrue(UInt128.One.Equals((object)UInt128.One));

            Assert.IsTrue(zero != one);
            Assert.IsTrue(!one.Equals(zero));

            Assert.IsTrue(m + one == n);
            Assert.IsTrue(n.Equals(m + one));
            Assert.IsTrue(!m.Equals(null));
            Assert.IsTrue((m + one).GetHashCode() == n.GetHashCode());
        }
Beispiel #4
0
 public override int GetHashCode()
 {
     return(v.GetHashCode());
 }
Beispiel #5
0
 public override int GetHashCode()
 {
     return(_state.GetHashCode());
 }