public void Equals_SameRangeButNotEquivalent() { LocalDate start = new LocalDate(2000, 1, 1); LocalDate end1 = new LocalDate(2001, 6, 19); LocalDate end2 = new LocalDate(2001, 6, 20); var interval1 = new DateInterval(start, end1, true); var interval2 = new DateInterval(start, end2, false); Assert.AreEqual(interval1.Length, interval2.Length); Assert.AreNotEqual(interval1, interval2); Assert.AreNotEqual(interval1.GetHashCode(), interval2.GetHashCode()); Assert.IsFalse(interval1 == interval2); Assert.IsTrue(interval1 != interval2); Assert.IsFalse(interval1.Equals(interval2)); // IEquatable implementation // This is the key difference between this comparer and standard equality. var comparer = DateInterval.NormalizingEqualityComparer; Assert.IsTrue(comparer.Equals(interval1, interval2)); Assert.AreEqual(comparer.GetHashCode(interval1), comparer.GetHashCode(interval2)); // The same range with different inclusivity is equal, like NormalizingEqualityComparer. comparer = DateInterval.ContainedDatesEqualityComparer; Assert.IsTrue(comparer.Equals(interval1, interval2)); Assert.AreEqual(comparer.GetHashCode(interval1), comparer.GetHashCode(interval2)); }
public void Equals_DifferentCalendars() { LocalDate start1 = new LocalDate(2000, 1, 1); LocalDate end1 = new LocalDate(2001, 6, 19); // This is a really, really similar calendar to ISO, but we do distinguish. LocalDate start2 = start1.WithCalendar(CalendarSystem.Gregorian); LocalDate end2 = end1.WithCalendar(CalendarSystem.Gregorian); var interval1 = new DateInterval(start1, end1, false); var interval2 = new DateInterval(start2, end2, false); Assert.AreNotEqual(interval1, interval2); Assert.AreNotEqual(interval1.GetHashCode(), interval2.GetHashCode()); Assert.IsFalse(interval1 == interval2); Assert.IsTrue(interval1 != interval2); Assert.IsFalse(interval1.Equals(interval2)); // IEquatable implementation var comparer = DateInterval.NormalizingEqualityComparer; Assert.IsFalse(comparer.Equals(interval1, interval2)); Assert.AreNotEqual(comparer.GetHashCode(interval1), comparer.GetHashCode(interval2)); // probably comparer = DateInterval.ContainedDatesEqualityComparer; Assert.IsFalse(comparer.Equals(interval1, interval2)); Assert.AreNotEqual(comparer.GetHashCode(interval1), comparer.GetHashCode(interval2)); // probably }
public void Equals_DifferentToNull() { LocalDate start = new LocalDate(2000, 1, 1); LocalDate end = new LocalDate(2001, 6, 19); var interval = new DateInterval(start, end); Assert.IsFalse(interval.Equals(null)); }
public void Equals_DifferentToOtherType() { LocalDate start = new LocalDate(2000, 1, 1); LocalDate end = new LocalDate(2001, 6, 19); var interval = new DateInterval(start, end); Assert.IsFalse(interval.Equals(Instant.FromUnixTimeTicks(0))); }
public void Equal_DateIntervalWithSameStartAndSameEndDatesExcludeStartIncludeEnd_ReturnsTrue() { // Arrange var dateInterval1 = new DateInterval(now, inOneHour, false, true); var dateInterval2 = new DateInterval(now, inOneHour, false, true); // Act bool value = dateInterval1.Equals(dateInterval2); // Assert Assert.True(value); }
public void Equal_DateIntervalWithSameStartAndEndDatesExcludeEndPoints_ReturnTrue() { // Arrange var dateInterval1 = new DateInterval(now, inOneHour, false, false); var dateInterval2 = new DateInterval(now, inOneHour, false, false); // Act bool equals = dateInterval1.Equals(dateInterval2); // Assert Assert.True(equals); }
public void Equals_EqualValues() { LocalDate start = new LocalDate(2000, 1, 1); LocalDate end = new LocalDate(2001, 6, 19); var interval1 = new DateInterval(start, end, false); var interval2 = new DateInterval(start, end, false); Assert.AreEqual(interval1, interval2); Assert.AreEqual(interval1.GetHashCode(), interval2.GetHashCode()); Assert.IsTrue(interval1 == interval2); Assert.IsFalse(interval1 != interval2); Assert.IsTrue(interval1.Equals(interval2)); // IEquatable implementation }
public void Equal_DateIntervalWithDifferentStartAndSameEndDates_ReturnFalse() { // Arrange var dateInterval1 = new DateInterval(now, inThreeHours); var dateInterval2 = new DateInterval(inOneHour, inThreeHours); // Act bool equals = dateInterval1.Equals(dateInterval2); // Assert Assert.False(equals); }
public void Equals_EqualValues() { LocalDate start = new LocalDate(2000, 1, 1); LocalDate end = new LocalDate(2001, 6, 19); var interval1 = new DateInterval(start, end); var interval2 = new DateInterval(start, end); Assert.AreEqual(interval1, interval2); Assert.AreEqual(interval1.GetHashCode(), interval2.GetHashCode()); Assert.IsTrue(interval1 == interval2); Assert.IsFalse(interval1 != interval2); Assert.IsTrue(interval1.Equals(interval2)); // IEquatable implementation }
public void Equals_DifferentInclusivity() { LocalDate start = new LocalDate(2000, 1, 1); LocalDate end = new LocalDate(2001, 6, 19); var interval1 = new DateInterval(start, end, false); var interval2 = new DateInterval(start, end, true); Assert.AreNotEqual(interval1, interval2); Assert.AreNotEqual(interval1.GetHashCode(), interval2.GetHashCode()); Assert.IsFalse(interval1 == interval2); Assert.IsTrue(interval1 != interval2); Assert.IsFalse(interval1.Equals(interval2)); // IEquatable implementation }
public void Equal_DateIntervalWithSameStartAndSameEndDifferentInclusions_ReturnsFalse( bool minInclusive1, bool maxInclusive1, bool minInclusive2, bool maxInclusive2) { // Arrange var dateInterval1 = new DateInterval(now, inOneHour, minInclusive1, maxInclusive1); var dateInterval2 = new DateInterval(now, inOneHour, minInclusive2, maxInclusive2); // Act bool equals = dateInterval1.Equals(dateInterval2); // Assert Assert.False(equals); }
public void Equals_DifferentToNull() { LocalDate start = new LocalDate(2000, 1, 1); LocalDate end = new LocalDate(2001, 6, 19); var interval = new DateInterval(start, end, false); Assert.IsFalse(interval.Equals(null)); Assert.IsFalse(DateInterval.NormalizingEqualityComparer.Equals(interval, null)); Assert.IsFalse(DateInterval.NormalizingEqualityComparer.Equals(null, interval)); Assert.IsFalse(DateInterval.ContainedDatesEqualityComparer.Equals(interval, null)); Assert.IsFalse(DateInterval.ContainedDatesEqualityComparer.Equals(null, interval)); }
public void Equals_SameInstance() { LocalDate start = new LocalDate(2000, 1, 1); LocalDate end = new LocalDate(2001, 6, 19); var interval = new DateInterval(start, end); Assert.AreEqual(interval, interval); Assert.AreEqual(interval.GetHashCode(), interval.GetHashCode()); // CS1718: Comparison made to same variable. This is intentional to test operator ==. #pragma warning disable 1718 Assert.IsTrue(interval == interval); Assert.IsFalse(interval != interval); #pragma warning restore 1718 Assert.IsTrue(interval.Equals(interval)); // IEquatable implementation }
public void Equals_SameRangeButNotEquivalent() { LocalDate start = new LocalDate(2000, 1, 1); LocalDate end1 = new LocalDate(2001, 6, 19); LocalDate end2 = new LocalDate(2001, 6, 20); var interval1 = new DateInterval(start, end1, true); var interval2 = new DateInterval(start, end2, false); Assert.AreEqual(interval1.Length, interval2.Length); Assert.AreNotEqual(interval1, interval2); Assert.AreNotEqual(interval1.GetHashCode(), interval2.GetHashCode()); Assert.IsFalse(interval1 == interval2); Assert.IsTrue(interval1 != interval2); Assert.IsFalse(interval1.Equals(interval2)); // IEquatable implementation }
public void Equals_DifferentCalendars() { LocalDate start1 = new LocalDate(2000, 1, 1); LocalDate end1 = new LocalDate(2001, 6, 19); // This is a really, really similar calendar to ISO, but we do distinguish. LocalDate start2 = start1.WithCalendar(CalendarSystem.Gregorian); LocalDate end2 = end1.WithCalendar(CalendarSystem.Gregorian); var interval1 = new DateInterval(start1, end1); var interval2 = new DateInterval(start2, end2); Assert.AreNotEqual(interval1, interval2); Assert.AreNotEqual(interval1.GetHashCode(), interval2.GetHashCode()); Assert.IsFalse(interval1 == interval2); Assert.IsTrue(interval1 != interval2); Assert.IsFalse(interval1.Equals(interval2)); // IEquatable implementation }
public void Equals_DifferentCalendars() { LocalDate start1 = new LocalDate(2000, 1, 1); LocalDate end1 = new LocalDate(2001, 6, 19); // This is a really, really similar calendar to ISO - the dates could differ by week of year, // but that's all. LocalDate start2 = start1.WithCalendar(CalendarSystem.GetGregorianCalendar(1)); LocalDate end2 = end1.WithCalendar(CalendarSystem.GetGregorianCalendar(1)); var interval1 = new DateInterval(start1, end1, false); var interval2 = new DateInterval(start2, end2, false); Assert.AreNotEqual(interval1, interval2); Assert.AreNotEqual(interval1.GetHashCode(), interval2.GetHashCode()); Assert.IsFalse(interval1 == interval2); Assert.IsTrue(interval1 != interval2); Assert.IsFalse(interval1.Equals(interval2)); // IEquatable implementation }
public void Equals_EqualValues() { LocalDate start = new LocalDate(2000, 1, 1); LocalDate end = new LocalDate(2001, 6, 19); var interval1 = new DateInterval(start, end, false); var interval2 = new DateInterval(start, end, false); Assert.AreEqual(interval1, interval2); Assert.AreEqual(interval1.GetHashCode(), interval2.GetHashCode()); Assert.IsTrue(interval1 == interval2); Assert.IsFalse(interval1 != interval2); Assert.IsTrue(interval1.Equals(interval2)); // IEquatable implementation var comparer = DateInterval.NormalizingEqualityComparer; Assert.IsTrue(comparer.Equals(interval1, interval2)); Assert.AreEqual(comparer.GetHashCode(interval1), comparer.GetHashCode(interval2)); comparer = DateInterval.ContainedDatesEqualityComparer; Assert.IsTrue(comparer.Equals(interval1, interval2)); Assert.AreEqual(comparer.GetHashCode(interval1), comparer.GetHashCode(interval2)); }
public void Equals_DifferentEnd() { LocalDate start = new LocalDate(2000, 1, 1); LocalDate end1 = new LocalDate(2001, 6, 19); LocalDate end2 = new LocalDate(2001, 6, 20); var interval1 = new DateInterval(start, end1, false); var interval2 = new DateInterval(start, end2, false); Assert.AreNotEqual(interval1, interval2); Assert.AreNotEqual(interval1.GetHashCode(), interval2.GetHashCode()); Assert.IsFalse(interval1 == interval2); Assert.IsTrue(interval1 != interval2); Assert.IsFalse(interval1.Equals(interval2)); // IEquatable implementation var comparer = DateInterval.NormalizingEqualityComparer; Assert.IsFalse(comparer.Equals(interval1, interval2)); Assert.AreNotEqual(comparer.GetHashCode(interval1), comparer.GetHashCode(interval2)); // probably comparer = DateInterval.ContainedDatesEqualityComparer; Assert.IsFalse(comparer.Equals(interval1, interval2)); Assert.AreNotEqual(comparer.GetHashCode(interval1), comparer.GetHashCode(interval2)); // probably }
public void Equals_DifferentCalendars() { LocalDate start1 = new LocalDate(2000, 1, 1); LocalDate end1 = new LocalDate(2001, 6, 19); // This is a really, really similar calendar to ISO, but we do distinguish. // TODO: Should we? LocalDate start2 = start1.WithCalendar(CalendarSystem.Gregorian); LocalDate end2 = end1.WithCalendar(CalendarSystem.Gregorian); var interval1 = new DateInterval(start1, end1, false); var interval2 = new DateInterval(start2, end2, false); Assert.AreNotEqual(interval1, interval2); Assert.AreNotEqual(interval1.GetHashCode(), interval2.GetHashCode()); Assert.IsFalse(interval1 == interval2); Assert.IsTrue(interval1 != interval2); Assert.IsFalse(interval1.Equals(interval2)); // IEquatable implementation }
public void Equals_DifferentToOtherType() { LocalDate start = new LocalDate(2000, 1, 1); LocalDate end = new LocalDate(2001, 6, 19); var interval = new DateInterval(start, end, false); Assert.IsFalse(interval.Equals(Instant.FromUnixTimeTicks(0))); }
public void Equals_DifferentToNull() { LocalDate start = new LocalDate(2000, 1, 1); LocalDate end = new LocalDate(2001, 6, 19); var interval = new DateInterval(start, end, false); Assert.IsFalse(interval.Equals(null)); }
public void Equals_DifferentEnd() { LocalDate start = new LocalDate(2000, 1, 1); LocalDate end1 = new LocalDate(2001, 6, 19); LocalDate end2 = new LocalDate(2001, 6, 20); var interval1 = new DateInterval(start, end1, false); var interval2 = new DateInterval(start, end2, false); Assert.AreNotEqual(interval1, interval2); Assert.AreNotEqual(interval1.GetHashCode(), interval2.GetHashCode()); Assert.IsFalse(interval1 == interval2); Assert.IsTrue(interval1 != interval2); Assert.IsFalse(interval1.Equals(interval2)); // IEquatable implementation }
public void Equal_DateIntervalWithSameStartAndEndDates_ReturnTrue() { // Arrange var dateInterval1 = new DateInterval(now, inOneHour); var dateInterval2 = new DateInterval(now, inOneHour); // Act bool equals = dateInterval1.Equals(dateInterval2); // Assert Assert.True(equals); }
public void Equal_DateIntervalWithSameStartAndDifferentEndDates_ReturnFalse() { // Arrange var dateInterval1 = new DateInterval(now, inOneHour); var dateInterval2 = new DateInterval(now, inThreeHours); // Act bool equals = dateInterval1.Equals(dateInterval2); // Assert Assert.False(equals); }