コード例 #1
0
        public void TestCompareTo()
        {
            Optional <int> one           = new Optional <int>(1);
            Optional <int> two           = new Optional <int>(2);
            Optional <int> anotherOne    = new Optional <int>(1);
            Optional <int> unassignedOne = new Optional <int>();
            Optional <int> unassignedTwo = Optional <int> .Unassigned;

            Assert.IsTrue(one.CompareTo(two) < 0);
            Assert.IsTrue(two.CompareTo(one) > 0);
            Assert.IsTrue(one.CompareTo(one) == 0);
            Assert.IsTrue(one.CompareTo(anotherOne) == 0);
            Assert.IsTrue(one.CompareTo(unassignedTwo) > 0);
            Assert.IsTrue(unassignedOne.CompareTo(unassignedTwo) == 0);
            Assert.IsTrue(unassignedOne.CompareTo(one) < 0);

            Assert.IsTrue(one.CompareTo(2) < 0);
            Assert.IsTrue(one.CompareTo(1) == 0);
            Assert.IsTrue(two.CompareTo(1) > 0);
            Assert.IsTrue(unassignedOne.CompareTo(1) < 0);
        }