Пример #1
0
        public void TestDaysInMonth()
        {
            for (int i = 1; i < 10000; ++i)
            {
                Assert.AreEqual(31, YearMonthDay.DaysInMonth(i, 1)); // January
                if ((i % 4 == 0) && !((i % 100 == 0) && (i % 400 != 0)))
                {
                    Assert.AreEqual(29, YearMonthDay.DaysInMonth(i, 2)); // February of a leap year
                }
                else
                {
                    Assert.AreEqual(28, YearMonthDay.DaysInMonth(i, 2)); // February of a common year
                }

                Assert.AreEqual(31, YearMonthDay.DaysInMonth(i, 3));  // March
                Assert.AreEqual(30, YearMonthDay.DaysInMonth(i, 4));  // April
                Assert.AreEqual(31, YearMonthDay.DaysInMonth(i, 5));  // May
                Assert.AreEqual(30, YearMonthDay.DaysInMonth(i, 6));  // June
                Assert.AreEqual(31, YearMonthDay.DaysInMonth(i, 7));  // July
                Assert.AreEqual(31, YearMonthDay.DaysInMonth(i, 8));  // August
                Assert.AreEqual(30, YearMonthDay.DaysInMonth(i, 9));  // September
                Assert.AreEqual(31, YearMonthDay.DaysInMonth(i, 10)); // October
                Assert.AreEqual(30, YearMonthDay.DaysInMonth(i, 11)); // November
                Assert.AreEqual(31, YearMonthDay.DaysInMonth(i, 12)); // December
            }
        }
Пример #2
0
        public void TestIsValidDate()
        {
            Assert.IsFalse(YearMonthDay.IsValidDate(2000, 0, 1));
            Assert.IsTrue(YearMonthDay.IsValidDate(2000, 1, 1));
            Assert.IsTrue(YearMonthDay.IsValidDate(2000, 2, 1));
            Assert.IsTrue(YearMonthDay.IsValidDate(2000, 3, 1));
            Assert.IsTrue(YearMonthDay.IsValidDate(2000, 4, 1));
            Assert.IsTrue(YearMonthDay.IsValidDate(2000, 5, 1));
            Assert.IsTrue(YearMonthDay.IsValidDate(2000, 6, 1));
            Assert.IsTrue(YearMonthDay.IsValidDate(2000, 7, 1));
            Assert.IsTrue(YearMonthDay.IsValidDate(2000, 8, 1));
            Assert.IsTrue(YearMonthDay.IsValidDate(2000, 9, 1));
            Assert.IsTrue(YearMonthDay.IsValidDate(2000, 10, 1));
            Assert.IsTrue(YearMonthDay.IsValidDate(2000, 11, 1));
            Assert.IsTrue(YearMonthDay.IsValidDate(2000, 12, 1));
            Assert.IsFalse(YearMonthDay.IsValidDate(2000, 13, 1));

            for (int month = 1; month < 13; ++month)
            {
                int daysInMonth = YearMonthDay.DaysInMonth(2000, month);

                Assert.IsFalse(YearMonthDay.IsValidDate(2000, month, 0));
                for (int day = 1; day < daysInMonth + 1; ++day)
                {
                    Assert.IsTrue(YearMonthDay.IsValidDate(2000, month, day));
                }

                Assert.IsFalse(YearMonthDay.IsValidDate(2000, month, daysInMonth + 1));
            }
        }
Пример #3
0
        public void TestConstructFromDayOfYear()
        {
            int[] years = { 2000, 2001 };

            Assert.IsTrue(YearMonthDay.IsLeapYear(years[0]));
            Assert.IsFalse(YearMonthDay.IsLeapYear(years[1]));

            foreach (int year in years)
            {
                int cumulativeDays = 0;
                for (int month = 1; month <= 12; ++month)
                {
                    // Test first of the month.
                    YearMonthDay ymd = new YearMonthDay(year, cumulativeDays + 1);
                    Assert.AreEqual(year, ymd.Year);
                    Assert.AreEqual(month, ymd.Month);
                    Assert.AreEqual(1, ymd.Day);

                    int daysInMonth = YearMonthDay.DaysInMonth(year, month);

                    // Test last of the month.
                    ymd = new YearMonthDay(year, cumulativeDays + daysInMonth);
                    Assert.AreEqual(year, ymd.Year);
                    Assert.AreEqual(month, ymd.Month);
                    Assert.AreEqual(daysInMonth, ymd.Day);

                    cumulativeDays += daysInMonth;
                }
            }
        }