/// <summary> /// Compares the value of this instance to a specified <see cref="LocalTime"/> 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(LocalTime other) { if (ReferenceEquals(this, other)) { return(0); } if (other is null) { return(1); } 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)); }
public void Should_compare_with_null_instance(double value) { var instance = new Second(value); Assert.IsFalse(instance.Equals(null), "Equals"); Assert.AreEqual(1, instance.CompareTo(null), "CompareTo"); }
public void Should_compare_with_another_type_of_instance(double value) { var instance1 = new Second(value); object instance2 = value; Assert.IsFalse(instance1.Equals(instance2), "Equals"); Assert.Throws <ArgumentException>(() => instance1.CompareTo(instance2), "CompareTo"); }
public void SecondCompareToReturnsZeroIfOtherIsSameReference() { const int expected = 0; Second second = new Second(47); Second other = second; Assert.AreEqual(expected, second.CompareTo(other)); }
public void SecondCompareToReturnsOneIfOtherIsLessThanValue() { const int expected = 1; Second second = new Second(47); Second other = new Second(46); Assert.AreEqual(expected, second.CompareTo(other)); }
public void SecondCompareToReturnsOneIfOtherIsNotTypeOfSecond() { const int expected = 1; Second second = new Second(47); Task other = new Task(() => { }); Assert.AreEqual(expected, second.CompareTo(other)); }
public void SecondCompareToReturnsOneIfOtherIsNull() { const int expected = 1; Second second = new Second(47); Second other = null; Assert.AreEqual(expected, second.CompareTo(other)); }
public void Should_compare_with_bigger_value(double baseValue, double biggerValue) { var baseInstance = new Second(baseValue); var biggerInstance = new Second(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, ">="); }
public void Should_compare_with_smaller_value(double baseValue, double smallerValue) { var baseInstance = new Second(baseValue); var smallerInstance = new Second(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, ">="); }
public void Should_compare_with_same_value(double value) { var baseInstance = new Second(value); var otherInstance = new Second(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, ">="); }
public int CompareTo(Tuple <TFirst, TSecond, TThird> other) { if (First.CompareTo(other.First) != 0) { return(First.CompareTo(other.First)); } if (Second.CompareTo(other.Second) != 0) { return(Second.CompareTo(other.Second)); } return(Third.CompareTo(other.Third)); }
/// <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)); }
public int CompareTo(object obj) { ComparablePair <S, T> op = obj as ComparablePair <S, T>; if (op == null) { return(-1); } var k = First.CompareTo(op.First); if (k != 0) { return(k); } else { return(Second.CompareTo(op.Second)); } }
public int CompareTo(object obj) { var c = (Code)obj; if (First.CompareTo(c.First) == 0) { if (Second.CompareTo(c.Second) == 0) { return(Third.CompareTo(c.Third)); } else { return(Second.CompareTo(c.Second)); } } else { return(First.CompareTo(c.First)); } }
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); }