Пример #1
0
        public void TestEquality()
        {
            YearMonthDay first  = new YearMonthDay(2000, 1, 1);
            YearMonthDay second = new YearMonthDay(2000, 1, 1);

            Assert.AreEqual(first, second);
            Assert.IsTrue(first.Equals(second));
            Assert.IsTrue(second.Equals(first));
            Assert.AreEqual(0, first.CompareTo(second));
            Assert.AreEqual(0, second.CompareTo(first));

            second = new YearMonthDay(2001, 1, 1);
            Assert.AreNotEqual(first, second);
            Assert.IsFalse(first.Equals(second));
            Assert.IsFalse(second.Equals(first));
            Assert.AreNotEqual(0, first.CompareTo(second));
            Assert.AreNotEqual(0, second.CompareTo(first));

            second = new YearMonthDay(2000, 2, 1);
            Assert.AreNotEqual(first, second);
            Assert.IsFalse(first.Equals(second));
            Assert.IsFalse(second.Equals(first));
            Assert.AreNotEqual(0, first.CompareTo(second));
            Assert.AreNotEqual(0, second.CompareTo(first));

            second = new YearMonthDay(2000, 1, 2);
            Assert.AreNotEqual(first, second);
            Assert.IsFalse(first.Equals(second));
            Assert.IsFalse(second.Equals(first));
            Assert.AreNotEqual(0, first.CompareTo(second));
            Assert.AreNotEqual(0, second.CompareTo(first));

            Assert.AreNotEqual(first, 5);
        }
Пример #2
0
        public void TestCompareToObject()
        {
            YearMonthDay ymd1 = new YearMonthDay(2006, 3, 14);
            object       ymd4 = new YearMonthDay(2004, 2, 21);

            Assert.Greater(ymd1.CompareTo(null), 0);
            Assert.Greater(ymd1.CompareTo(ymd4), 0);
        }
Пример #3
0
        public void TestCompareToWrongType()
        {
            YearMonthDay ymd = new YearMonthDay(2006, 3, 14);

            Assert.Throws <ArgumentException>(() =>
            {
                int unused = ymd.CompareTo(5);
            });
        }
Пример #4
0
        public void TestComparisons()
        {
            YearMonthDay ymd1 = new YearMonthDay(2006, 3, 14);
            YearMonthDay ymd2 = new YearMonthDay(2006, 3, 14);
            YearMonthDay ymd3 = new YearMonthDay(2006, 5, 26);
            object       ymd4 = new YearMonthDay(2004, 2, 21);

            Assert.IsTrue(ymd1 == ymd2);
            Assert.IsTrue(ymd2 == ymd1);
            Assert.IsTrue(ymd1 != ymd3);
            Assert.IsTrue(ymd1 >= ymd2);
            Assert.IsTrue(ymd1 <= ymd2);
            Assert.AreEqual(0, ymd1.CompareTo(ymd2));
            Assert.IsTrue(ymd2 < ymd3);
            Assert.IsTrue(ymd2 <= ymd3);
            Assert.IsTrue(ymd3 > ymd2);
            Assert.IsTrue(ymd3 >= ymd2);
            Assert.AreNotEqual(ymd1, ymd4);
        }
 public override int Compare(YearMonthDay lhs, YearMonthDay rhs)
 {
     // The civil month numbering system allows a naive comparison.
     if (monthNumbering == HebrewMonthNumbering.Civil)
     {
         return lhs.CompareTo(rhs);
     }
     // Otherwise, try one component at a time. (We could benchmark this
     // against creating a new pair of YearMonthDay values in the civil month numbering,
     // and comparing them...)
     int yearComparison = lhs.Year.CompareTo(rhs.Year);
     if (yearComparison != 0)
     {
         return yearComparison;
     }
     int lhsCivilMonth = CalendarToCivilMonth(lhs.Year, lhs.Month);
     int rhsCivilMonth = CalendarToCivilMonth(rhs.Year, rhs.Month);
     int monthComparison = lhsCivilMonth.CompareTo(rhsCivilMonth);
     if (monthComparison != 0)
     {
         return monthComparison;
     }
     return lhs.Day.CompareTo(rhs.Day);
 }
Пример #6
0
 public void TestCompareToWrongType()
 {
     YearMonthDay ymd = new YearMonthDay(2006, 3, 14);
     ymd.CompareTo(5);
 }
Пример #7
0
        public void TestCompareToObject()
        {
            YearMonthDay ymd1 = new YearMonthDay(2006, 3, 14);
            object ymd4 = new YearMonthDay(2004, 2, 21);

            Assert.IsTrue(ymd1.CompareTo(null) > 0);
            Assert.IsTrue(ymd1.CompareTo(ymd4) > 0);
        }
Пример #8
0
        public void TestComparisons()
        {
            YearMonthDay ymd1 = new YearMonthDay(2006, 3, 14);
            YearMonthDay ymd2 = new YearMonthDay(2006, 3, 14);
            YearMonthDay ymd3 = new YearMonthDay(2006, 5, 26);
            object ymd4 = new YearMonthDay(2004, 2, 21);

            Assert.IsTrue(ymd1 == ymd2);
            Assert.IsTrue(ymd2 == ymd1);
            Assert.IsTrue(ymd1 != ymd3);
            Assert.IsTrue(ymd1 >= ymd2);
            Assert.IsTrue(ymd1 <= ymd2);
            Assert.IsTrue(ymd1.CompareTo(ymd2) == 0);
            Assert.IsTrue(ymd2 < ymd3);
            Assert.IsTrue(ymd2 <= ymd3);
            Assert.IsTrue(ymd3 > ymd2);
            Assert.IsTrue(ymd3 >= ymd2);
            Assert.AreNotEqual(ymd1, ymd4);
        }
Пример #9
0
        public void TestEquality()
        {
            YearMonthDay first = new YearMonthDay(2000, 1, 1);
            YearMonthDay second = new YearMonthDay(2000, 1, 1);
            Assert.AreEqual(first, second);
            Assert.IsTrue(first.Equals(second));
            Assert.IsTrue(second.Equals(first));
            Assert.AreEqual(0, first.CompareTo(second));
            Assert.AreEqual(0, second.CompareTo(first));

            second = new YearMonthDay(2001, 1, 1);
            Assert.AreNotEqual(first, second);
            Assert.IsFalse(first.Equals(second));
            Assert.IsFalse(second.Equals(first));
            Assert.AreNotEqual(0, first.CompareTo(second));
            Assert.AreNotEqual(0, second.CompareTo(first));

            second = new YearMonthDay(2000, 2, 1);
            Assert.AreNotEqual(first, second);
            Assert.IsFalse(first.Equals(second));
            Assert.IsFalse(second.Equals(first));
            Assert.AreNotEqual(0, first.CompareTo(second));
            Assert.AreNotEqual(0, second.CompareTo(first));

            second = new YearMonthDay(2000, 1, 2);
            Assert.AreNotEqual(first, second);
            Assert.IsFalse(first.Equals(second));
            Assert.IsFalse(second.Equals(first));
            Assert.AreNotEqual(0, first.CompareTo(second));
            Assert.AreNotEqual(0, second.CompareTo(first));

            Assert.AreNotEqual(first, 5);
        }
Пример #10
0
        public void TestCompareToWrongType()
        {
            YearMonthDay ymd = new YearMonthDay(2006, 3, 14);

            ymd.CompareTo(5);
        }