public void CompareToTest()
        {
            var my1 = new MonthYear(1, 2000);
            var my2 = new MonthYear(2, 2000);
            var actual = my1.CompareTo(my2);
            Assert.Less(actual, 0);

            my1 = new MonthYear(1, 2000);
            my2 = new MonthYear(1, 2001);
            actual = my1.CompareTo(my2);
            Assert.Less(actual, 0);

            my1 = new MonthYear(1, 2000);
            my2 = new MonthYear(1, 2000);
            actual = my1.CompareTo(my2);
            Assert.AreEqual(actual, 0);

            my1 = new MonthYear(3, 2000);
            my2 = new MonthYear(2, 2000);
            actual = my1.CompareTo(my2);
            Assert.Greater(actual, 0);

            my1 = new MonthYear(1, 2002);
            my2 = new MonthYear(1, 2001);
            actual = my1.CompareTo(my2);
            Assert.Greater(actual, 0);
        }
Ejemplo n.º 2
0
        public void Should_Throw_Exception_Give_Unknown_Type_To_Compare()
        {
            MonthYear monthYear = MonthYear.Now;
            string    datetime  = MonthYear.Now.ToString();

            Assert.Throws <ArgumentException>(() => monthYear.CompareTo(datetime));
        }
Ejemplo n.º 3
0
        public void Should_MonthYear_Comparable_Lesser()
        {
            MonthYear monthYear    = new MonthYear(2021, 2);
            MonthYear monthYearTwo = new MonthYear(2021, 3);
            bool      assertion    = monthYear.CompareTo(monthYearTwo) == -1;

            Assert.True(assertion);
        }
Ejemplo n.º 4
0
        public void Should_MonthYear_Comparable_To_DateTime_Lesser()
        {
            MonthYear monthYear = new MonthYear(2021, 2);
            DateTime  dateTime  = new DateTime(2021, 3, 1);

            bool assertion = monthYear.CompareTo(dateTime) == -1;

            Assert.True(assertion);
        }
Ejemplo n.º 5
0
        public void Should_MonthYear_Comparable_To_DateTime_Equals()
        {
            DateTime  dateTime  = DateTime.Now;
            MonthYear monthYear = new MonthYear(dateTime.Year, dateTime.Month);

            bool assertion = monthYear.CompareTo(dateTime) == 0;

            Assert.True(assertion);
        }
        public void DateComparisonTests()
        {
            var my1 = new MonthYear(12, 1999);
            var my2 = new MonthYear(1, 2000);

            var dt1 = new DateTime(1999, 12, 1);
            var dt2 = new DateTime(2000, 1, 1);
            var dt3 = new DateTime(2000, 2, 1);

            MonthYear my3 = dt3;

            Assert.True(my1.Equals(dt1));
            Assert.False(my1.Equals(dt2));
            Assert.True(my1.CompareTo(dt1) == 0);
            Assert.True(my2.CompareTo(dt1) > 0);
            Assert.True(my1.Equals(dt1));
            Assert.True(my1.Equals((object)my1));

            Assert.True(my1.Equals(dt1));
            Assert.False(my1.Equals(dt2));
            my1++;
            Assert.True(my1.Equals(dt2));
            Assert.False(my1.Equals(dt1));
            my1--;
            Assert.False(my1.Equals(dt2));
            Assert.True(my1.Equals(dt1));
        }