コード例 #1
0
        public void TestIEquatable()
        {
            Null <int> nil             = null;
            IEquatable <Null <int> > a = new Null <int>(5);
            Null <int> b1 = 6;

            Assert.IsTrue(a.Equals(5));
            Assert.IsFalse(a.Equals(nil));
            Assert.IsFalse(a.Equals(b1));
        }
コード例 #2
0
        public void TestEquals()
        {
            object nil = null;
            object a   = new Null <int>(5);
            object b1  = 6;

            Assert.IsTrue(a.Equals((Null <int>) 5));
            Assert.IsFalse(a.Equals(nil));
            Assert.IsFalse(a.Equals(b1));
        }
コード例 #3
0
        public void Null_Equals_Null()
        {
            object nullLiteral           = null;
            object nullSingletonAsObject = Null.Instance;
            Null   nullSingletonAsTyped  = Null.Instance;

            nullSingletonAsObject.Equals(nullLiteral).Should().BeTrue();
            nullSingletonAsTyped.Equals(nullLiteral).Should().BeTrue();
            nullSingletonAsTyped.Equals(Null.Instance).Should().BeTrue();
            nullSingletonAsTyped.Equals(nullSingletonAsObject).Should().BeTrue();
            nullSingletonAsObject.Equals(nullSingletonAsTyped).Should().BeTrue();

            (nullSingletonAsObject == nullLiteral).Should().BeFalse();
            (nullSingletonAsTyped == nullLiteral).Should().BeTrue();
        }
コード例 #4
0
        public void TestEqual()
        {
            var left  = new Null();
            var right = new Null();

            Assert.Equal(left, right);
            Assert.True(left == right);
            Assert.True(left.Equals(right));
            Assert.True(left != null);
            // ReSharper disable EqualExpressionComparison
            Assert.True(left == left);
            // ReSharper restore EqualExpressionComparison
            Assert.Throws <ArgumentNullException>(() => left.AppendBytesTo(null));
            Assert.Equal("Null", left.ToString());

            Assert.False(left.Equals(1));
        }
コード例 #5
0
ファイル: ShortParam.cs プロジェクト: orf53975/hadoop.net
 internal override short Parse(string str)
 {
     try
     {
         return(Null.Equals(str) || str == null ? null : short.ParseShort(str, radix));
     }
     catch (FormatException e)
     {
         throw new ArgumentException("Failed to parse \"" + str + "\" as a radix-" + radix
                                     + " short integer.", e);
     }
 }
コード例 #6
0
 internal override int Parse(string str)
 {
     try
     {
         return(Null.Equals(str) || str == null ? null : System.Convert.ToInt32(str, radix
                                                                                ));
     }
     catch (FormatException e)
     {
         throw new ArgumentException("Failed to parse \"" + str + "\" as a radix-" + radix
                                     + " integer.", e);
     }
 }
コード例 #7
0
            private static string ParsePart(string[] parts, int index)
            {
                if (index >= parts.Length)
                {
                    return(null);
                }

                var value = parts[index];

                if (Null.Equals(value, StringComparison.CurrentCultureIgnoreCase))
                {
                    return(null);
                }

                return(value);
            }
コード例 #8
0
        public void TestIEqualityComparer()
        {
            IEqualityComparer <Null <int> > cmp = Null <int> .Comparer;
            Null <int> nil = null;
            Null <int> a   = 5;
            Null <int> b1  = 6;
            Null <int> b2  = 6;

            Assert.IsTrue(cmp.Equals(null, nil));
            Assert.IsTrue(cmp.Equals(nil, null));
            Assert.IsTrue(cmp.Equals(b1, b2));
            Assert.IsFalse(cmp.Equals(a, b1));
            Assert.IsFalse(cmp.Equals(b1, a));
            Assert.IsFalse(cmp.Equals(nil, a));
            Assert.IsFalse(cmp.Equals(a, nil));
            Assert.IsFalse(cmp.Equals(null, a));
            Assert.IsFalse(cmp.Equals(a, null));

            Assert.IsTrue(Null <int> .Equals(null, nil));
            Assert.IsTrue(Null <int> .Equals(nil, null));
            Assert.IsTrue(Null <int> .Equals(b1, b2));
            Assert.IsFalse(Null <int> .Equals(a, b1));
            Assert.IsFalse(Null <int> .Equals(b1, a));
            Assert.IsFalse(Null <int> .Equals(nil, a));
            Assert.IsFalse(Null <int> .Equals(a, nil));
            Assert.IsFalse(Null <int> .Equals(null, a));
            Assert.IsFalse(Null <int> .Equals(a, null));

            Assert.AreNotEqual(a.GetHashCode(), b2.GetHashCode());
            Assert.AreEqual(b1.GetHashCode(), b2.GetHashCode());

            Assert.AreEqual(cmp.GetHashCode(nil), 0);
            Assert.AreEqual(cmp.GetHashCode(a), a.GetHashCode());
            Assert.AreEqual(cmp.GetHashCode(b1), b2.GetHashCode());

            Assert.AreEqual(Null <int> .GetHashCode(nil), 0);
            Assert.AreEqual(Null <int> .GetHashCode(a), a.GetHashCode());
            Assert.AreEqual(Null <int> .GetHashCode(b1), b2.GetHashCode());
        }