示例#1
0
        public void Comparability()
        {
            Timestamp
                a = null,
                b = new Timestamp {
                Seconds = 1, Nanos = 1
            },
                c = new Timestamp {
                Seconds = 1, Nanos = 10
            },
                d = new Timestamp {
                Seconds = 10, Nanos = 1
            },
                e = new Timestamp {
                Seconds = 10, Nanos = 10
            };

            Assert.IsTrue(b.CompareTo(a) > 0); // null is always first (according to default behavior of Array.Sort)
            Assert.IsTrue(b.CompareTo(b) == 0);
            Assert.IsTrue(b.CompareTo(b.Clone()) == 0);
            Assert.IsTrue(b.CompareTo(c) < 0);
            Assert.IsTrue(b.CompareTo(d) < 0);
            Assert.IsTrue(b.CompareTo(e) < 0);

            Assert.IsTrue(c.CompareTo(a) > 0);
            Assert.IsTrue(c.CompareTo(b) > 0);
            Assert.IsTrue(c.CompareTo(c) == 0);
            Assert.IsTrue(c.CompareTo(c.Clone()) == 0);
            Assert.IsTrue(c.CompareTo(d) < 0);
            Assert.IsTrue(c.CompareTo(e) < 0);

            Assert.IsTrue(d.CompareTo(a) > 0);
            Assert.IsTrue(d.CompareTo(b) > 0);
            Assert.IsTrue(d.CompareTo(c) > 0);
            Assert.IsTrue(d.CompareTo(d) == 0);
            Assert.IsTrue(d.CompareTo(d.Clone()) == 0);
            Assert.IsTrue(d.CompareTo(e) < 0);

            Assert.IsTrue(e.CompareTo(a) > 0);
            Assert.IsTrue(e.CompareTo(b) > 0);
            Assert.IsTrue(e.CompareTo(c) > 0);
            Assert.IsTrue(e.CompareTo(d) > 0);
            Assert.IsTrue(e.CompareTo(e) == 0);
            Assert.IsTrue(e.CompareTo(e.Clone()) == 0);
        }
示例#2
0
        public void ComparabilityOperators()
        {
            Timestamp
                a = null,
                b = new Timestamp {
                Seconds = 1, Nanos = 1
            },
                c = new Timestamp {
                Seconds = 1, Nanos = 10
            },
                d = new Timestamp {
                Seconds = 10, Nanos = 1
            },
                e = new Timestamp {
                Seconds = 10, Nanos = 10
            };

#pragma warning disable CS1718 // Comparison made to same variable
            Assert.IsTrue(b > a);
            Assert.IsTrue(b == b);
            Assert.IsTrue(b == b.Clone());
            Assert.IsTrue(b < c);
            Assert.IsTrue(b < d);
            Assert.IsTrue(b < e);

            Assert.IsTrue(c > a);
            Assert.IsTrue(c > b);
            Assert.IsTrue(c == c);
            Assert.IsTrue(c == c.Clone());
            Assert.IsTrue(c < d);
            Assert.IsTrue(c < e);

            Assert.IsTrue(d > a);
            Assert.IsTrue(d > b);
            Assert.IsTrue(d > c);
            Assert.IsTrue(d == d);
            Assert.IsTrue(d == d.Clone());
            Assert.IsTrue(d < e);

            Assert.IsTrue(e > a);
            Assert.IsTrue(e > b);
            Assert.IsTrue(e > c);
            Assert.IsTrue(e > d);
            Assert.IsTrue(e == e);
            Assert.IsTrue(e == e.Clone());

            Assert.IsTrue(b >= a);
            Assert.IsTrue(b <= c);
            Assert.IsTrue(b <= d);
            Assert.IsTrue(b <= e);

            Assert.IsTrue(c >= a);
            Assert.IsTrue(c >= b);
            Assert.IsTrue(c <= d);
            Assert.IsTrue(c <= e);

            Assert.IsTrue(d >= a);
            Assert.IsTrue(d >= b);
            Assert.IsTrue(d >= c);
            Assert.IsTrue(d <= e);

            Assert.IsTrue(e >= a);
            Assert.IsTrue(e >= b);
            Assert.IsTrue(e >= c);
            Assert.IsTrue(e >= d);
#pragma warning restore CS1718 // Comparison made to same variable
        }