Example #1
0
        public void Should_compare_with_bigger_value(double baseValue, double biggerValue)
        {
            var baseInstance   = new Minute(baseValue);
            var biggerInstance = new Minute(biggerValue);

            Assert.IsFalse(baseInstance.Equals(biggerInstance), "Equals");
            Assert.IsFalse(baseInstance.Equals((object)biggerInstance), "Equals object");

            Assert.IsFalse(baseInstance == biggerInstance, "==");
            Assert.IsTrue(baseInstance != biggerInstance, "!=");

            Assert.AreEqual(-1, baseInstance.CompareTo(biggerInstance), "CompareTo");
            Assert.AreEqual(-1, baseInstance.CompareTo((object)biggerInstance), "CompareTo object");

            Assert.IsTrue(baseInstance < biggerInstance, "<");
            Assert.IsFalse(baseInstance > biggerInstance, ">");

            Assert.IsTrue(baseInstance <= biggerInstance, "<=");
            Assert.IsFalse(baseInstance >= biggerInstance, ">=");
        }
Example #2
0
        public void Should_compare_with_smaller_value(double baseValue, double smallerValue)
        {
            var baseInstance    = new Minute(baseValue);
            var smallerInstance = new Minute(smallerValue);

            Assert.IsFalse(baseInstance.Equals(smallerInstance), "Equals");
            Assert.IsFalse(baseInstance.Equals((object)smallerInstance), "Equals object");

            Assert.IsFalse(baseInstance == smallerInstance, "==");
            Assert.IsTrue(baseInstance != smallerInstance, "!=");

            Assert.AreEqual(+1, baseInstance.CompareTo(smallerInstance), "CompareTo");
            Assert.AreEqual(+1, baseInstance.CompareTo((object)smallerInstance), "CompareTo object");

            Assert.IsFalse(baseInstance < smallerInstance, "<");
            Assert.IsTrue(baseInstance > smallerInstance, ">");

            Assert.IsFalse(baseInstance <= smallerInstance, "<=");
            Assert.IsTrue(baseInstance >= smallerInstance, ">=");
        }
Example #3
0
        public void Should_compare_with_same_value(double value)
        {
            var baseInstance  = new Minute(value);
            var otherInstance = new Minute(value);

            Assert.IsTrue(baseInstance.Equals(otherInstance), "Equals");
            Assert.IsTrue(baseInstance.Equals((object)otherInstance), "Equals object");

            Assert.IsTrue(baseInstance == otherInstance, "==");
            Assert.IsFalse(baseInstance != otherInstance, "!=");

            Assert.AreEqual(0, baseInstance.CompareTo(otherInstance), "CompareTo");
            Assert.AreEqual(0, baseInstance.CompareTo((object)otherInstance), "CompareTo object");

            Assert.IsFalse(baseInstance < otherInstance, "<");
            Assert.IsFalse(baseInstance > otherInstance, ">");

            Assert.IsTrue(baseInstance <= otherInstance, "<=");
            Assert.IsTrue(baseInstance >= otherInstance, ">=");
        }
Example #4
0
        public int CompareTo(Time other)
        {
            var result = Hour.CompareTo(other.Hour);

            if (result == 0)
            {
                result = Minute.CompareTo(other.Minute);
            }
            if (result == 0)
            {
                result = Second.CompareTo(other.Second);
            }
            return(result);
        }
Example #5
0
        /// <summary>
        /// Compares the value of this instance to a specified <see cref="LocalDateTime"/> value and returns an integer
        /// that indicates whether this instance is earlier than, the same as, or later than the specified
        /// DateTime value.
        /// </summary>
        /// <param name="other">The object to compare to the current instance.</param>
        /// <returns>A signed number indicating the relative values of this instance and the value parameter.</returns>
        public int CompareTo(LocalDateTime other)
        {
            if (ReferenceEquals(this, other))
            {
                return(0);
            }
            if (other is null)
            {
                return(1);
            }
            var yearComparison = Year.CompareTo(other.Year);

            if (yearComparison != 0)
            {
                return(yearComparison);
            }
            var monthComparison = Month.CompareTo(other.Month);

            if (monthComparison != 0)
            {
                return(monthComparison);
            }
            var dayComparison = Day.CompareTo(other.Day);

            if (dayComparison != 0)
            {
                return(dayComparison);
            }
            var hourComparison = Hour.CompareTo(other.Hour);

            if (hourComparison != 0)
            {
                return(hourComparison);
            }
            var minuteComparison = Minute.CompareTo(other.Minute);

            if (minuteComparison != 0)
            {
                return(minuteComparison);
            }
            var secondComparison = Second.CompareTo(other.Second);

            if (secondComparison != 0)
            {
                return(secondComparison);
            }
            return(Nanosecond.CompareTo(other.Nanosecond));
        }
Example #6
0
        public int CompareTo(Time other)
        {
            int hourComparation = Hour.CompareTo(other.Hour);

            if (hourComparation == 0)
            {
                int minuteComparation = Minute.CompareTo(other.Minute);
                if (minuteComparation == 0)
                {
                    return(Second.CompareTo(other.Second));
                }

                return(minuteComparation);
            }

            return(hourComparation);
        }
Example #7
0
        public int CompareTo(Time other)
        {
            var hourComp = Hour.CompareTo(other.Hour);

            if (hourComp != 0)
            {
                return(hourComp);
            }

            var minComp = Minute.CompareTo(other.Minute);

            if (minComp != 0)
            {
                return(minComp);
            }

            return(Second.CompareTo(other.Second));
        }
Example #8
0
        }                                                     // обычно ToString возвращает российский формат

        public int CompareTo(object ob)
        {
            Date comp = (Date)ob;

            int year   = Year.CompareTo(comp.Year);
            int month  = Month.CompareTo(comp.Month);
            int day    = Day.CompareTo(comp.Day);
            int hour   = Hour.CompareTo(comp.Hour);
            int minute = Minute.CompareTo(comp.Minute);
            int second = Second.CompareTo(comp.Second);

            if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0 && second == 0)
            {
                return(0);
            }

            if (year != 0)
            {
                return(year);
            }
            if (month != 0)
            {
                return(month);
            }
            if (day != 0)
            {
                return(day);
            }
            if (hour != 0)
            {
                return(hour);
            }
            if (minute != 0)
            {
                return(minute);
            }
            if (second != 0)
            {
                return(second);
            }

            return(1);
        }
Example #9
0
        public int CompareTo(GuardLog otherLog)
        {
            int result = Year.CompareTo(otherLog.Year);

            if (result == 0)
            {
                result = Month.CompareTo(otherLog.Month);
            }
            if (result == 0)
            {
                result = Day.CompareTo(otherLog.Day);
            }
            if (result == 0)
            {
                result = Hour.CompareTo(otherLog.Hour);
            }
            if (result == 0)
            {
                result = Minute.CompareTo(otherLog.Minute);
            }

            return(result);
        }
        public int CompareTo(Time time)
        {
            int result;

            result = Year.CompareTo(time.Year);
            if (result != 0)
            {
                return(result);
            }

            result = Month.CompareTo(time.Month);
            if (result != 0)
            {
                return(result);
            }

            result = Day.CompareTo(time.Day);
            if (result != 0)
            {
                return(result);
            }

            result = Hour.CompareTo(time.Hour);
            if (result != 0)
            {
                return(result);
            }

            result = Minute.CompareTo(time.Minute);
            if (result != 0)
            {
                return(result);
            }

            result = Second.CompareTo(time.Second);
            return(result);
        }