예제 #1
0
        public void OverlapTest()
        {
            var intRange1 = new NullableRange <int>(1, 7);
            var intRange2 = new NullableRange <int>(3, 10);
            var intRange3 = new NullableRange <int>(8, 12);
            var intRange4 = new NullableRange <int>(7, 9);
            var intRange5 = new NullableRange <int>(0, 1);

            Assert.That(intRange1.OverlapsWithOtherRange(intRange2), Is.True);
            Assert.That(intRange1.OverlapsWithOtherRange(intRange3), Is.False);
            Assert.That(intRange1.OverlapsWithOtherRange(intRange4), Is.True);
            Assert.That(intRange1.OverlapsWithOtherRange(intRange5), Is.True);
        }
예제 #2
0
        public void OverlapTestWithNull()
        {
            var nullSevenRange   = new NullableRange <int>(null, 7);
            var threeNullRange   = new NullableRange <int>(3, null);
            var nullNullRange    = new NullableRange <int>(null, null);
            var sevenNineRange   = new NullableRange <int>(7, 9);
            var eightElevenRange = new NullableRange <int>(8, 11);
            var zeroTwoRange     = new NullableRange <int>(0, 2);

            // Self overlap
            // ------------
            AssertOverlapsWithSelf(nullSevenRange);
            AssertOverlapsWithSelf(threeNullRange);
            AssertOverlapsWithSelf(nullNullRange);
            AssertOverlapsWithSelf(sevenNineRange);
            AssertOverlapsWithSelf(eightElevenRange);

            // Overlap with the infinite range
            // -------------------------------
            const string nullRangeOverlapsWithAll = "Null range overlaps with all";

            Assert.That(nullNullRange.OverlapsWithOtherRange(nullNullRange), Is.True, nullRangeOverlapsWithAll);
            Assert.That(nullNullRange.OverlapsWithOtherRange(threeNullRange), Is.True, nullRangeOverlapsWithAll);
            Assert.That(nullNullRange.OverlapsWithOtherRange(nullSevenRange), Is.True, nullRangeOverlapsWithAll);
            Assert.That(nullNullRange.OverlapsWithOtherRange(sevenNineRange), Is.True, nullRangeOverlapsWithAll);
            Assert.That(nullNullRange.OverlapsWithOtherRange(eightElevenRange), Is.True, nullRangeOverlapsWithAll);

            Assert.That(nullNullRange.OverlapsWithOtherRange(nullNullRange), Is.True, nullRangeOverlapsWithAll);
            Assert.That(threeNullRange.OverlapsWithOtherRange(nullNullRange), Is.True, nullRangeOverlapsWithAll);
            Assert.That(nullSevenRange.OverlapsWithOtherRange(nullNullRange), Is.True, nullRangeOverlapsWithAll);
            Assert.That(sevenNineRange.OverlapsWithOtherRange(nullNullRange), Is.True, nullRangeOverlapsWithAll);
            Assert.That(eightElevenRange.OverlapsWithOtherRange(nullNullRange), Is.True, nullRangeOverlapsWithAll);

            // Overlaps
            // --------
            Assert.That(nullSevenRange.OverlapsWithOtherRange(threeNullRange), Is.True);
            Assert.That(nullSevenRange.OverlapsWithOtherRange(sevenNineRange), Is.True);
            Assert.That(nullSevenRange.OverlapsWithOtherRange(eightElevenRange), Is.False);

            Assert.That(threeNullRange.OverlapsWithOtherRange(eightElevenRange), Is.True);
            Assert.That(threeNullRange.OverlapsWithOtherRange(sevenNineRange), Is.True);
            Assert.That(threeNullRange.OverlapsWithOtherRange(zeroTwoRange), Is.False);
        }
예제 #3
0
 private void AssertOverlapsWithSelf(NullableRange <int> nullableRange)
 {
     Assert.That(nullableRange.OverlapsWithOtherRange(nullableRange), Is.True, "Should always overlap with self");
 }