public void TestCompareTo() { Duration duration1 = new Duration(1, 0.0); Duration duration2 = new Duration(1, 0.0); Assert.AreEqual(0, duration1.CompareTo(duration2)); Assert.AreEqual(0, duration2.CompareTo(duration1)); Assert.IsTrue(duration1 >= duration2); Assert.IsTrue(duration2 <= duration1); Assert.IsTrue(duration1 <= duration2); Assert.IsTrue(duration2 >= duration1); duration2 = new Duration(2, 0.0); Assert.Less(duration1.CompareTo(duration2), 0); Assert.Greater(duration2.CompareTo(duration1), 0); Assert.IsTrue(duration1 < duration2); Assert.IsTrue(duration2 > duration1); Assert.IsTrue(duration1 <= duration2); Assert.IsTrue(duration2 >= duration1); duration2 = new Duration(1, 1.0); Assert.Less(duration1.CompareTo(duration2), 0); Assert.Greater(duration2.CompareTo(duration1), 0); Assert.IsTrue(duration1 < duration2); Assert.IsTrue(duration2 > duration1); Assert.IsTrue(duration1 <= duration2); Assert.IsTrue(duration2 >= duration1); }
public void CompareToIsImplemented() { Duration second = Duration.FromSeconds(1); Assert.Equal(0, second.CompareTo(second)); Assert.True(second.CompareTo(Duration.Zero) > 0); Assert.True(Duration.Zero.CompareTo(second) < 0); }
public void CompareToIsImplemented() { Duration second = Duration.FromSeconds(1); Assert.AreEqual(0, second.CompareTo(second)); Assert.Greater(second.CompareTo(Duration.Zero), 0); Assert.Less(Duration.Zero.CompareTo(second), 0); }
public void TestObjectCompareTo() { Duration duration1 = new Duration(1, 1.0); Assert.Greater(duration1.CompareTo(null), 0); object duration2 = new Duration(1, 1.0); Assert.AreEqual(0, duration1.CompareTo(duration2)); }
public void TestObjectCompareTo() { Duration duration1 = new Duration(1, 1.0); Assert.IsTrue(duration1.CompareTo(null) > 0); object duration2 = new Duration(1, 1.0); Assert.IsTrue(duration1.CompareTo(duration2) == 0); }
public void CompareToThrowsOnTypeMismatch() { Duration second = Duration.FromSeconds(1); // ReSharper disable once ReturnValueOfPureMethodIsNotUsed second.CompareTo(new object()); }
public void CompareToThrowsOnNull() { Duration second = Duration.FromSeconds(1); // ReSharper disable once ReturnValueOfPureMethodIsNotUsed second.CompareTo(null); }
public void TestCompareTo() { Duration duration1 = new Duration(1, 0.0); Duration duration2 = new Duration(1, 0.0); Assert.IsTrue(duration1.CompareTo(duration2) == 0); Assert.IsTrue(duration2.CompareTo(duration1) == 0); Assert.IsTrue(duration1 >= duration2); Assert.IsTrue(duration2 <= duration1); Assert.IsTrue(duration1 <= duration2); Assert.IsTrue(duration2 >= duration1); duration2 = new Duration(2, 0.0); Assert.IsTrue(duration1.CompareTo(duration2) < 0); Assert.IsTrue(duration2.CompareTo(duration1) > 0); Assert.IsTrue(duration1 < duration2); Assert.IsTrue(duration2 > duration1); Assert.IsTrue(duration1 <= duration2); Assert.IsTrue(duration2 >= duration1); duration2 = new Duration(1, 1.0); Assert.IsTrue(duration1.CompareTo(duration2) < 0); Assert.IsTrue(duration2.CompareTo(duration1) > 0); Assert.IsTrue(duration1 < duration2); Assert.IsTrue(duration2 > duration1); Assert.IsTrue(duration1 <= duration2); Assert.IsTrue(duration2 >= duration1); }
public void TestLap() { Mock.Get(mockClock).Setup(m => m.GetCurrentInstant()).Returns(Instant.FromUnixTimeSeconds(0)); Timer parentTimer = new Timer(mockClock, null); Mock.Get(mockClock).Setup(m => m.GetCurrentInstant()).Returns(Instant.FromUnixTimeSeconds(0) + Duration.FromMilliseconds(5)); Duration parentDuration1 = parentTimer.Lap(); Mock.Get(mockClock).Setup(m => m.GetCurrentInstant()).Returns(Instant.FromUnixTimeSeconds(0) + Duration.FromMilliseconds(15)); Duration parentDuration2 = parentTimer.Lap(); Mock.Get(mockClock).Setup(m => m.GetCurrentInstant()).Returns(Instant.FromUnixTimeSeconds(0) + Duration.FromMilliseconds(16)); Timer childTimer = new Timer(mockClock, parentTimer); Mock.Get(mockClock).Setup(m => m.GetCurrentInstant()).Returns((Instant.FromUnixTimeSeconds(0) + Duration.FromMilliseconds(16)).PlusNanoseconds(1)); Duration childDuration = childTimer.Lap(); Mock.Get(mockClock).Setup(m => m.GetCurrentInstant()).Returns((Instant.FromUnixTimeSeconds(0) + Duration.FromMilliseconds(16)).PlusNanoseconds(2)); Duration parentDuration3 = parentTimer.Lap(); Assert.IsTrue(parentDuration2.CompareTo(parentDuration1) > 0); Assert.IsTrue(parentDuration1.CompareTo(parentDuration3) > 0); Assert.IsTrue(parentDuration3.CompareTo(childDuration) > 0); }
public void TestEquality() { Duration first = new Duration(5, 565.0); Duration second = new Duration(5, 565.0); Assert.AreEqual(first, second); Assert.IsTrue(first.Equals(second)); Assert.IsTrue(second.Equals(first)); Assert.IsTrue(first == second); Assert.IsTrue(second == first); Assert.IsFalse(first != second); Assert.IsFalse(second != first); Assert.AreEqual(0, first.CompareTo(second)); Assert.AreEqual(0, second.CompareTo(first)); first = new Duration(5, 0.00001); second = new Duration(4, 86399.99999); Assert.AreNotEqual(first, second); Assert.IsFalse(first.Equals(second)); Assert.IsFalse(second.Equals(first)); Assert.IsFalse(first == second); Assert.IsFalse(second == first); Assert.IsTrue(first != second); Assert.IsTrue(second != first); Assert.AreNotEqual(0, first.CompareTo(second)); Assert.AreNotEqual(0, second.CompareTo(first)); Assert.IsTrue(first.EqualsEpsilon(second, 1e-4)); Assert.IsTrue(second.EqualsEpsilon(first, 1e-4)); // Make sure a Duration compared with a non-Duration returns false Assert.IsFalse(first.Equals(5)); }
public int CompareTo(object obj) { if (!(obj is SectorTiming)) { return(-1); } return(Duration.CompareTo(((SectorTiming)obj).Duration)); }
public void ShouldThrowOnCompareToOtherType() { var duration1 = new Duration(0, 0, 0, 0); var ex = Record.Exception(() => duration1.CompareTo(new DateTime(1947, 12, 17))); ex.Should().NotBeNull().And.BeOfType <ArgumentException>(); }
public void ShouldReportLargerOnCompareToNull() { var duration1 = new Duration(0, 0, 0, 0); var comp = duration1.CompareTo(null); comp.Should().BeGreaterThan(0); }
public int CompareTo(FrameElement other) { if (StartTime.Equals(other.StartTime)) { return(Duration.CompareTo(other.Duration)); } return(StartTime.CompareTo(other.StartTime)); }
} // CompareStart // ---------------------------------------------------------------------- public int CompareDuration(ITimePeriod compare) { if (compare == null) { throw new ArgumentNullException("compare"); } return(Duration.CompareTo(compare.Duration)); } // CompareDuration
public void ShouldReportSmallerOnCompareTo() { var duration1 = new Duration(1, 12, 500, 999999999); var duration2 = new Duration(1, 12, 501, 0); var comp = duration1.CompareTo(duration2); comp.Should().BeLessThan(0); }
public void ShouldReportEqualOnCompareToAbsolute() { var duration1 = new Duration(0, 1, 0, 999999999); var duration2 = new Duration(0, 0, 86400, 999999999); var comp = duration1.CompareTo(duration2); comp.Should().Be(0); }
public void ShouldReportEqualOnCompareTo() { var duration1 = new Duration(1, 12, 500, 999999999); var duration2 = new Duration(1, 12, 500, 999999999); var comp = duration1.CompareTo(duration2); comp.Should().Be(0); }
public void ShouldReportLargerOnCompareToAbsolute() { var duration1 = new Duration(0, 1, 0, 1); var duration2 = new Duration(0, 0, 86400, 0); var comp = duration1.CompareTo(duration2); comp.Should().BeGreaterThan(0); }
public void ShouldReportLargerOnCompareTo() { var duration1 = new Duration(1, 12, 500, 999999999); var duration2 = new Duration(1, 12, 500, 0); var comp = duration1.CompareTo(duration2); comp.Should().BeGreaterThan(0); }
public void TestObjectCompareToNotDuration() { Duration duration = new Duration(1, 1.0); Assert.Throws <ArgumentException>(() => { int unused = duration.CompareTo(5); }); }
public void ShouldReportSmallerOnCompareToAbsolute() { var duration1 = new Duration(0, 1, 0, 999999999); var duration2 = new Duration(0, 0, 86401, 999999999); var comp = duration1.CompareTo(duration2); comp.Should().BeLessThan(0); }
public int CompareTo(object obj) { if (obj is Film) { int result = 1; Film film = (Film)obj; return(Duration.CompareTo(film.Duration)); } throw new ArgumentException("Incorrect type"); }
public void When_Duration_Is_TimeSpan() { var duration = new Duration(TimeSpan.FromSeconds(24)); Assert.IsTrue(duration.HasTimeSpan); Assert.IsTrue(duration.Equals((object)new Duration(TimeSpan.FromSeconds(24)))); Assert.IsTrue(duration.Equals(new Duration(TimeSpan.FromSeconds(24)))); Assert.IsTrue(Duration.Equals(duration, new Duration(TimeSpan.FromSeconds(24)))); Assert.IsFalse(duration.Equals(null)); Assert.IsFalse(duration.Equals((object)Duration.Automatic)); Assert.IsFalse(duration.Equals(new Duration(TimeSpan.FromSeconds(30)))); Assert.IsFalse(Duration.Equals(duration, Duration.Forever)); Assert.AreEqual("00:00:24", duration.ToString()); Assert.AreEqual(1, duration.CompareTo(Duration.Automatic)); Assert.AreEqual(-1, duration.CompareTo(Duration.Forever)); Assert.AreEqual(0, Duration.Compare(duration, new Duration(TimeSpan.FromSeconds(24)))); Assert.AreEqual(new Duration(TimeSpan.FromSeconds(48)), duration.Add(new Duration(TimeSpan.FromSeconds(24)))); Assert.AreEqual(new Duration(TimeSpan.FromSeconds(1)), duration.Subtract(new Duration(TimeSpan.FromSeconds(23)))); }
/**@}*/ #endregion #region Order comparison /*! \name Order comparison */ /**@{*/ /// <summary> /// Generic IComparable implementation (default) for comparing AcSession objects /// to sort by Duration and then Name. /// </summary> /// <param name="other">An AcSession object to compare with this instance.</param> /// <returns>Value indicating the relative order of the AcSession objects being compared.</returns> /*! \sa [AcSessions example](@ref AcUtils#AcSessions#AcSessions) */ public int CompareTo(AcSession other) { int result; if (AcSession.ReferenceEquals(this, other)) { result = 0; } else { result = Duration.CompareTo(other.Duration); if (result == 0) { result = Name.CompareTo(other.Name); } } //return -1 * result; // sort in reverse order to show longer sessions first return(result); }
public int CompareTo(object obj) { var ob = (ImageItem)obj; switch (sortstate) { case 0: return(blur.CompareTo(ob.blur)); case 1: return(exposure.CompareTo(ob.exposure)); case 2: return(timeTaken.CompareTo(ob.timeTaken)); case 3: return(Duration.CompareTo(ob.Duration)); } throw new Exception(); }
/// <summary> /// Compare two tracks. /// </summary> public int CompareTo(Track other) { if (other == null) { return(+1); } int rc = Start.CompareTo(other.Start); if (rc != 0) { return(rc); } rc = Duration.CompareTo(other.Duration); if (rc != 0) { return(rc); } return(0); }
/// <summary> /// Calculate the scheduled working time between the specified dates and /// times of day.Non-working periods are removed. /// </summary> /// <param name="from">Starting date and time of day</param> /// <param name="to">Ending date and time of day</param> /// <returns>Duration of working time</returns> public Duration CalculateWorkingTime(LocalDateTime from, LocalDateTime to) { Duration sum = Duration.Zero; // now add up scheduled time by team foreach (Team team in Teams) { sum = sum.Plus(team.CalculateWorkingTime(from, to)); } // remove the non-working time Duration nonWorking = CalculateNonWorkingTime(from, to); sum = sum.Minus(nonWorking); // clip if negative if (sum.CompareTo(Duration.Zero) < 0) { sum = Duration.Zero; } return(sum); }
public int CompareTo(RegisteredAction other) { if (ReferenceEquals(this, other)) { return(0); } if (ReferenceEquals(null, other)) { return(1); } var idComparison = string.Compare(Id, other.Id, StringComparison.Ordinal); if (idComparison != 0) { return(idComparison); } var startTimeComparison = StartTime.CompareTo(other.StartTime); if (startTimeComparison != 0) { return(startTimeComparison); } var durationComparison = Duration.CompareTo(other.Duration); if (durationComparison != 0) { return(durationComparison); } var projectMemberIdComparison = string.Compare(ProjectMemberId, other.ProjectMemberId, StringComparison.Ordinal); if (projectMemberIdComparison != 0) { return(projectMemberIdComparison); } return(string.Compare(ProjectActionId, other.ProjectActionId, StringComparison.Ordinal)); }
/// <summary> /// Compares the current object with another object of the same type. /// </summary> /// <param name="other">An object to compare with this object.</param> /// <returns> /// A value that indicates the relative order of the objects being compared. The return value has the following meanings: Value Meaning Less than zero This object is less than the <paramref name="other"/> parameter. /// Zero This object is equal to <paramref name="other"/>. Greater than zero This object is greater than <paramref name="other"/>. /// </returns> public int CompareTo(Period other) => Duration.CompareTo(other.Duration);